mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-12 04:15:25 +00:00
Merge pull request #17225 from ShirasawaSama/feat/dynamic-load-heic2any
feat: dynamically load heic2any to accelerate initial page loading speed and fix heic convert bug
This commit is contained in:
commit
5b3eae3855
3 changed files with 16 additions and 6 deletions
|
|
@ -1,7 +1,6 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import DOMPurify from 'dompurify';
|
import DOMPurify from 'dompurify';
|
||||||
import { marked } from 'marked';
|
import { marked } from 'marked';
|
||||||
import heic2any from 'heic2any';
|
|
||||||
|
|
||||||
import { toast } from 'svelte-sonner';
|
import { toast } from 'svelte-sonner';
|
||||||
|
|
||||||
|
|
@ -28,7 +27,7 @@
|
||||||
} from '$lib/stores';
|
} from '$lib/stores';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
blobToFile,
|
convertHeicToJpeg,
|
||||||
compressImage,
|
compressImage,
|
||||||
createMessagesList,
|
createMessagesList,
|
||||||
extractContentFromFile,
|
extractContentFromFile,
|
||||||
|
|
@ -761,7 +760,7 @@
|
||||||
};
|
};
|
||||||
reader.readAsDataURL(
|
reader.readAsDataURL(
|
||||||
file['type'] === 'image/heic'
|
file['type'] === 'image/heic'
|
||||||
? await heic2any({ blob: file, toType: 'image/jpeg' })
|
? await convertHeicToJpeg(file)
|
||||||
: file
|
: file
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { getContext, onDestroy, onMount, tick } from 'svelte';
|
import { getContext, onDestroy, onMount, tick } from 'svelte';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import heic2any from 'heic2any';
|
|
||||||
import fileSaver from 'file-saver';
|
import fileSaver from 'file-saver';
|
||||||
const { saveAs } = fileSaver;
|
const { saveAs } = fileSaver;
|
||||||
|
|
||||||
|
|
@ -26,7 +25,7 @@
|
||||||
|
|
||||||
import { PaneGroup, Pane, PaneResizer } from 'paneforge';
|
import { PaneGroup, Pane, PaneResizer } from 'paneforge';
|
||||||
|
|
||||||
import { compressImage, copyToClipboard, splitStream } from '$lib/utils';
|
import { compressImage, copyToClipboard, splitStream, convertHeicToJpeg } from '$lib/utils';
|
||||||
import { WEBUI_API_BASE_URL, WEBUI_BASE_URL } from '$lib/constants';
|
import { WEBUI_API_BASE_URL, WEBUI_BASE_URL } from '$lib/constants';
|
||||||
import { uploadFile } from '$lib/apis/files';
|
import { uploadFile } from '$lib/apis/files';
|
||||||
import { chatCompletion, generateOpenAIChatCompletion } from '$lib/apis/openai';
|
import { chatCompletion, generateOpenAIChatCompletion } from '$lib/apis/openai';
|
||||||
|
|
@ -547,7 +546,7 @@ ${content}
|
||||||
|
|
||||||
reader.readAsDataURL(
|
reader.readAsDataURL(
|
||||||
file['type'] === 'image/heic'
|
file['type'] === 'image/heic'
|
||||||
? await heic2any({ blob: file, toType: 'image/jpeg' })
|
? await convertHeicToJpeg(file)
|
||||||
: file
|
: file
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1538,3 +1538,15 @@ export const getAge = (birthDate) => {
|
||||||
}
|
}
|
||||||
return age.toString();
|
return age.toString();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const convertHeicToJpeg = async (file: File) => {
|
||||||
|
const { default: heic2any } = await import('heic2any');
|
||||||
|
try {
|
||||||
|
return await heic2any({ blob: file, toType: 'image/jpeg' });
|
||||||
|
} catch (err: any) {
|
||||||
|
if (err?.message?.includes('already browser readable')) {
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue