mirror of
https://github.com/immich-app/immich.git
synced 2025-05-24 01:12:58 -04:00
minor tweaks
This commit is contained in:
parent
00bcf659c3
commit
92befd87a7
@ -1,9 +1,6 @@
|
||||
import { build, files, version } from '$service-worker';
|
||||
|
||||
const pendingLoads = new Map<string, AbortController>();
|
||||
|
||||
const useCache = true;
|
||||
// Create a unique cache name for this deployment
|
||||
const CACHE = `cache-${version}`;
|
||||
|
||||
export const APP_RESOURCES = [
|
||||
@ -11,6 +8,9 @@ export const APP_RESOURCES = [
|
||||
...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() {
|
||||
for (const key of await caches.keys()) {
|
||||
if (key !== CACHE) {
|
||||
@ -24,8 +24,15 @@ export async function addFilesToCache() {
|
||||
await cache.addAll(APP_RESOURCES);
|
||||
}
|
||||
|
||||
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;
|
||||
const pendingLoads = new Map<string, AbortController>();
|
||||
|
||||
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) {
|
||||
const cached = await checkCache(request);
|
||||
@ -42,7 +49,6 @@ export async function getCachedOrFetch(request: URL | Request | string, cancelab
|
||||
|
||||
return await fetchWithCancellation(request, cached.cache);
|
||||
} catch {
|
||||
console.log('getCachedOrFetch error', request);
|
||||
return new Response(undefined, {
|
||||
status: 499,
|
||||
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) {
|
||||
const cacheKey = getCacheKey(request);
|
||||
const cancelToken = new AbortController();
|
||||
|
@ -4,7 +4,7 @@
|
||||
/// <reference lib="webworker" />
|
||||
import { installBroadcastChannelListener } from './broadcast-channel';
|
||||
import { addFilesToCache, deleteOldCaches } from './cache';
|
||||
import { handleFetchEvent } from './fetchEvent';
|
||||
import { handleFetchEvent } from './fetch-event';
|
||||
|
||||
const sw = globalThis as unknown as ServiceWorkerGlobalScope;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user