Refactor image upload handling across items and receipts routes to include validation for uploaded images, enhancing error handling and user feedback. Consolidate parsing functions by importing from a shared module, improving code maintainability. Update server hooks to ensure consistent cookie handling and error logging.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { fail } from "@sveltejs/kit";
|
||||
import type { Actions, PageServerLoad } from "./$types";
|
||||
import type { StackqReceipt } from "$lib/types/receipts";
|
||||
import { validateImageUpload } from "$lib/validate-image-upload";
|
||||
|
||||
const COLLECTION = "Stackq_Receipts";
|
||||
|
||||
@@ -30,6 +31,10 @@ export const actions: Actions = {
|
||||
const Type = (form.get("Type") as string)?.trim() || "Purchase";
|
||||
const imageFile = form.get("Image") as File | null;
|
||||
const hasImage = imageFile && imageFile.size > 0;
|
||||
if (hasImage) {
|
||||
const imgError = validateImageUpload(imageFile);
|
||||
if (imgError) return fail(400, { error: imgError, Type });
|
||||
}
|
||||
|
||||
const body: Record<string, unknown> = {
|
||||
Status: "New",
|
||||
|
||||
Reference in New Issue
Block a user