refactor(editor): Bild-Upload/Delete auf asyncFetch (Item H)
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 1m29s
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 1m29s
RecipeEditor war noch die letzte Stelle im UI, die das
handgeschriebene "if (!res.ok) { alertAction(...) }"-Pattern
benutzte, welches wir in review-fixes-2026-04-18 ueberall sonst
durch asyncFetch() ersetzt hatten.
Netto: -14 Zeilen, konsistenter Fehlermessage-Fallback (body.message
> res.status), eine Import-Zeile weniger (alertAction raus, asyncFetch
rein).
Gate: svelte-check clean, 184/184 Tests, Upload/Delete-Flow per
Hand zu testen beim naechsten Editor-Touch.
Refs docs/superpowers/plans/2026-04-19-post-review-roadmap.md Item H.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,8 @@
|
|||||||
import { untrack } from 'svelte';
|
import { untrack } from 'svelte';
|
||||||
import { Plus, Trash2, ChevronUp, ChevronDown, ImagePlus, ImageOff } from 'lucide-svelte';
|
import { Plus, Trash2, ChevronUp, ChevronDown, ImagePlus, ImageOff } from 'lucide-svelte';
|
||||||
import type { Recipe, Ingredient, Step } from '$lib/types';
|
import type { Recipe, Ingredient, Step } from '$lib/types';
|
||||||
import { alertAction, confirmAction } from '$lib/client/confirm.svelte';
|
import { confirmAction } from '$lib/client/confirm.svelte';
|
||||||
|
import { asyncFetch } from '$lib/client/api-fetch-wrapper';
|
||||||
import { requireOnline } from '$lib/client/require-online';
|
import { requireOnline } from '$lib/client/require-online';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@@ -48,18 +49,12 @@
|
|||||||
try {
|
try {
|
||||||
const fd = new FormData();
|
const fd = new FormData();
|
||||||
fd.append('file', file);
|
fd.append('file', file);
|
||||||
const res = await fetch(`/api/recipes/${recipe.id}/image`, {
|
const res = await asyncFetch(
|
||||||
method: 'POST',
|
`/api/recipes/${recipe.id}/image`,
|
||||||
body: fd
|
{ method: 'POST', body: fd },
|
||||||
});
|
'Upload fehlgeschlagen'
|
||||||
if (!res.ok) {
|
);
|
||||||
const body = await res.json().catch(() => ({}));
|
if (!res) return;
|
||||||
await alertAction({
|
|
||||||
title: 'Upload fehlgeschlagen',
|
|
||||||
message: body.message ?? `HTTP ${res.status}`
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const body = await res.json();
|
const body = await res.json();
|
||||||
imagePath = body.image_path;
|
imagePath = body.image_path;
|
||||||
onimagechange?.(imagePath);
|
onimagechange?.(imagePath);
|
||||||
@@ -80,14 +75,12 @@
|
|||||||
if (!requireOnline('Das Entfernen')) return;
|
if (!requireOnline('Das Entfernen')) return;
|
||||||
uploading = true;
|
uploading = true;
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`/api/recipes/${recipe.id}/image`, { method: 'DELETE' });
|
const res = await asyncFetch(
|
||||||
if (!res.ok) {
|
`/api/recipes/${recipe.id}/image`,
|
||||||
await alertAction({
|
{ method: 'DELETE' },
|
||||||
title: 'Entfernen fehlgeschlagen',
|
'Entfernen fehlgeschlagen'
|
||||||
message: `HTTP ${res.status}`
|
);
|
||||||
});
|
if (!res) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
imagePath = null;
|
imagePath = null;
|
||||||
onimagechange?.(null);
|
onimagechange?.(null);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user