telegram-tt/dist/524.af6f31b37dd7937fdd14.js

2 lines
5.3 KiB
JavaScript
Raw Normal View History

2021-08-20 22:51:08 +02:00
(()=>{"use strict";const e="tt-media-progressive",t="tt-assets";"undefined"!=typeof window&&window.innerHeight,Math.round(425),new Set(["newMessage","newScheduledMessage","deleteMessages","deleteScheduledMessages","deleteHistory"]),new Set(["image/png","image/gif","image/jpeg","video/mp4","video/avi","video/quicktime"]);const s=524288,n=new Map;var a,i;self.addEventListener("message",(e=>{const{type:t,messageId:s,result:a}=e.data;if("partResponse"===t){const e=n.get(s);e&&e.resolve(a)}})),(i=a||(a={})).True="1",i.False="0";let o=(new Date).valueOf();const r=new Set,c={};function d(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 l(e){if(e.custom.msg_id)return parseInt(e.custom.msg_id,10)}async function u(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}})}async function f({chatId:e,messageId:t,body:s,title:n,icon:a}){const i=String(e||0),o={body:s,data:{chatId:e,messageId:t,count:1},icon:a||"icon-192x192.png",badge:"icon-192x192.png",tag:i,vibrate:[200,100,200]},r=await self.registration.getNotifications({tag:i});if(r.length>0){const e=r[0],t=e.data.count+1;o.data.count=t,o.data.messageId=e.data.messageId,o.body=`You have ${t} new messages`,e.close()}return Promise.all([u(t||e||0),self.registration.showNotification(n,o)])}async function g(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=()=>{o=(new Date).valueOf()};const p=/[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(self.caches.delete(t)),e.waitUntil(self.clients.claim())})),self.addEventListener("fetch",(a=>{const{url:i}=a.request;return i.includes("/progressive/")?(a.respondWith(async function(t){const{url:a}=t.request,i=t.request.headers.get("range"),o=/^bytes=(\d+)-(\d+)?$/g.exec(i||""),r=Number(o[1]);let c=Number(o[2]);if((!c||c-r+1>s)&&(c=r+s-1),0===r&&1===c){const e=t.request.url.match(/fileSize=(\d+)&mimeType=([\w/]+)/),s=e&&Number(e[1]),n=e&&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 d=`${a}?start=${r}&end=${c}`,[l,u]=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))])}(d);if(l)return new Response(l,{status:206,statusText:"Partial Content",headers:u});let f;try{f=await async function(e,t){if(!e.clientId)return;const s=await self.clients.get(e.clientId);if(!s)return;const a=(e=>{let t;do{t=String(Math.random()).replace("0.","id")}while(e.hasOwnProperty(t));return t})(n),i={},o=Promise.race([(r=6e4,new Promise((e=>{setTimeout((()=>e()),r)}))).then((()=>Promise.reject(new Error("ERROR_PART_TIMEOUT")))),new Promise(((e,t)=>{Object.assign(i,{resolve:e,reject:t})}))]);var r;return n.set(a,i),o.catch((()=>{})).finally((()=>{n.delete(a)})),s.postMessage({type:"requestPart",messageId:a,params:t}),o}(t,{url:a,start:r,end:c})}catch(e){}if(!f)return new Response("",{status:500,statusText:"Failed to fetch progressive part"});const{arrayBuffer:g,fullSize:p,mimeType:m}=f,w=Math.min(c-r+1,g.byteLength);c=r+w-1;const h=g.slice(0,w),y=[["Content-Range",`bytes ${r}-${c}/${p}`],["Accept-Ranges","bytes"],["Content-Length",String(w)],["Content-Type",m]];return w<=524288&&c<2097151&&async function(t,s,n){const a=await self.caches.open(e);Promise.all([a.put(new Request(`${t}&type=arrayBuffer`),new Response(s)),a.put(new Request(`${t}&type=headers`),new Response(JSON.stringify(n)))])}(d,h,y),new Response(h,{status:206,statusText:"Partial Content",headers:y})}(
2021-08-21 13:36:25 +02:00
//# sourceMappingURL=524.af6f31b37dd7937fdd14.js.map