fix(router): adjust type check for extra parameter in navigation
fix(import): ensure correct typing for passing markdown and imageUrl fix(recipes): delete local image file on recipe deletion to avoid orphan files
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import * as fs from 'node:fs/promises';
|
||||
import * as path from 'node:path';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { CreateRecipeDto } from './dto/create-recipe.dto';
|
||||
import { ParseMarkdownDto } from './dto/parse-markdown.dto';
|
||||
@@ -272,6 +274,15 @@ export class RecipesService {
|
||||
|
||||
await this.prisma.recipeIngredient.deleteMany({ where: { recipeId: id } });
|
||||
await this.prisma.recipe.delete({ where: { id } });
|
||||
|
||||
// Radera lokal bildfil om den finns (undviker orphan-filer på disk).
|
||||
if (existingRecipe.imageUrl?.startsWith('/images/')) {
|
||||
const filename = path.basename(existingRecipe.imageUrl);
|
||||
const filePath = path.join(IMAGE_DEST_DIR, filename);
|
||||
await fs.unlink(filePath).catch(() => {
|
||||
// Filen kanske redan är borttagen — ignorera felet.
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async updateImage(id: number, sourceUrl: string) {
|
||||
|
||||
Reference in New Issue
Block a user