From 8dbb724a0fe44f759fe8b59a7b3c42da63c7867f Mon Sep 17 00:00:00 2001 From: GitBluub Date: Tue, 30 May 2023 00:51:36 +0900 Subject: [PATCH] feat: song illustration --- back/prisma/schema.prisma | 25 +++++++++++++------------ back/src/song/song.controller.ts | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/back/prisma/schema.prisma b/back/prisma/schema.prisma index 225949b..bebd22c 100644 --- a/back/prisma/schema.prisma +++ b/back/prisma/schema.prisma @@ -46,18 +46,19 @@ model SearchHistory { } model Song { - id Int @id @default(autoincrement()) - name String @unique - midiPath String - musicXmlPath String - artistId Int? - artist Artist? @relation(fields: [artistId], references: [id]) - albumId Int? - album Album? @relation(fields: [albumId], references: [id]) - genreId Int? - genre Genre? @relation(fields: [genreId], references: [id]) - difficulties Json - SongHistory SongHistory[] + id Int @id @default(autoincrement()) + name String @unique + midiPath String + musicXmlPath String + illustrationPath String? + artistId Int? + artist Artist? @relation(fields: [artistId], references: [id]) + albumId Int? + album Album? @relation(fields: [albumId], references: [id]) + genreId Int? + genre Genre? @relation(fields: [genreId], references: [id]) + difficulties Json + SongHistory SongHistory[] } model SongHistory { diff --git a/back/src/song/song.controller.ts b/back/src/song/song.controller.ts index 441cb6e..b9ff893 100644 --- a/back/src/song/song.controller.ts +++ b/back/src/song/song.controller.ts @@ -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') async getMusicXml(@Param('id', ParseIntPipe) id: number) { const song = await this.songService.song({ id });