mirror of
https://github.com/immich-app/immich.git
synced 2026-01-23 09:58:56 -08:00
35 lines
822 B
TypeScript
35 lines
822 B
TypeScript
import { getAssetUrl } from '$lib/utils';
|
|
import { cancelImageUrl } from '$lib/utils/sw-messaging';
|
|
import { AssetTypeEnum, type AssetResponseDto } from '@immich/sdk';
|
|
|
|
class PreloadManager {
|
|
preload(asset: AssetResponseDto | undefined) {
|
|
if (!asset || asset.type !== AssetTypeEnum.Image) {
|
|
return;
|
|
}
|
|
const img = new Image();
|
|
const url = getAssetUrl({ asset });
|
|
if (!url) {
|
|
return;
|
|
}
|
|
img.src = url;
|
|
}
|
|
|
|
cancel(asset: AssetResponseDto | undefined) {
|
|
if (!globalThis.isSecureContext || !asset) {
|
|
return;
|
|
}
|
|
const url = getAssetUrl({ asset });
|
|
cancelImageUrl(url);
|
|
}
|
|
|
|
cancelPreloadUrl(url: string | undefined) {
|
|
if (!globalThis.isSecureContext) {
|
|
return;
|
|
}
|
|
cancelImageUrl(url);
|
|
}
|
|
}
|
|
|
|
export const preloadManager = new PreloadManager();
|