mirror of
https://github.com/immich-app/immich.git
synced 2025-12-14 17:23:36 +03:00
Compare commits
1 Commits
revert-sve
...
push-lrzks
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2cb97c3cee |
@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import BrokenAsset from '$lib/components/assets/broken-asset.svelte';
|
import BrokenAsset from '$lib/components/assets/broken-asset.svelte';
|
||||||
import { cancelImageUrl } from '$lib/utils/sw-messaging';
|
import { preloadManager } from '$lib/managers/PreloadManager.svelte';
|
||||||
import { Icon } from '@immich/ui';
|
import { Icon } from '@immich/ui';
|
||||||
import { mdiEyeOffOutline } from '@mdi/js';
|
import { mdiEyeOffOutline } from '@mdi/js';
|
||||||
import type { ActionReturn } from 'svelte/action';
|
import type { ActionReturn } from 'svelte/action';
|
||||||
@@ -60,7 +60,7 @@
|
|||||||
onComplete?.(false);
|
onComplete?.(false);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
destroy: () => cancelImageUrl(url),
|
destroy: () => preloadManager.cancelPreloadUrl(url),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
37
web/src/lib/managers/PreloadManager.svelte.ts
Normal file
37
web/src/lib/managers/PreloadManager.svelte.ts
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import { getAssetUrl } from '$lib/utils';
|
||||||
|
import { cancelImageUrl, preloadImageUrl } from '$lib/utils/sw-messaging';
|
||||||
|
import { AssetTypeEnum, type AssetResponseDto } from '@immich/sdk';
|
||||||
|
|
||||||
|
class PreloadManager {
|
||||||
|
preload(asset: AssetResponseDto | undefined) {
|
||||||
|
if (!asset) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (globalThis.isSecureContext) {
|
||||||
|
preloadImageUrl(getAssetUrl({ asset }));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (asset.type === AssetTypeEnum.Image) {
|
||||||
|
const img = new Image();
|
||||||
|
img.src = getAssetUrl({ asset });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cancel(asset: AssetResponseDto | undefined) {
|
||||||
|
if (!globalThis.isSecureContext || !asset) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const url = getAssetUrl({ asset });
|
||||||
|
cancelImageUrl(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
cancelPreloadUrl(url: string) {
|
||||||
|
if (!globalThis.isSecureContext) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cancelImageUrl(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const preloadManager = new PreloadManager();
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
import { defaultLang, langs, locales } from '$lib/constants';
|
import { defaultLang, langs, locales } from '$lib/constants';
|
||||||
import { authManager } from '$lib/managers/auth-manager.svelte';
|
import { authManager } from '$lib/managers/auth-manager.svelte';
|
||||||
import { lang } from '$lib/stores/preferences.store';
|
import { alwaysLoadOriginalFile, lang } from '$lib/stores/preferences.store';
|
||||||
|
import { isWebCompatibleImage } from '$lib/utils/asset-utils';
|
||||||
import { handleError } from '$lib/utils/handle-error';
|
import { handleError } from '$lib/utils/handle-error';
|
||||||
import {
|
import {
|
||||||
AssetJobName,
|
AssetJobName,
|
||||||
AssetMediaSize,
|
AssetMediaSize,
|
||||||
|
AssetTypeEnum,
|
||||||
MemoryType,
|
MemoryType,
|
||||||
QueueName,
|
QueueName,
|
||||||
finishOAuth,
|
finishOAuth,
|
||||||
@@ -17,6 +19,7 @@ import {
|
|||||||
linkOAuthAccount,
|
linkOAuthAccount,
|
||||||
startOAuth,
|
startOAuth,
|
||||||
unlinkOAuthAccount,
|
unlinkOAuthAccount,
|
||||||
|
type AssetResponseDto,
|
||||||
type MemoryResponseDto,
|
type MemoryResponseDto,
|
||||||
type PersonResponseDto,
|
type PersonResponseDto,
|
||||||
type ServerVersionResponseDto,
|
type ServerVersionResponseDto,
|
||||||
@@ -191,6 +194,37 @@ const createUrl = (path: string, parameters?: Record<string, unknown>) => {
|
|||||||
|
|
||||||
type AssetUrlOptions = { id: string; cacheKey?: string | null };
|
type AssetUrlOptions = { id: string; cacheKey?: string | null };
|
||||||
|
|
||||||
|
export const getAssetUrl = ({
|
||||||
|
asset,
|
||||||
|
sharedLink,
|
||||||
|
forceOriginal = false,
|
||||||
|
}: {
|
||||||
|
asset: AssetResponseDto;
|
||||||
|
sharedLink?: SharedLinkResponseDto;
|
||||||
|
forceOriginal?: boolean;
|
||||||
|
}) => {
|
||||||
|
const id = asset.id;
|
||||||
|
const cacheKey = asset.thumbhash;
|
||||||
|
if (sharedLink && (!sharedLink.allowDownload || !sharedLink.showMetadata)) {
|
||||||
|
return getAssetThumbnailUrl({ id, size: AssetMediaSize.Preview, cacheKey });
|
||||||
|
}
|
||||||
|
const targetSize = targetImageSize(asset, forceOriginal);
|
||||||
|
return targetSize === 'original'
|
||||||
|
? getAssetOriginalUrl({ id, cacheKey })
|
||||||
|
: getAssetThumbnailUrl({ id, size: targetSize, cacheKey });
|
||||||
|
};
|
||||||
|
|
||||||
|
const forceUseOriginal = (asset: AssetResponseDto) => {
|
||||||
|
return asset.type === AssetTypeEnum.Image && asset.duration && !asset.duration.includes('0:00:00.000');
|
||||||
|
};
|
||||||
|
|
||||||
|
export const targetImageSize = (asset: AssetResponseDto, forceOriginal: boolean) => {
|
||||||
|
if (forceOriginal || get(alwaysLoadOriginalFile) || forceUseOriginal(asset)) {
|
||||||
|
return isWebCompatibleImage(asset) ? 'original' : AssetMediaSize.Fullsize;
|
||||||
|
}
|
||||||
|
return AssetMediaSize.Preview;
|
||||||
|
};
|
||||||
|
|
||||||
export const getAssetOriginalUrl = (options: string | AssetUrlOptions) => {
|
export const getAssetOriginalUrl = (options: string | AssetUrlOptions) => {
|
||||||
if (typeof options === 'string') {
|
if (typeof options === 'string') {
|
||||||
options = { id: options };
|
options = { id: options };
|
||||||
|
|||||||
Reference in New Issue
Block a user