1const cacheName = 'ffmpegweb-cache'; 2const filestoCache = [ 3 './', 4 './index.html', 5 './icon.png', 6 './icon.svg', 7 './manifest.json', 8 './assets/_commonjsHelpers.js', 9 './assets/index.css', 10 './assets/index.js', 11 './assets/index2.js', 12 './assets/index3.js', 13 './assets/index4.js', 14 './assets/index5.js', 15 './assets/jszip.min.js', 16 './assets/worker-lPYB70QI.js', 17 'https://unpkg.com/@ffmpeg/[email protected]/dist/ffmpeg-core.wasm', 18 'https://unpkg.com/@ffmpeg/[email protected]/dist/ffmpeg-core.worker.js', 19 'https://unpkg.com/@ffmpeg/[email protected]/dist/ffmpeg-core.js', 20 'https://unpkg.com/@ffmpeg/[email protected]/dist/esm/ffmpeg-core.js', 21 'https://unpkg.com/@ffmpeg/[email protected]/dist/esm/ffmpeg-core.wasm', 22 'https://unpkg.com/@ffmpeg/[email protected]/dist/esm/ffmpeg-core.worker.js', 23]; 24self.addEventListener('install', e => { 25 e.waitUntil( 26 caches.open(cacheName) 27 .then(cache => cache.addAll(filestoCache)) 28 ); 29}); 30self.addEventListener('activate', e => self.clients.claim()); 31self.addEventListener('fetch', event => { 32 const req = event.request; 33 if (req.url.indexOf("updatecode") !== -1 || new URL(req.url).origin !== self.location.origin) { 34 return; 35 } else event.respondWith(networkFirst(req)); 36}); 37/** 38 * The BroadcastChannel used to communicate with the main window 39 */ 40const comms = new BroadcastChannel("comms"); 41/** 42 * The Map that contains the zip file ID as the key, and the TransformStream and its writer as a value. 43 */ 44const zipStreams = new Map(); 45self.addEventListener("message", (msg) => { 46 switch (msg.data.action) { 47 case "CreateStream": { 48 const stream = new TransformStream(); 49 zipStreams.set(msg.data.id, { 50 stream, 51 writer: stream.writable.getWriter() 52 }); 53 comms.postMessage({ action: "SuccessStream", id: msg.data.id }); 54 break; 55 } 56 case "WriteChunk": { 57 const stream = zipStreams.get(msg.data.id); 58 if (stream) { 59 /** 60 * @type WritableStreamDefaultWriter 61 */ 62 const writer = stream.writer; 63 writer.write(msg.data.chunk).then(() => { 64 comms.postMessage({action: "SuccessWrite", operationId: msg.data.operationId}) 65 }); 66 } 67 break; 68 } 69 case "CloseStream": { 70 const stream = zipStreams.get(msg.data.id); 71 if (stream) { 72 stream.writer.close(); 73 } 74 comms.postMessage({ action: "SuccessClose", id: msg.data.id }); 75 break; 76 } 77 } 78}) 79 80async function networkFirst(req) { 81 const getStream = zipStreams.get(req.url.substring(req.url.lastIndexOf("/downloader?id=") + "/downloader?id=".length)); // Look if the request is tied with a local zip file. In this case, the readable stream needs to be returned. 82 if (getStream) { 83 return new Response(getStream.stream.readable, { 84 headers: { 85 "Content-Disposition": `attachment; filename="FfmpegWeb-Zip-${Date.now()}.zip"`, 86 "Content-Type": "application/zip" 87 } 88 }) 89 } 90 if (req.url.endsWith("/ping")) return new Response("Success."); 91 try { 92 const networkResponse = await fetch(req); 93 const cache = await caches.open(cacheName); 94 await cache.delete(req); 95 await cache.put(req, networkResponse.clone()); 96 return networkResponse; 97 } catch (error) { 98 const cachedResponse = await caches.match(req); 99 return cachedResponse; 100 } 101}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.