TelegramPWA/dist/125.a148b005feb070ac70b9.js
Alexander Zinchuk 236dfc0cd2 [Build]
2023-06-21 18:35:31 +02:00

2 lines
8.7 KiB
JavaScript

"use strict";(self.webpackChunktelegram_t=self.webpackChunktelegram_t||[]).push([[125],{40125:(e,t,n)=>{const s="tt-media-progressive",a="tt-assets",i=("undefined"!=typeof window&&window.innerHeight,Math.round(450),new Set(["newMessage","newScheduledMessage","deleteMessages","deleteScheduledMessages","deleteHistory"]),new Set(["image/png","image/jpeg","image/gif"])),o=new Set(["video/mp4"]);new Set(["audio/mp3","audio/ogg","audio/wav","audio/mpeg","audio/flac","audio/aac","audio/m4a","audio/mp4","audio/x-m4a"]),new Set([...i,...o]),new Set(["t.me","web.t.me","a.t.me","k.t.me","z.t.me"]),new Set(["AU","BD","CA","CO","EG","HN","IE","IN","JO","MX","MY","NI","NZ","PH","PK","SA","SV","US"]);var r=n(69118),c=n(26926);const u=524288,l=new Map;async function d(e,t){const n=t.url.includes("/download/")?(await self.clients.matchAll()).find((e=>"window"===e.type&&"top-level"===e.frameType)):await self.clients.get(e.clientId);if(!n)return;const s=(0,c.Z)(l),a={};let i=!1;const o=Promise.race([(0,r.wO)(6e4).then((()=>i?void 0:Promise.reject(new Error("ERROR_PART_TIMEOUT")))),new Promise(((e,t)=>{Object.assign(a,{resolve:e,reject:t})}))]);return l.set(s,a),o.catch((()=>{})).finally((()=>{l.delete(s),i=!0})),n.postMessage({type:"requestPart",messageId:s,params:t}),o}self.addEventListener("message",(e=>{const{type:t,messageId:n,result:s}=e.data;if("partResponse"===t){const e=l.get(n);e&&e.resolve(s)}}));const f=1048576;class p{constructor(){var e,t,n;e=this,n=void 0,(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var s=n.call(e,t);if("object"!=typeof s)return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t="queue"))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,this.queue=[]}push(e){this.queue.push(e)}async pop(){return await this.queue.shift()}get size(){return this.queue.length}}async function h(e){const t=await w((async()=>{const t=await self.caches.open(a),n=await t.match(e.request);return{cache:t,cached:n}}),3e3),{cache:n,cached:s}=t||{};if(n&&s){if(s.ok)return s;await n.delete(e.request)}const i=await fetch(e.request);return i.ok&&n&&n.put(e.request,i.clone()),i}async function w(e,t){let n=!1;try{return await Promise.race([(0,r.wO)(t).then((()=>n?void 0:Promise.reject(new Error("TIMEOUT")))),e()])}catch(e){return void console.error(e)}finally{n=!0}}var m=function(e){return e.True="1",e.False="0",e}(m||{});let g=(new Date).valueOf();const y=new Set,v={};function b(e){return e.custom.from_id?e.custom.from_id:e.custom.chat_id||e.custom.channel_id?`-${e.custom.chat_id||e.custom.channel_id}`:void 0}function R(e){if(e.custom.msg_id)return parseInt(e.custom.msg_id,10)}async function S(){const e=new URL(self.registration.scope).origin;return(await self.clients.matchAll({type:"window"})).filter((t=>new URL(t.url).origin===e))}async function I(e){const t=(await S())[0];t&&t.postMessage({type:"playNotificationSound",payload:{id:e}})}function T(e){let{chatId:t,messageId:n,body:s,title:a,icon:i,reaction:o,isSilent:r,shouldReplaceHistory:c}=e;const u=(new Date).valueOf()-g<1e3,l={body:s,data:{chatId:t,messageId:n,reaction:o,count:1,shouldReplaceHistory:c},icon:i||"icon-192x192.png",badge:"icon-192x192.png",tag:String(u?0:t||0),vibrate:[200,100,200]};return Promise.all([o||r?void 0:I(String(n)||t||""),self.registration.showNotification(a,l)])}async function q(e,t){if(t.chatId&&(e.postMessage({type:"focusMessage",payload:t}),!e.focused))try{await e.focus()}catch(e){}}self.addEventListener("sync",(()=>{g=Date.now()}));var P=n(46586);const M=new P.Z;M.resolve();const E=new Map;const C=/\.(wasm|html)$/,U=/[\da-f]{20}.*\.(js|css|woff2?|svg|png|jpg|jpeg|tgs|json|wasm)$/;self.addEventListener("install",(e=>{e.waitUntil(self.skipWaiting())})),self.addEventListener("activate",(e=>{e.waitUntil(Promise.race([(0,r.wO)(3e3),Promise.all([self.caches.delete(a),self.clients.claim()])]))})),self.addEventListener("fetch",(e=>{const{url:t}=e.request;if(t.includes("/progressive/"))return e.respondWith(async function(e){const{url:t}=e.request,n=e.request.headers.get("range"),a=/^bytes=(\d+)-(\d+)?$/g.exec(n||""),i=Number(a[1]);let o=Number(a[2]);if((!o||o-i+1>u)&&(o=i+u-1),0===i&&1===o){const t=e.request.url.match(/fileSize=(\d+)&mimeType=([\w/]+)/),n=t&&Number(t[1]),s=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 r=`${t}?start=${i}&end=${o}`,[c,l]=await async function(e){const t=await self.caches.open(s);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))])}(r);if(c)return new Response(c,{status:206,statusText:"Partial Content",headers:l});let f;try{f=await d(e,{url:t,start:i,end:o})}catch(e){}if(!f)return new Response("",{status:500,statusText:"Failed to fetch progressive part"});const{arrayBuffer:p,fullSize:h,mimeType:w}=f,m=Math.min(o-i+1,p.byteLength);o=i+m-1;const g=p.slice(0,m),y=[["Content-Range",`bytes ${i}-${o}/${h}`],["Accept-Ranges","bytes"],["Content-Length",String(m)],["Content-Type",w]];return m<=524288&&o<2097151&&async function(e,t,n){const a=await self.caches.open(s);Promise.all([a.put(new Request(`${e}&type=arrayBuffer`),new Response(t)),a.put(new Request(`${e}&type=headers`),new Response(JSON.stringify(n)))])}(r,g,y),new Response(g,{status:206,statusText:"Partial Content",headers:y})}(e)),!0;if(t.includes("/download/"))return e.respondWith(async function(e){const{url:t}=e.request;let n;try{n=await d(e,{url:t,start:0,end:65536})}catch(e){}if(!n)return new Response("",{status:500,statusText:"Failed to fetch file to download"});const s=e.request.url.match(/filename=(.*)/),a=s?`filename="${decodeURIComponent(s[1])}"`:"",{fullSize:i,mimeType:o}=n,r=[["Content-Length",String(i)],["Content-Type",o],["Content-Disposition",`attachment; ${a}`]],c=new p,u=n=>(c.push(d(e,{url:t,start:n,end:n+f-1}).then((e=>e?.arrayBuffer))),n+f);let l=0;const h=new ReadableStream({start(){for(let e=0;e<8&&!(l>=i);e++)l=u(l)},async pull(e){const t=await c.pop();t?(e.enqueue(new Uint8Array(t)),t.byteLength<f?e.close():l<i&&(l=u(l))):e.close()}});return new Response(h,{status:200,statusText:"OK",headers:r})}(e)),!0;if(t.includes("/share/")&&e.respondWith(async function(e){if("POST"===e.request.method)try{!async function(e,t){const n=await self.clients.get(t);n&&(await function(e){const t=E.get(e);if(t)return t.promise;const n=new P.Z;return E.set(e,n),n.promise}(t),n.postMessage({type:"share",payload:e}))}(function(e){const t=e.getAll("files");return{title:e.get("title"),text:e.get("text"),url:e.get("url"),files:t}}(await e.request.formData()),e.resultingClientId)}catch(e){console.warn("[SHARE] Failed to parse input data",e)}return Response.redirect(".")}(e)),t.startsWith("http")){if("/"===new URL(t).pathname||t.match(C))return e.respondWith(async function(e){const t=await w((()=>fetch(e.request)),3e3);if(!t?.ok)return h(e);const n=t.clone();return self.caches.open(a).then((t=>t?.put(e.request,n))),t}(e)),!0;if(t.match(U))return e.respondWith(h(e)),!0}return!1})),self.addEventListener("push",(function(e){const t=function(e){try{return e.data.json()}catch(e){return}}(e);if(!t||t.mute===m.True)return;const n=function(e){let t=e.title||"Telegram Web A";const n=e.custom?.silent===m.True;return n&&(t+=" 🔕"),{chatId:b(e),messageId:R(e),body:e.description,isSilent:n,title:t}}(t);y.has(n.messageId)?y.delete(n.messageId):e.waitUntil(T(n))})),self.addEventListener("notificationclick",(function(e){const t=self.registration.scope;e.notification.close();const{data:n}=e.notification;e.waitUntil((async()=>{const e=await S();if(await Promise.all(e.map((e=>(v[e.id]=n,q(e,n))))),self.clients.openWindow&&!(e.length>0)){v[0]=n;try{const e=await self.clients.openWindow(t);e&&(v[e.id]=n)}catch(e){}}})())})),self.addEventListener("message",(e=>{(function(e){if(!e.data)return;const t=e.source;if("clientReady"===e.data.type){const n=v[t.id]||v[0];n&&(delete v[t.id],delete v[0],e.waitUntil(q(t,n)))}if("showMessageNotification"===e.data.type){const t=e.data.payload;e.waitUntil((async()=>(t.chatId&&(await self.registration.getNotifications({tag:t.chatId})).forEach((e=>e.close())),y.add(t.messageId),T(t)))())}"closeMessageNotifications"===e.data.type&&e.waitUntil(async function(e){let{chatId:t,lastReadInboxMessageId:n}=e;const s=await self.registration.getNotifications(),a=n||Number.MAX_VALUE;s.forEach((e=>{("0"===e.tag||e.data.chatId===t&&e.data.messageId<=a)&&e.close()}))}(e.data.payload))})(e),function(e){const{source:t,data:n}=e;if(t&&"clientReady"===n.type){const{id:e}=t,n=E.get(e);n?n.resolve():E.set(e,M)}}(e)}))}}]);
//# sourceMappingURL=125.a148b005feb070ac70b9.js.map