diff --git a/backend/src/recipes/recipes.service.ts b/backend/src/recipes/recipes.service.ts index 813730ed..653e4690 100644 --- a/backend/src/recipes/recipes.service.ts +++ b/backend/src/recipes/recipes.service.ts @@ -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) { diff --git a/flutter/lib/core/router/app_router.dart b/flutter/lib/core/router/app_router.dart index 07a81d69..f608f847 100644 --- a/flutter/lib/core/router/app_router.dart +++ b/flutter/lib/core/router/app_router.dart @@ -71,7 +71,9 @@ final appRouterProvider = Provider((ref) { final extra = state.extra; String? initialMarkdown; String? initialImageUrl; - if (extra is Map) { + // Use 'is Map' without type params — Dart reifies generics, so + // Map does NOT match Map at runtime. + if (extra is Map) { initialMarkdown = extra['markdown'] as String?; initialImageUrl = extra['imageUrl'] as String?; } else if (extra is String) { diff --git a/flutter/lib/features/import/presentation/recipe_import_tab.dart b/flutter/lib/features/import/presentation/recipe_import_tab.dart index f746f487..f60e7c97 100644 --- a/flutter/lib/features/import/presentation/recipe_import_tab.dart +++ b/flutter/lib/features/import/presentation/recipe_import_tab.dart @@ -78,8 +78,9 @@ class _RecipeImportTabState extends ConsumerState { ); if (!mounted) return; - // Pass both markdown and imageUrl so CreateRecipeScreen can pre-fill both. - context.push('/recipes/create', extra: { + // Explicitly typed as so the router's + // 'is Map' runtime check succeeds. + context.push('/recipes/create', extra: { 'markdown': result.markdown, 'imageUrl': result.imageUrl, });