From 3ee881427c66fb65583c37300a94db08db73bc5b Mon Sep 17 00:00:00 2001 From: "planetrenox@protonmail.com" Date: Wed, 14 Oct 2026 18:14:28 +0000 Subject: [PATCH] Accept AVIF and JXL image attachments Both are converted to WebP in the browser like other non-WebP images, so providers never see them. Browsers that can't decode JXL now get a readable error instead of [object Event]. Co-Authored-By: Claude Opus 5.5 --- src/attachments.js | 2 +- src/parts/footer.html | 2 +- src/utils.js | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/attachments.js b/src/attachments.js index 3b44bd9..ad8ce5e 100644 --- a/src/attachments.js +++ b/src/attachments.js @@ -6,7 +6,7 @@ export async function toAttach(file, opts) { if (file instanceof File) { const name = file.name || 'file', mime = (file.type || 'application/octet-stream').toLowerCase(); if (isVideo(name, mime)) return compressVideo(file, opts); - if (/^image\//.test(mime) || /\.(png|jpe?g|webp|gif)$/i.test(name)) { + if (/^image\//.test(mime) || /\.(png|jpe?g|webp|gif|avif|jxl)$/i.test(name)) { const data = await imgToWebp(file, 2048, 94, mime === 'image/webp' || /\.webp$/i.test(name)); return { type: 'image_url', image_url: { url: data } }; } diff --git a/src/parts/footer.html b/src/parts/footer.html index c05967e..fecdec4 100644 --- a/src/parts/footer.html +++ b/src/parts/footer.html @@ -6,7 +6,7 @@ - + diff --git a/src/utils.js b/src/utils.js index 6747b8f..028fbe0 100644 --- a/src/utils.js +++ b/src/utils.js @@ -28,7 +28,8 @@ export const imgToWebp = (f, D = 96, q = 75, k) => new Promise((r, j) => { r(c.toDataURL('image/webp', clamp(q, 0, 100) / 100)); URL.revokeObjectURL(i.src); }; - i.onerror = j; i.src = URL.createObjectURL(f); + i.onerror = () => (URL.revokeObjectURL(i.src), j(new Error("this browser can't read this image format"))); + i.src = URL.createObjectURL(f); }); export const b64 = x => x.split(',')[1] || ''; export const utob = s => btoa(unescape(encodeURIComponent(s)));