feat: add image handling to recipes

- Implemented image downloading and optimization in QuickImportService.
- Added imageUrl field to CreateRecipeDto for recipe creation.
- Created an endpoint in RecipesController to update recipe images.
- Enhanced RecipesService to handle image URL updates and optimizations.
- Updated Docker Compose to mount a volume for recipe images.
- Refactored frontend to display images in recipe grids and detail views.
- Added a new utility function for downloading and optimizing images.
- Created a new API route for handling image uploads.
- Introduced RecipeGrid component for better recipe display.
- Updated RecipeDetailClient to manage image updates and display.
- Added migration for new imageUrl column in the Recipe table.
This commit is contained in:
Nils-Johan Gynther
2026-04-15 19:46:50 +02:00
parent a2038ffbec
commit 73bf5193c4
20 changed files with 933 additions and 49 deletions
@@ -11,10 +11,14 @@ import { createWorker } from 'tesseract.js';
import { IcaRecipeParser } from './parsers/ica.parser';
import { GenericRecipeParser } from './parsers/generic.parser';
import { RecipeParser } from './parsers/base.parser';
import { downloadAndOptimizeImage } from '../common/utils/download-image';
const IMAGE_DEST_DIR = process.env.IMAGE_DEST_DIR || '/app/recipe-images';
export interface QuickImportResult {
markdown: string;
source: 'ica' | 'pdf' | 'image' | 'other';
imageUrl?: string;
}
type UploadKind = 'pdf' | 'image';
@@ -311,9 +315,21 @@ export class QuickImportService {
source = 'ica';
}
// Ladda ner och optimera bild om parser hittade en
let imageUrl: string | undefined;
if (recipe.imageUrl) {
try {
imageUrl = await downloadAndOptimizeImage(recipe.imageUrl, IMAGE_DEST_DIR);
console.log('[QuickImport] Bild optimerad och sparad:', imageUrl);
} catch (imgErr) {
console.warn('[QuickImport] Kunde inte ladda ner bild:', imgErr);
}
}
return {
markdown,
source,
imageUrl,
};
} catch (err) {
const message = err instanceof Error ? err.message : 'Okänt fel vid scraping';