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
+13 -2
View File
@@ -1,15 +1,25 @@
function isHeifConsoleMessage(msg: string): boolean {
return /HEIF|parse HEIF|Could not parse/i.test(msg);
}
/**
* Convert HEIC/HEIF blob to JPEG. Uses heic2any only when this function is called
* (dynamic import), so the receipt page can load even if heic2any fails to resolve.
* Suppresses the library's "Could not parse HEIF file" console errors during conversion.
* Suppresses the library's "Could not parse HEIF file" console output during conversion.
*/
export async function convertHeicBlobToJpeg(blob: Blob): Promise<Blob> {
const originalError = console.error;
const originalWarn = console.warn;
console.error = (...args: unknown[]) => {
const msg = args[0]?.toString?.() ?? "";
if (msg.includes("HEIF") || msg.includes("parse HEIF")) return;
if (isHeifConsoleMessage(msg)) return;
originalError.apply(console, args);
};
console.warn = (...args: unknown[]) => {
const msg = args[0]?.toString?.() ?? "";
if (isHeifConsoleMessage(msg)) return;
originalWarn.apply(console, args);
};
try {
const mod = await import(/* @vite-ignore */ "heic2any");
const heic2any = (mod as unknown as {
@@ -19,5 +29,6 @@ export async function convertHeicBlobToJpeg(blob: Blob): Promise<Blob> {
return Array.isArray(out) ? out[0] : out;
} finally {
console.error = originalError;
console.warn = originalWarn;
}
}