mirror of
https://github.com/danog/telegram-tt.git
synced 2024-12-15 10:47:04 +01:00
1 line
3.8 KiB
JavaScript
1 line
3.8 KiB
JavaScript
!function(e){var t={};function n(s){if(t[s])return t[s].exports;var r=t[s]={i:s,l:!1,exports:{}};return e[s].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=e,n.c=t,n.d=function(e,t,s){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:s})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var s=Object.create(null);if(n.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(s,r,function(t){return e[t]}.bind(null,r));return s},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";n.r(t);new Set(["newMessage","newScheduledMessage","deleteMessages","deleteScheduledMessages","deleteHistory"]),"undefined"!=typeof window&&window.innerHeight;const s=new Map;async function r(e){const{url:t}=e.request,n=e.request.headers.get("range"),r=/^bytes=(\d+)-(\d+)?$/g.exec(n||""),a=Number(r[1]),i=Number(r[2]);let o=i;if((!o||o-a+1>524288)&&(o=a+524288-1),0===a&&1===o){const t=e.request.url.match(/fileSize=(\d+)&mimeType=([\w/]+)/),n=t&&Number(t[1]),s=t&&t[2];if(n&&s)return new Response(new Uint8Array(2).buffer,{status:206,statusText:"Partial Content",headers:[["Content-Range","bytes 0-1/"+n],["Accept-Ranges","bytes"],["Content-Length","2"],["Content-Type",s]]})}const u=`${t}?start=${a}&end=${o}`,[c,l]=await async function(e){const t=await self.caches.open("tt-media-progressive");return Promise.all([t.match(e+"&type=arrayBuffer").then(e=>e?e.arrayBuffer():void 0),t.match(e+"&type=headers").then(e=>e?e.json():void 0)])}(u);if(c)return new Response(c,{status:206,statusText:"Partial Content",headers:l});let f;try{f=await async function(e,t){if(!e.clientId)return;const n=await self.clients.get(e.clientId);if(!n)return;const r=(e=>{let t;do{t=String(Math.random()).replace("0.","id")}while(e.hasOwnProperty(t));return t})(s),a={},i=Promise.race([(o=3e4,new Promise(e=>{setTimeout(()=>e(),o)})).then(()=>Promise.reject(new Error("ERROR_PART_TIMEOUT"))),new Promise((e,t)=>{Object.assign(a,{resolve:e,reject:t})})]);var o;return s.set(r,a),i.catch(()=>{}).finally(()=>{s.delete(r)}),n.postMessage({type:"requestPart",messageId:r,params:t}),i}(e,{url:t,start:a,end:o})}catch(e){0}if(!f)return new Response("",{status:500,statusText:"Failed to fetch progressive part"});const{arrayBuffer:d,fullSize:p,mimeType:y}=f,g=Math.min(o-a+1,d.byteLength);o=a+g-1;const w=d.slice(0,g),h=[["Content-Range",`bytes ${a}-${o}/${p}`],["Accept-Ranges","bytes"],["Content-Length",String(g)],["Content-Type",y]];return g<=524288&&o<2097151&&async function(e,t,n){const s=await self.caches.open("tt-media-progressive");Promise.all([s.put(new Request(e+"&type=arrayBuffer"),new Response(t)),s.put(new Request(e+"&type=headers"),new Response(JSON.stringify(n)))])}(u,w,h),new Response(w,{status:206,statusText:"Partial Content",headers:h})}self.addEventListener("message",e=>{const{type:t,messageId:n,result:r}=e.data;if("partResponse"===t){const e=s.get(n);e&&e.resolve(r)}});const a=/[0-9a-f]{20}.*\.(js|css|woff2?|svg|png|jpg|json|wasm)$/;self.addEventListener("install",e=>{e.waitUntil(self.skipWaiting())}),self.addEventListener("activate",e=>{e.waitUntil(self.caches.delete("tt-assets")),e.waitUntil(self.clients.claim())}),self.addEventListener("fetch",e=>{e.respondWith((()=>{const{url:t}=e.request;return t.includes("/progressive/")?r(e):t.match(a)?async function(e){const t=await self.caches.open("tt-assets"),n=await t.match(e.request);if(n)return n;const s=await fetch(e.request);return t.put(e.request,s.clone()),s}(e):fetch(e.request)})())})}]); |