Spaces:
Sleeping
Sleeping
File size: 3,070 Bytes
b0798af | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | 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);
}
}
|