Enhance image upload handling by integrating HEIC to JPEG conversion in receipts routes. Update ReceiptForm and related components to improve user feedback during image processing, ensuring compatibility with HEIC files. Refactor image handling logic for better maintainability and user experience.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import { fail } from "@sveltejs/kit";
|
||||
import type { Actions, PageServerLoad } from "./$types";
|
||||
import type { StackqReceipt } from "$lib/types/receipts";
|
||||
import { convertHeicFileToJpegIfNeeded } from "$lib/convert-heic-server";
|
||||
import { validateImageUpload } from "$lib/validate-image-upload";
|
||||
|
||||
const COLLECTION = "Stackq_Receipts";
|
||||
@@ -37,12 +38,24 @@ export const actions = {
|
||||
if (imgError) return fail(400, { error: imgError, Type });
|
||||
}
|
||||
|
||||
let imageToSave: File | null = hasImage ? imageFile : null;
|
||||
if (imageToSave) {
|
||||
try {
|
||||
imageToSave = await convertHeicFileToJpegIfNeeded(imageToSave);
|
||||
} catch {
|
||||
return fail(400, {
|
||||
error: "Could not convert HEIC image. Try saving as JPEG (iPhone: Settings → Camera → Formats) or use a different photo.",
|
||||
Type,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const body: Record<string, unknown> = {
|
||||
Status: "New",
|
||||
Type: TYPE_OPTIONS.includes(Type as (typeof TYPE_OPTIONS)[number]) ? Type : "Purchase",
|
||||
User: user.id,
|
||||
};
|
||||
if (hasImage) body.Image = imageFile;
|
||||
if (imageToSave) body.Image = imageToSave;
|
||||
|
||||
try {
|
||||
await locals.pb.collection(COLLECTION).create(body);
|
||||
|
||||
Reference in New Issue
Block a user