@@ -13,8 +13,6 @@ import { GetRequestToken, validateUser } from '@server/lib/GetRequestUser';
13
13
14
14
import { SongService } from './song.service' ;
15
15
16
- // Handles public-facing song routes.
17
-
18
16
@Controller ( 'song' )
19
17
@ApiTags ( 'song' )
20
18
export class SongController {
@@ -62,31 +60,27 @@ export class SongController {
62
60
@ApiQuery ( { name : 'count' , required : false , type : 'string' , description : 'Number of random songs to return (1-10). Only used when q=random.' , example : '5' , } )
63
61
@ApiQuery ( { name : 'category' , required : false , type : 'string' , description : 'Category filter for random songs. Only used when q=random.' , example : 'electronic' , } )
64
62
@ApiResponse ( {
65
- status : 200 ,
66
- description :
67
- 'Success. Returns either an array of song previews or category counts.' ,
68
- schema : {
63
+ status : 200 ,
64
+ description : 'Success. Returns either an array of song previews or category counts.' ,
65
+ schema : {
69
66
oneOf : [
70
67
{
71
- type : 'array' ,
72
- items : { $ref : '#/components/schemas/SongPreviewDto' } ,
73
- description :
74
- 'Array of song previews (default behavior and most query modes)' ,
68
+ type : 'array' ,
69
+ items : { $ref : '#/components/schemas/SongPreviewDto' } ,
70
+ description : 'Array of song previews (default behavior and most query modes)' ,
75
71
} ,
76
72
{
77
73
type : 'object' ,
78
74
additionalProperties : { type : 'number' } ,
79
- description :
80
- 'Category name to song count mapping (only when q=categories without id)' ,
81
- example : { pop : 42 , rock : 38 , electronic : 15 } ,
75
+ description : 'Category name to song count mapping (only when q=categories without id)' ,
76
+ example : { pop : 42 , rock : 38 , electronic : 15 } ,
82
77
} ,
83
78
] ,
84
79
} ,
85
80
} )
86
81
@ApiResponse ( {
87
- status : 400 ,
88
- description :
89
- 'Bad Request. Invalid query parameters (e.g., invalid count for random query).' ,
82
+ status : 400 ,
83
+ description : 'Bad Request. Invalid query parameters (e.g., invalid count for random query).' ,
90
84
} )
91
85
public async getSongList (
92
86
@Query ( ) query : PageQueryDTO ,
@@ -149,13 +143,8 @@ export class SongController {
149
143
}
150
144
151
145
@Get ( '/search' )
152
- @ApiOperation ( {
153
- summary : 'Search songs by keywords with pagination and sorting' ,
154
- } )
155
- public async searchSongs (
156
- @Query ( ) query : PageQueryDTO ,
157
- @Query ( 'q' ) q : string ,
158
- ) : Promise < PageDto < SongPreviewDto > > {
146
+ @ApiOperation ( { summary : 'Search songs by keywords with pagination and sorting' , } )
147
+ public async searchSongs ( @Query ( ) query : PageQueryDTO , @Query ( 'q' ) q : string , ) : Promise < PageDto < SongPreviewDto > > {
159
148
const data = await this . songService . searchSongs ( query , q ?? '' ) ;
160
149
return new PageDto < SongPreviewDto > ( {
161
150
content : data ,
@@ -167,21 +156,15 @@ export class SongController {
167
156
168
157
@Get ( '/:id' )
169
158
@ApiOperation ( { summary : 'Get song info by ID' } )
170
- public async getSong (
171
- @Param ( 'id' ) id : string ,
172
- @GetRequestToken ( ) user : UserDocument | null ,
173
- ) : Promise < SongViewDto > {
159
+ public async getSong ( @Param ( 'id' ) id : string , @GetRequestToken ( ) user : UserDocument | null , ) : Promise < SongViewDto > {
174
160
return await this . songService . getSong ( id , user ) ;
175
161
}
176
162
177
163
@Get ( '/:id/edit' )
178
164
@ApiOperation ( { summary : 'Get song info for editing by ID' } )
179
165
@UseGuards ( AuthGuard ( 'jwt-refresh' ) )
180
166
@ApiBearerAuth ( )
181
- public async getEditSong (
182
- @Param ( 'id' ) id : string ,
183
- @GetRequestToken ( ) user : UserDocument | null ,
184
- ) : Promise < UploadSongDto > {
167
+ public async getEditSong ( @Param ( 'id' ) id : string , @GetRequestToken ( ) user : UserDocument | null , ) : Promise < UploadSongDto > {
185
168
user = validateUser ( user ) ;
186
169
return await this . songService . getSongEdit ( id , user ) ;
187
170
}
@@ -191,11 +174,7 @@ export class SongController {
191
174
@ApiBearerAuth ( )
192
175
@ApiOperation ( { summary : 'Edit song info by ID' } )
193
176
@ApiBody ( { description : 'Upload Song' , type : UploadSongResponseDto , } )
194
- public async patchSong (
195
- @Param ( 'id' ) id : string ,
196
- @Req ( ) req : RawBodyRequest < Request > ,
197
- @GetRequestToken ( ) user : UserDocument | null ,
198
- ) : Promise < UploadSongResponseDto > {
177
+ public async patchSong ( @Param ( 'id' ) id : string , @Req ( ) req : RawBodyRequest < Request > , @GetRequestToken ( ) user : UserDocument | null , ) : Promise < UploadSongResponseDto > {
199
178
user = validateUser ( user ) ;
200
179
//TODO: Fix this weird type casting and raw body access
201
180
const body = req . body as unknown as UploadSongDto ;
@@ -204,12 +183,7 @@ export class SongController {
204
183
205
184
@Get ( '/:id/download' )
206
185
@ApiOperation ( { summary : 'Get song .nbs file' } )
207
- public async getSongFile (
208
- @Param ( 'id' ) id : string ,
209
- @Query ( 'src' ) src : string ,
210
- @GetRequestToken ( ) user : UserDocument | null ,
211
- @Res ( ) res : Response ,
212
- ) : Promise < void > {
186
+ public async getSongFile ( @Param ( 'id' ) id : string , @Query ( 'src' ) src : string , @GetRequestToken ( ) user : UserDocument | null , @Res ( ) res : Response , ) : Promise < void > {
213
187
user = validateUser ( user ) ;
214
188
215
189
// TODO: no longer used
@@ -225,11 +199,7 @@ export class SongController {
225
199
226
200
@Get ( '/:id/open' )
227
201
@ApiOperation ( { summary : 'Get song .nbs file' } )
228
- public async getSongOpenUrl (
229
- @Param ( 'id' ) id : string ,
230
- @GetRequestToken ( ) user : UserDocument | null ,
231
- @Headers ( 'src' ) src : string ,
232
- ) : Promise < string > {
202
+ public async getSongOpenUrl ( @Param ( 'id' ) id : string , @GetRequestToken ( ) user : UserDocument | null , @Headers ( 'src' ) src : string , ) : Promise < string > {
233
203
if ( src != 'downloadButton' ) {
234
204
throw new UnauthorizedException ( 'Invalid source' ) ;
235
205
}
@@ -248,10 +218,7 @@ export class SongController {
248
218
@UseGuards ( AuthGuard ( 'jwt-refresh' ) )
249
219
@ApiBearerAuth ( )
250
220
@ApiOperation ( { summary : 'Delete a song' } )
251
- public async deleteSong (
252
- @Param ( 'id' ) id : string ,
253
- @GetRequestToken ( ) user : UserDocument | null ,
254
- ) : Promise < void > {
221
+ public async deleteSong ( @Param ( 'id' ) id : string , @GetRequestToken ( ) user : UserDocument | null , ) : Promise < void > {
255
222
user = validateUser ( user ) ;
256
223
await this . songService . deleteSong ( id , user ) ;
257
224
}
@@ -263,11 +230,7 @@ export class SongController {
263
230
@ApiBody ( { description : 'Upload Song' , type : UploadSongResponseDto , } )
264
231
@UseInterceptors ( FileInterceptor ( 'file' , SongController . multerConfig ) )
265
232
@ApiOperation ( { summary : 'Upload a .nbs file and send the song data, creating a new song' , } )
266
- public async createSong (
267
- @UploadedFile ( ) file : Express . Multer . File ,
268
- @Body ( ) body : UploadSongDto ,
269
- @GetRequestToken ( ) user : UserDocument | null ,
270
- ) : Promise < UploadSongResponseDto > {
233
+ public async createSong ( @UploadedFile ( ) file : Express . Multer . File , @Body ( ) body : UploadSongDto , @GetRequestToken ( ) user : UserDocument | null , ) : Promise < UploadSongResponseDto > {
271
234
user = validateUser ( user ) ;
272
235
return await this . songService . uploadSong ( { body, file, user } ) ;
273
236
}
0 commit comments