mirror of
https://github.com/sune-org/sune.git
synced 2026-10-18 16:17:53 +00:00
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 <noreply@anthropic.com>
This commit is contained in:
+1
-1
@@ -6,7 +6,7 @@ export async function toAttach(file, opts) {
|
|||||||
if (file instanceof File) {
|
if (file instanceof File) {
|
||||||
const name = file.name || 'file', mime = (file.type || 'application/octet-stream').toLowerCase();
|
const name = file.name || 'file', mime = (file.type || 'application/octet-stream').toLowerCase();
|
||||||
if (isVideo(name, mime)) return compressVideo(file, opts);
|
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));
|
const data = await imgToWebp(file, 2048, 94, mime === 'image/webp' || /\.webp$/i.test(name));
|
||||||
return { type: 'image_url', image_url: { url: data } };
|
return { type: 'image_url', image_url: { url: data } };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<button id="sendBtn" type="submit" aria-label="Send" class="shrink-0 rounded-2xl bg-black text-white h-10 w-10 inline-flex items-center justify-center shadow-sm hover:bg-black/90 active:scale-[.98] transition"><i data-lucide="sparkles" class="h-5 w-5"></i></button>
|
<button id="sendBtn" type="submit" aria-label="Send" class="shrink-0 rounded-2xl bg-black text-white h-10 w-10 inline-flex items-center justify-center shadow-sm hover:bg-black/90 active:scale-[.98] transition"><i data-lucide="sparkles" class="h-5 w-5"></i></button>
|
||||||
<button id="attachBtn" type="button" aria-label="Attach" class="relative shrink-0 rounded-2xl bg-gray-100 text-gray-900 h-10 w-10 inline-flex items-center justify-center shadow-sm hover:bg-gray-200 active:scale-[.98] transition"><i data-lucide="paperclip" class="h-5 w-5"></i><span id="attachBadge" class="hidden absolute -top-1 -right-1 h-4 min-w-4 px-1 rounded-full bg-black text-white text-[10px] leading-4 text-center"></span></button>
|
<button id="attachBtn" type="button" aria-label="Attach" class="relative shrink-0 rounded-2xl bg-gray-100 text-gray-900 h-10 w-10 inline-flex items-center justify-center shadow-sm hover:bg-gray-200 active:scale-[.98] transition"><i data-lucide="paperclip" class="h-5 w-5"></i><span id="attachBadge" class="hidden absolute -top-1 -right-1 h-4 min-w-4 px-1 rounded-full bg-black text-white text-[10px] leading-4 text-center"></span></button>
|
||||||
</div>
|
</div>
|
||||||
<input id="fileInput" type="file" class="hidden" multiple accept="image/png,image/jpeg,image/webp,image/gif,application/pdf,audio/wav,audio/x-wav,audio/mpeg,audio/mp3,video/*"/>
|
<input id="fileInput" type="file" class="hidden" multiple accept="image/png,image/jpeg,image/webp,image/gif,image/avif,image/jxl,.avif,.jxl,application/pdf,audio/wav,audio/x-wav,audio/mpeg,audio/mp3,video/*"/>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
|
|||||||
+2
-1
@@ -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));
|
r(c.toDataURL('image/webp', clamp(q, 0, 100) / 100));
|
||||||
URL.revokeObjectURL(i.src);
|
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 b64 = x => x.split(',')[1] || '';
|
||||||
export const utob = s => btoa(unescape(encodeURIComponent(s)));
|
export const utob = s => btoa(unescape(encodeURIComponent(s)));
|
||||||
|
|||||||
Reference in New Issue
Block a user