From 34ffa32571e03e88c37a4bfdda1dbaaf500ae487 Mon Sep 17 00:00:00 2001 From: EduardSkibidiEdger Date: Sun, 24 Nov 2024 15:13:56 +0200 Subject: [PATCH] sgdfj --- index.js | 14 +++++++------- service-worker.js | 30 ++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index c1cb8ac..9a5a4c7 100644 --- a/index.js +++ b/index.js @@ -1011,24 +1011,24 @@ const webamp = new Webamp({ }, { "metaData": { - "artist": "6.prigoana.lol2.prigoana.lolPac", + "artist": "2Pac", "title": "California Love (Original Version)" }, - "url": "https://6.prigoana.lol2.prigoana.lolPac - California Love (Original Version).flac" + "url": "https://6.prigoana.lol/2Pac%20-%20California%20Love%20(Original%20Version).flac" }, { "metaData": { - "artist": "6.prigoana.lol2.prigoana.lolPac", + "artist": "2Pac", "title": "Dear Mama (Album Version (Explicit))" }, - "url": "https://6.prigoana.lol2.prigoana.lolPac - Dear Mama (Album Version (Explicit)).flac" + "url": "https://6.prigoana.lol/2Pac - Dear Mama (Album Version (Explicit)).flac" }, { "metaData": { - "artist": "6.prigoana.lol2.prigoana.lolPac", + "artist": "2Pac", "title": "Hit 'Em Up (Single Version)" }, - "url": "https://6.prigoana.lol2.prigoana.lolPac - Hit 'Em Up (Single Version).flac" + "url": "https://6.prigoana.lol/2Pac - Hit 'Em Up (Single Version).flac" }, { "metaData": { @@ -1644,7 +1644,7 @@ const webamp = new Webamp({ "artist": "Immortal Technique", "title": "Dance With The Devil" }, - "url": "https://9.prigoana.lol/Immortal Technique - Dance with the Devil" + "url": "https://9.prigoana.lol/Immortal Technique - Dance with the Devil.flac" }, { "metaData": { diff --git a/service-worker.js b/service-worker.js index be7386f..b7d3bf3 100644 --- a/service-worker.js +++ b/service-worker.js @@ -8,6 +8,7 @@ const URLS_TO_CACHE = [ 'https://lastfm.freetls.fastly.net/' ]; +// Install event: Pre-cache the static resources self.addEventListener('install', function(event) { event.waitUntil( caches.open(CACHE_NAME) @@ -17,15 +18,36 @@ self.addEventListener('install', function(event) { ); }); +// Fetch event: Serve cached files and dynamically cache .mp3 or .flac files self.addEventListener('fetch', function(event) { + const requestUrl = new URL(event.request.url); + event.respondWith( - caches.match(event.request) - .then(function(response) { - return response || fetch(event.request); - }) + caches.match(event.request).then(function(response) { + // If the resource is already cached, return it + if (response) { + return response; + } + + // Otherwise, fetch the resource and check if it's an audio file + return fetch(event.request).then(function(fetchResponse) { + // Clone the response (responses can only be used once) + const fetchResponseClone = fetchResponse.clone(); + + // Check if the file ends with .mp3 or .flac + if (requestUrl.pathname.endsWith('.mp3') || requestUrl.pathname.endsWith('.flac')) { + caches.open(CACHE_NAME).then(function(cache) { + cache.put(event.request, fetchResponseClone); + }); + } + + return fetchResponse; + }); + }) ); }); +// Activate event: Clean up old caches self.addEventListener('activate', function(event) { event.waitUntil( caches.keys().then(function(cacheNames) {