fix(admin): return presignedUrl from from-url endpoint and update image preview after fetch
- images.ts: import getImageUrl from storage service, call after fetchImageFromUrl and include presignedUrl in response - $itemId.tsx: update handleFetchFromUrl to use presignedUrl and dominantColor from response, set imageUrl in form state so ImageUpload component shows preview immediately
This commit is contained in:
@@ -161,13 +161,17 @@ function AdminItemEditPage() {
|
||||
setFetchingImage(true);
|
||||
setFetchError(null);
|
||||
try {
|
||||
const result = await apiPost<{ filename: string; sourceUrl: string }>(
|
||||
"/api/images/from-url",
|
||||
{ url: fetchUrl.trim() },
|
||||
);
|
||||
const result = await apiPost<{
|
||||
filename: string;
|
||||
sourceUrl: string;
|
||||
presignedUrl: string;
|
||||
dominantColor: string | null;
|
||||
}>("/api/images/from-url", { url: fetchUrl.trim() });
|
||||
setForm((prev) => ({
|
||||
...prev,
|
||||
imageFilename: result.filename,
|
||||
imageUrl: result.presignedUrl,
|
||||
dominantColor: result.dominantColor ?? "",
|
||||
imageSourceUrl: fetchUrl.trim(),
|
||||
}));
|
||||
setFetchUrl("");
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
extractDominantColor,
|
||||
fetchImageFromUrl,
|
||||
} from "../services/image.service";
|
||||
import { uploadImage } from "../services/storage.service";
|
||||
import { getImageUrl, uploadImage } from "../services/storage.service";
|
||||
|
||||
const ALLOWED_TYPES = ["image/jpeg", "image/png", "image/webp"];
|
||||
const MAX_SIZE = 5 * 1024 * 1024; // 5MB
|
||||
@@ -19,7 +19,8 @@ app.post("/from-url", zValidator("json", fromUrlSchema), async (c) => {
|
||||
const { url } = c.req.valid("json");
|
||||
try {
|
||||
const result = await fetchImageFromUrl(url);
|
||||
return c.json(result, 201);
|
||||
const presignedUrl = await getImageUrl(result.filename);
|
||||
return c.json({ ...result, presignedUrl }, 201);
|
||||
} catch (err) {
|
||||
const message = (err as Error).message;
|
||||
// Known validation errors from the service
|
||||
|
||||
Reference in New Issue
Block a user