telegram-tt/dist/524.0664b1e0b71af4d55173.js

2 lines
5.7 KiB
JavaScript
Raw Normal View History

2021-10-08 15:19:58 +02:00
(()=>{"use strict";const e="tt-media-progressive",t="tt-assets",s=("undefined"!=typeof window&&window.innerHeight,Math.round(425),new Set(["newMessage","newScheduledMessage","deleteMessages","deleteScheduledMessages","deleteHistory"]),new Set(["image/png","image/gif","image/jpeg"])),n=new Set(["video/mp4"]);new Set([...s,...n]);const a=e=>new Promise((t=>{setTimeout((()=>t()),e)})),i=524288,r=new Map;async function o(e){const s=await async function(s,n){try{return await Promise.race([a(3e3).then((()=>Promise.reject(new Error("TIMEOUT")))),(async()=>{const s=await self.caches.open(t),n=await s.match(e.request);return{cache:s,cached:n}})()])}catch(e){return void console.error(e)}}(),{cache:n,cached:i}=s||{};if(n&&i){if(i.ok)return i;await n.delete(e.request)}const r=await fetch(e.request);return r.ok&&n&&n.put(e.request,r.clone()),r}var c,d;self.addEventListener("message",(e=>{const{type:t,messageId:s,result:n}=e.data;if("partResponse"===t){const e=r.get(s);e&&e.resolve(n)}})),(d=c||(c={})).True="1",d.False="0";let l=(new Date).valueOf();const u=new Set,f={};function g(e){return e.custom.from_id?parseInt(e.custom.from_id,10):e.custom.chat_id?-1*parseInt(e.custom.chat_id,10):e.custom.channel_id?-1*parseInt(e.custom.channel_id,10):void 0}function p(e){if(e.custom.msg_id)return parseInt(e.custom.msg_id,10)}async function w(e){const t=(await self.clients.matchAll({type:"window"})).filter((e=>e.url===self.registration.scope)),s=t[0];s&&0!==t.length&&s.postMessage({type:"playNotificationSound",payload:{id:e}})}function h({chatId:e,messageId:t,body:s,title:n,icon:a}){const i=(new Date).valueOf()-l<1e3,r={body:s,data:{chatId:e,messageId:t,count:1},icon:a||"icon-192x192.png",badge:"icon-192x192.png",tag:String(i?0:e||0),vibrate:[200,100,200]};return Promise.all([w(t||e||0),self.registration.showNotification(n,r)])}async function m(e,t){const{chatId:s,messageId:n}=t;if(s){e.postMessage({type:"focusMessage",payload:{chatId:s,messageId:n}});try{await e.focus()}catch(e){}}}self.onsync=()=>{l=(new Date).valueOf()};const y=/[0-9a-f]{20}.*\.(js|css|woff2?|svg|png|jpg|jpeg|json|wasm)$/;self.addEventListener("install",(e=>{e.waitUntil(self.skipWaiting())})),self.addEventListener("activate",(e=>{e.waitUntil(Promise.race([a(3e3),Promise.all([self.caches.delete(t),self.clients.claim()])]))})),self.addEventListener("fetch",(t=>{const{url:s}=t.request;return s.includes("/progressive/")?(t.respondWith(async function(t){const{url:s}=t.request,n=t.request.headers.get("range"),o=/^bytes=(\d+)-(\d+)?$/g.exec(n||""),c=Number(o[1]);let d=Number(o[2]);if((!d||d-c+1>i)&&(d=c+i-1),0===c&&1===d){const e=t.request.url.match(/fileSize=(\d+)&mimeType=([\w/]+)/),s=e&&Number(e[1]),n=null==e?void 0:e[2];if(s&&n)return new Response(new Uint8Array(2).buffer,{status:206,statusText:"Partial Content",headers:[["Content-Range",`bytes 0-1/${s}`],["Accept-Ranges","bytes"],["Content-Length","2"],["Content-Type",n]]})}const l=`${s}?start=${c}&end=${d}`,[u,f]=await async function(t){const s=await self.caches.open(e);return Promise.all([s.match(`${t}&type=arrayBuffer`).then((e=>e?e.arrayBuffer():void 0)),s.match(`${t}&type=headers`).then((e=>e?e.json():void 0))])}(l);if(u)return new Response(u,{status:206,statusText:"Partial Content",headers:f});let g;try{g=await async function(e,t){if(!e.clientId)return;const s=await self.clients.get(e.clientId);if(!s)return;const n=(e=>{let t;do{t=String(Math.random()).replace("0.","id")}while(e.hasOwnProperty(t));return t})(r),i={},o=Promise.race([a(6e4).then((()=>Promise.reject(new Error("ERROR_PART_TIMEOUT")))),new Promise(((e,t)=>{Object.assign(i,{resolve:e,reject:t})}))]);return r.set(n,i),o.catch((()=>{})).finally((()=>{r.delete(n)})),s.postMessage({type:"requestPart",messageId:n,params:t}),o}(t,{url:s,start:c,end:d})}catch(e){}if(!g)return new Response("",{status:500,statusText:"Failed to fetch progressive part"});const{arrayBuffer:p,fullSize:w,mimeType:h}=g,m=Math.min(d-c+1,p.byteLength);d=c+m-1;const y=p.slice(0,m),I=[["Content-Range",`bytes ${c}-${d}/${w}`],["Accept-Ranges","bytes"],["Content-Length",String(m)],["Content-Type",
2021-10-15 15:49:23 +02:00
//# sourceMappingURL=524.0664b1e0b71af4d55173.js.map