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.
CI / build (push) Has been skipped
CI / deploy (push) Successful in 1m35s

This commit is contained in:
eewing
2026-02-26 10:48:33 -06:00
parent 694a5295cc
commit b72df41ec7
8 changed files with 162 additions and 41 deletions
@@ -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);