Chat / backend /src /modules /tracks /tracks.controller.ts
kishankrish19's picture
Deploy Stillwave fullstack clean
b0798af
Raw History Blame Contribute Delete
3.07 kB
import {
Controller,
Get,
Post,
Patch,
Delete,
Param,
Body,
UseGuards,
Res,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { TracksService } from './tracks.service';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
@ApiTags('Tracks')
@Controller('tracks')
export class TracksController {
constructor(private readonly tracksService: TracksService) {}
@Get()
@ApiOperation({ summary: 'List published music tracks' })
getAllTracks() {
return this.tracksService.findAll();
}
@Get('on-repeat')
@ApiOperation({ summary: 'Get user On Repeat frequently played tracks' })
getOnRepeatTracks() {
return this.tracksService.getOnRepeatTracks();
}
@Post('download-demand')
@ApiOperation({
summary: 'Trigger non-blocking background on-demand track download',
})
downloadOnDemand(@Body() body: { track_id: string }) {
return this.tracksService.downloadOnDemand(body.track_id);
}
@Get('download-status/:trackId')
@ApiOperation({ summary: 'Check background download job status' })
getDownloadStatus(@Param('trackId') trackId: string) {
return this.tracksService.getDownloadStatus(trackId);
}
@Get(':id')
@ApiOperation({ summary: 'Get track metadata by ID' })
getTrackById(@Param('id') id: string) {
return this.tracksService.findOne(id);
}
@Get(':id/lyrics')
@ApiOperation({ summary: 'Get plain or time-synced lyrics for a track' })
getLyrics(@Param('id') id: string) {
return this.tracksService.getLyrics(id);
}
@Get(':id/stream')
@ApiOperation({ summary: 'Get short-lived signed audio streaming URL' })
getStreamUrl(@Param('id') id: string) {
return this.tracksService.getStreamUrl(id);
}
@Get(':id/audio')
@ApiOperation({ summary: 'Direct binary audio stream or CDN redirect' })
async streamAudio(@Param('id') id: string, @Res() res: any) {
return this.tracksService.streamAudio(id, res);
}
@Post()
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Upload/create a new track' })
createTrack(
@Body()
dto: {
title: string;
artist_name: string;
album_title?: string;
duration_ms: number;
audio_path: string;
cover_url?: string;
explicit?: boolean;
},
) {
return this.tracksService.create(dto);
}
@Patch(':id')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Edit track metadata' })
updateTrack(@Param('id') id: string, @Body() dto: any) {
return this.tracksService.update(id, dto);
}
@Delete(':id')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Remove a track' })
removeTrack(@Param('id') id: string) {
return this.tracksService.remove(id);
}
@Post(':id/play')
@ApiOperation({ summary: 'Log a play event (context, ms_played)' })
logPlay(
@Param('id') id: string,
@Body()
body: { context_type?: string; context_id?: string; ms_played?: number },
) {
return this.tracksService.logPlay(id, body);
}
}