| Server IP : 162.214.74.102 / Your IP : 216.73.217.46 Web Server : Apache System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64 User : lrsys ( 1015) PHP Version : 5.6.40 Disable Function : exec,passthru,shell_exec,system MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/lrsys/www/lrsys_apps/leve/application/plugins/module_helpdesk/assets/js/ |
Upload File : |
const CACHE_NAME = 'helpdesk-hexagon-cache-v3'; // Versão do cache para forçar atualização
// Lista de URLs que você deseja armazenar em cache
const INITIAL_CACHED_RESOURCES = [
'/?ng=module_helpdesk/ticket/listAll&cache',
'/ui/lib/bottomBar/bottom_bar.js'
// Certifique-se de adicionar a página offline
];
// Instalação do service worker
self.addEventListener('install', event => {
event.waitUntil((async () => {
const cache = await caches.open(CACHE_NAME);
try {
await cache.addAll(INITIAL_CACHED_RESOURCES);
} catch (error) {
console.error('Falha ao adicionar recursos ao cache:', error);
}
})());
});
// Evento de fetch
self.addEventListener('fetch', event => {
event.respondWith((async () => {
const cache = await caches.open(CACHE_NAME);
// Tente obter a resposta do cache primeiro.
const cachedResponse = await cache.match(event.request);
if (cachedResponse !== undefined) {
// Cache hit, retorna o recurso em cache.
return cachedResponse;
} else {
// Nada no cache, tente buscar na rede.
try {
const fetchResponse = await fetch(event.request);
// Salve o novo recurso no cache (as respostas são streams, então precisamos clonar para usar aqui).
cache.put(event.request, fetchResponse.clone());
// E retorne a resposta da rede.
return fetchResponse;
} catch (error) {
// A busca falhou, retorne a página offline.
if (event.request.mode === 'navigate') {
const errorResponse = await cache.match('./offline.html');
return errorResponse || new Response('Página offline não disponível.', { status: 503 });
}
throw error;
}
}
})());
});
// Lidar com ativação do service worker
self.addEventListener('activate', event => {
console.log(event);
return true;
event.waitUntil((async () => {
// Obtenha todos os nomes de cache
const cacheNames = await caches.keys();
// Espere até que todas as promessas de exclusão sejam resolvidas
await Promise.all(
cacheNames.map(name => {
if (name !== CACHE_NAME) {
return caches.delete(name);
}
})
);
})());
});
self.addEventListener('fetch', function(event) {
console.log(event);
return true;
event.respondWith(
caches.match(event.request).then(function(response) {
// Retorna a resposta do cache se estiver disponível
if (response) {
return response;
}
// Se o recurso não estiver em cache, faz a solicitação de rede normalmente
return fetch(event.request);
}).catch(function() {
// Se houver erro ao acessar o cache ou a rede, exibe uma página de erro ou uma mensagem
return new Response('Você está offline. Por favor, verifique sua conexão com a internet.');
})
);
});