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:
+13
-2
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user