fix: back crash if file not found

This commit is contained in:
GitBluub
2023-05-30 02:07:36 +09:00
committed by Clément Le Bihan
parent 7eb3d54903
commit 5843da2d02
2 changed files with 6 additions and 2 deletions

View File

@@ -21,7 +21,7 @@ import { Request } from 'express';
import { ArtistService } from './artist.service';
import { Prisma, Artist } from '@prisma/client';
import { ApiTags } from '@nestjs/swagger';
import { createReadStream } from 'fs';
import { createReadStream, existsSync } from 'fs';
@Controller('artist')
@ApiTags('artist')
@@ -47,6 +47,8 @@ export class ArtistController {
const artist = await this.service.get({ id });
if (!artist) throw new NotFoundException('Artist not found');
const path = `/assets/artists/${artist.name}/illustration.png`;
if (!existsSync(path))
throw new NotFoundException('Illustration not found');
try {
const file = createReadStream(path);

View File

@@ -21,7 +21,7 @@ import { Request } from 'express';
import { GenreService } from './genre.service';
import { Prisma, Genre } from '@prisma/client';
import { ApiTags } from '@nestjs/swagger';
import { createReadStream } from 'fs';
import { createReadStream, existsSync } from 'fs';
@Controller('genre')
@ApiTags('genre')
@@ -47,6 +47,8 @@ export class GenreController {
const genre = await this.service.get({ id });
if (!genre) throw new NotFoundException('Genre not found');
const path = `/assets/genres/${genre.name}/illustration.png`;
if (!existsSync(path))
throw new NotFoundException('Illustration not found');
try {
const file = createReadStream(path);