Refactor saveBase64AsFile uploads (#4200)

* Refactor saveBase64AsFile uploads

* Add request body check

* Extract server-side constants

* Allow .jfif media attachments

* Allow .bmp uploads

* Enhance image prompt handling: support additional MIME types and prevent upscaling in thumbnails

* Convert file extension to lowercase

* Enhance thumbnail creation: improve image quality and add white background

* Add toast for error in media upload
This commit is contained in:
Cohee
2025-06-25 21:34:08 +03:00
committed by GitHub
parent 7755fc50a5
commit dbe0111034
9 changed files with 95 additions and 63 deletions
+6 -2
View File
@@ -38,10 +38,14 @@ export async function getMultimodalCaption(base64Img, prompt) {
const isVllm = extension_settings.caption.multimodal_api === 'vllm';
const base64Bytes = base64Img.length * 0.75;
const compressionLimit = 2 * 1024 * 1024;
const safeMimeTypes = ['image/jpeg', 'image/png', 'image/webp'];
const mimeType = base64Img?.split(';')?.[0]?.split(':')?.[1];
const thumbnailNeeded = ['google', 'openrouter', 'mistral', 'groq', 'vertexai'].includes(extension_settings.caption.multimodal_api);
if ((thumbnailNeeded && base64Bytes > compressionLimit) || isOoba || isKoboldCpp) {
const maxSide = 1024;
base64Img = await createThumbnail(base64Img, maxSide, maxSide, 'image/jpeg');
const maxSide = 2048;
base64Img = await createThumbnail(base64Img, maxSide, maxSide);
} else if (!safeMimeTypes.includes(mimeType)) {
base64Img = await createThumbnail(base64Img, null, null);
}
const proxyUrl = useReverseProxy ? oai_settings.reverse_proxy : '';