feat(import): enhance image URL extraction and logging during recipe import

This commit is contained in:
Nils-Johan Gynther
2026-04-22 22:08:05 +02:00
parent 28606d7abd
commit 71bc162015
8 changed files with 163 additions and 21 deletions
@@ -320,7 +320,9 @@ export class QuickImportService {
let imageUrl: string | undefined;
let imageWarning: string | undefined;
if (recipe.imageUrl) {
this.logger.log(`Bildkandidat från parser: ${recipe.imageUrl}`);
const normalizedImageUrl = this.normalizeImageUrl(recipe.imageUrl, url);
this.logger.log(`Normaliserad bild-URL: ${normalizedImageUrl ?? 'null'}`);
if (!normalizedImageUrl) {
imageWarning = 'Receptbild kunde inte tolkas till en giltig URL.';
this.logger.warn(
@@ -331,7 +333,9 @@ export class QuickImportService {
imageUrl = await downloadAndOptimizeImage(normalizedImageUrl, IMAGE_DEST_DIR);
this.logger.log(`Bild optimerad och sparad: ${imageUrl}`);
} catch (imgErr) {
imageWarning = 'Receptbild kunde inte laddas ner.';
// Fallback: behåll extern URL så klienten ändå kan visa bild.
imageUrl = normalizedImageUrl;
imageWarning = 'Receptbild kunde inte laddas ner lokalt; extern URL används.';
this.logger.warn(
`Kunde inte ladda ner bild: ${imgErr} (källa: ${normalizedImageUrl})`,
);