refac
This commit is contained in:
1 parent
5ee7140b4c
commit
2578174637
1 file changed
+18
-2
@@ -1,9 +1,11 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onDestroy, getContext } from 'svelte';
|
import { onDestroy, getContext } from 'svelte';
|
||||||
|
|
||||||
|
import { toast } from 'svelte-sonner';
|
||||||
import fileSaver from 'file-saver';
|
import fileSaver from 'file-saver';
|
||||||
const { saveAs } = fileSaver;
|
const { saveAs } = fileSaver;
|
||||||
|
|
||||||
|
import { WEBUI_BASE_URL } from '$lib/constants';
|
||||||
import PanzoomContainer from '$lib/components/common/PanzoomContainer.svelte';
|
import PanzoomContainer from '$lib/components/common/PanzoomContainer.svelte';
|
||||||
import XMark from '$lib/components/icons/XMark.svelte';
|
import XMark from '$lib/components/icons/XMark.svelte';
|
||||||
|
|
||||||
@@ -120,8 +122,21 @@
|
|||||||
src.startsWith('https://')
|
src.startsWith('https://')
|
||||||
) {
|
) {
|
||||||
// Handle remote URLs
|
// Handle remote URLs
|
||||||
fetch(src)
|
const backendOrigin = new URL(WEBUI_BASE_URL || '/', window.location.origin).origin;
|
||||||
.then((response) => response.blob())
|
const isBackendUrl = new URL(src, window.location.origin).origin === backendOrigin;
|
||||||
|
|
||||||
|
fetch(
|
||||||
|
src,
|
||||||
|
isBackendUrl && localStorage.token
|
||||||
|
? { headers: { Authorization: `Bearer ${localStorage.token}` } }
|
||||||
|
: undefined
|
||||||
|
)
|
||||||
|
.then((response) => {
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`Failed to download image: ${response.status}`);
|
||||||
|
}
|
||||||
|
return response.blob();
|
||||||
|
})
|
||||||
.then((blob) => {
|
.then((blob) => {
|
||||||
// detect the MIME type from the blob
|
// detect the MIME type from the blob
|
||||||
const mimeType = blob.type || 'image/png';
|
const mimeType = blob.type || 'image/png';
|
||||||
@@ -140,6 +155,7 @@
|
|||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error('Error downloading remote image:', error);
|
console.error('Error downloading remote image:', error);
|
||||||
|
toast.error($i18n.t('Failed to download image'));
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user