Some checks failed
build-and-deploy / build-and-deploy (push) Has been cancelled
- Agregar share_target al manifest de la PWA - Crear endpoint /api/share-target para recibir archivos compartidos - Guardar archivos temporalmente en /public/temp-shared - Modificar UserProfileForm para aceptar imágenes externas - Detectar automáticamente imágenes compartidas y procesarlas - Crear endpoint /api/share-target/cleanup para limpiar temporales - Mostrar toast informativo al recibir imagen compartida - Redirigir automáticamente al formulario de perfil - Soportar compartir desde galería, otras apps, etc.
65 lines
1.8 KiB
JavaScript
65 lines
1.8 KiB
JavaScript
/*
|
|
Service worker para la app DayNight. Este script cachea recursos estáticos
|
|
durante la instalación para que se puedan servir sin conexión. Según MDN, en
|
|
el evento de instalación se deben abrir los caches y agregar recursos con
|
|
`addAll()`【407555884650804†L360-L410】, y luego interceptar las peticiones y
|
|
responder desde el cache cuando sea posible【407555884650804†L205-L213】.
|
|
*/
|
|
|
|
const CACHE_NAME = 'daynight-cache-v1';
|
|
const ASSETS = [
|
|
'/',
|
|
'/index.html',
|
|
'/manifest.json',
|
|
'/icons/icon-72x72.png',
|
|
'/icons/icon-96x96.png',
|
|
'/icons/icon-128x128.png',
|
|
'/icons/icon-144x144.png',
|
|
'/icons/icon-152x152.png',
|
|
'/icons/icon-192x192.png',
|
|
'/icons/icon-256x256.png',
|
|
'/icons/icon-384x384.png',
|
|
'/icons/icon-512x512.png'
|
|
];
|
|
|
|
self.addEventListener('install', (event) => {
|
|
event.waitUntil(
|
|
caches.open(CACHE_NAME).then((cache) => {
|
|
return cache.addAll(ASSETS);
|
|
})
|
|
);
|
|
});
|
|
|
|
self.addEventListener('activate', (event) => {
|
|
event.waitUntil(
|
|
caches.keys().then((names) => {
|
|
return Promise.all(
|
|
names.map((name) => {
|
|
if (name !== CACHE_NAME) {
|
|
return caches.delete(name);
|
|
}
|
|
})
|
|
);
|
|
})
|
|
);
|
|
});
|
|
|
|
self.addEventListener('fetch', (event) => {
|
|
event.respondWith(
|
|
caches.match(event.request).then((cached) => {
|
|
if (cached) {
|
|
return cached;
|
|
}
|
|
return fetch(event.request).then((networkResponse) => {
|
|
if (!networkResponse || networkResponse.status !== 200 || networkResponse.type !== 'basic') {
|
|
return networkResponse;
|
|
}
|
|
const responseClone = networkResponse.clone();
|
|
caches.open(CACHE_NAME).then((cache) => {
|
|
cache.put(event.request, responseClone);
|
|
});
|
|
return networkResponse;
|
|
});
|
|
})
|
|
);
|
|
}); |