fix: recover old GTIN service worker caches
This commit is contained in:
33
src/gtin/js/aktualisieren.js
Normal file
33
src/gtin/js/aktualisieren.js
Normal file
@@ -0,0 +1,33 @@
|
||||
/* Entfernt die umgeleitete Startantwort aus frueheren GTIN-Caches. */
|
||||
|
||||
const status = document.querySelector('#status');
|
||||
const appUrl = new URL('../', window.location.href);
|
||||
const alterIndex = new URL('index.html', appUrl).href;
|
||||
|
||||
async function aktualisiereWerkzeug() {
|
||||
if ('caches' in window) {
|
||||
const namen = await caches.keys();
|
||||
for (const name of namen) {
|
||||
if (!name.startsWith('desfoto-gtin-generator-')) continue;
|
||||
const cache = await caches.open(name);
|
||||
const antwort = await cache.match(alterIndex);
|
||||
if (antwort?.redirected) await cache.delete(alterIndex);
|
||||
}
|
||||
}
|
||||
|
||||
if ('serviceWorker' in navigator) {
|
||||
const registrierung = await navigator.serviceWorker.getRegistration(appUrl.href);
|
||||
if (registrierung) {
|
||||
await Promise.race([
|
||||
registrierung.update().catch(() => undefined),
|
||||
new Promise((resolve) => window.setTimeout(resolve, 5000)),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
window.location.replace(appUrl.href);
|
||||
}
|
||||
|
||||
aktualisiereWerkzeug().catch(() => {
|
||||
status.textContent = 'Die Aktualisierung ist fehlgeschlagen. Bitte lösche die Website-Daten für desfoto.de in deinem Browser und öffne das Werkzeug erneut.';
|
||||
});
|
||||
Reference in New Issue
Block a user