mirror of
https://github.com/immich-app/immich.git
synced 2025-06-03 05:34:32 -04:00
minor tweaks
This commit is contained in:
parent
00bcf659c3
commit
92befd87a7
@ -1,9 +1,6 @@
|
|||||||
import { build, files, version } from '$service-worker';
|
import { build, files, version } from '$service-worker';
|
||||||
|
|
||||||
const pendingLoads = new Map<string, AbortController>();
|
|
||||||
|
|
||||||
const useCache = true;
|
const useCache = true;
|
||||||
// Create a unique cache name for this deployment
|
|
||||||
const CACHE = `cache-${version}`;
|
const CACHE = `cache-${version}`;
|
||||||
|
|
||||||
export const APP_RESOURCES = [
|
export const APP_RESOURCES = [
|
||||||
@ -11,6 +8,9 @@ export const APP_RESOURCES = [
|
|||||||
...files, // everything in `static`
|
...files, // everything in `static`
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export const isURL = (request: URL | RequestInfo): request is URL => (request as URL).href !== undefined;
|
||||||
|
export const isRequest = (request: RequestInfo): request is Request => (request as Request).url !== undefined;
|
||||||
|
|
||||||
export async function deleteOldCaches() {
|
export async function deleteOldCaches() {
|
||||||
for (const key of await caches.keys()) {
|
for (const key of await caches.keys()) {
|
||||||
if (key !== CACHE) {
|
if (key !== CACHE) {
|
||||||
@ -24,8 +24,15 @@ export async function addFilesToCache() {
|
|||||||
await cache.addAll(APP_RESOURCES);
|
await cache.addAll(APP_RESOURCES);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const isURL = (request: URL | RequestInfo): request is URL => (request as URL).href !== undefined;
|
const pendingLoads = new Map<string, AbortController>();
|
||||||
export const isRequest = (request: RequestInfo): request is Request => (request as Request).url !== undefined;
|
|
||||||
|
export async function cancelLoad(urlString: string) {
|
||||||
|
const pending = pendingLoads.get(urlString);
|
||||||
|
if (pending) {
|
||||||
|
pending.abort();
|
||||||
|
pendingLoads.delete(urlString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function getCachedOrFetch(request: URL | Request | string, cancelable: boolean = false) {
|
export async function getCachedOrFetch(request: URL | Request | string, cancelable: boolean = false) {
|
||||||
const cached = await checkCache(request);
|
const cached = await checkCache(request);
|
||||||
@ -42,7 +49,6 @@ export async function getCachedOrFetch(request: URL | Request | string, cancelab
|
|||||||
|
|
||||||
return await fetchWithCancellation(request, cached.cache);
|
return await fetchWithCancellation(request, cached.cache);
|
||||||
} catch {
|
} catch {
|
||||||
console.log('getCachedOrFetch error', request);
|
|
||||||
return new Response(undefined, {
|
return new Response(undefined, {
|
||||||
status: 499,
|
status: 499,
|
||||||
statusText: 'Request canceled: Instructions unclear, accidentally interrupted myself',
|
statusText: 'Request canceled: Instructions unclear, accidentally interrupted myself',
|
||||||
@ -50,14 +56,6 @@ export async function getCachedOrFetch(request: URL | Request | string, cancelab
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function cancelLoad(urlString: string) {
|
|
||||||
const pending = pendingLoads.get(urlString);
|
|
||||||
if (pending) {
|
|
||||||
pending.abort();
|
|
||||||
pendingLoads.delete(urlString);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function fetchWithCancellation(request: URL | Request | string, cache: Cache) {
|
async function fetchWithCancellation(request: URL | Request | string, cache: Cache) {
|
||||||
const cacheKey = getCacheKey(request);
|
const cacheKey = getCacheKey(request);
|
||||||
const cancelToken = new AbortController();
|
const cancelToken = new AbortController();
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
/// <reference lib="webworker" />
|
/// <reference lib="webworker" />
|
||||||
import { installBroadcastChannelListener } from './broadcast-channel';
|
import { installBroadcastChannelListener } from './broadcast-channel';
|
||||||
import { addFilesToCache, deleteOldCaches } from './cache';
|
import { addFilesToCache, deleteOldCaches } from './cache';
|
||||||
import { handleFetchEvent } from './fetchEvent';
|
import { handleFetchEvent } from './fetch-event';
|
||||||
|
|
||||||
const sw = globalThis as unknown as ServiceWorkerGlobalScope;
|
const sw = globalThis as unknown as ServiceWorkerGlobalScope;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user