feat: song illustration

This commit is contained in:
GitBluub
2023-05-30 00:51:36 +09:00
committed by Clément Le Bihan
parent 7b5629f4a4
commit 8dbb724a0f
2 changed files with 27 additions and 12 deletions
+13 -12
View File
@@ -46,18 +46,19 @@ model SearchHistory {
} }
model Song { model Song {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
name String @unique name String @unique
midiPath String midiPath String
musicXmlPath String musicXmlPath String
artistId Int? illustrationPath String?
artist Artist? @relation(fields: [artistId], references: [id]) artistId Int?
albumId Int? artist Artist? @relation(fields: [artistId], references: [id])
album Album? @relation(fields: [albumId], references: [id]) albumId Int?
genreId Int? album Album? @relation(fields: [albumId], references: [id])
genre Genre? @relation(fields: [genreId], references: [id]) genreId Int?
difficulties Json genre Genre? @relation(fields: [genreId], references: [id])
SongHistory SongHistory[] difficulties Json
SongHistory SongHistory[]
} }
model SongHistory { model SongHistory {
+14
View File
@@ -48,6 +48,20 @@ export class SongController {
} }
} }
@Get(':id/illustration')
async getIllustration(@Param('id', ParseIntPipe) id: number) {
const song = await this.songService.song({ id });
if (!song) throw new NotFoundException('Song not found');
if (song.illustrationPath === null) throw new NotFoundException();
try {
const file = createReadStream(song.illustrationPath);
return new StreamableFile(file);
} catch {
throw new InternalServerErrorException();
}
}
@Get(':id/musicXml') @Get(':id/musicXml')
async getMusicXml(@Param('id', ParseIntPipe) id: number) { async getMusicXml(@Param('id', ParseIntPipe) id: number) {
const song = await this.songService.song({ id }); const song = await this.songService.song({ id });