TelegramPWA/dist/2715.6b222c9c8bd239aaa413.js
Alexander Zinchuk 10d4ae07ce [Build]
2025-08-15 18:26:19 +02:00

2 lines
9.6 KiB
JavaScript

(()=>{"use strict";const e="account",t="tt-media-progressive",s="tt-assets",n=("undefined"!=typeof window&&window.innerHeight,Math.round(450),new Set(["newMessage","newScheduledMessage","deleteMessages","deleteScheduledMessages","deleteHistory","deleteParticipantHistory"]),new Set(["svg","svgz"]),new Set(["image/png","image/jpeg","image/gif"])),a=new Set(["video/mp4","video/quicktime"]);new Set(["audio/mp3","audio/ogg","audio/wav","audio/mpeg","audio/flac","audio/aac","audio/m4a","audio/mp4","audio/x-m4a"]),new Set([...n,...a]),new Set(["USERNAME_PURCHASE_AVAILABLE","USERNAME_INVALID"]),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"]),new Set(["USER_CANCELED"]);const i=e=>new Promise((t=>{setTimeout((()=>t()),e)}));async function o(e){const t=await r((async()=>{const t=await self.caches.open(s),n=await t.match(e.request);return{cache:t,cached:n}}),3e3),{cache:n,cached:a}=t||{};if(n&&a){if(a.ok)return a;await n.delete(e.request)}const i=await fetch(e.request);return i.ok&&n&&n.put(e.request,i.clone()),i}async function r(e,t){let s=!1;try{return await Promise.race([i(t).then((()=>s?void 0:Promise.reject(new Error("TIMEOUT")))),e()])}catch(e){return void console.error(e)}finally{s=!0}}const c="SharedWorker"in globalThis,l=(Intl,new URL("tg://host").host,globalThis,"undefined"!=typeof WorkerGlobalScope&&globalThis.self instanceof WorkerGlobalScope?globalThis.self.name:void 0);function u(t){const s=new URL(t).searchParams.get(e),n=s?Number(s):1;if(n&&!Number.isNaN(n)&&1!==n)return n}if((l?Number(new URLSearchParams(l).get(e)):void 0)||c&&u(globalThis.location.href),"object"==typeof window){const e=new BroadcastChannel("tt-version");e.postMessage({version:"10.9.64"}),e.addEventListener("message",(t=>{const{version:s}=t.data;s&&(-1===d("10.9.64",s)&&window.location.reload(),1===d("10.9.64",s)&&e.postMessage({version:"10.9.64"}))}))}function d(e,t){return e.startsWith(`${t}-`)?-1:t.startsWith(`${e}-`)?1:e.localeCompare(t,void 0,{numeric:!0,sensitivity:"case",caseFirst:"upper"})}const f=524288,h=new Map;async function p(e,t){const s=t.url.includes("/download/"),n=await(s?async function(e){const t=u(e);return(await self.clients.matchAll()).find((e=>"window"===e.type&&"top-level"===e.frameType&&u(e.url)===t))}(t.url):self.clients.get(e.clientId));if(!n)return;const a=Date.now().toString(36)+Math.random().toString(36).slice(2),o={};let r=!1;const c=Promise.race([i(6e4).then((()=>r?void 0:Promise.reject(new Error("ERROR_PART_TIMEOUT")))),new Promise(((e,t)=>{Object.assign(o,{resolve:e,reject:t})}))]);return h.set(a,o),c.catch((()=>{})).finally((()=>{h.delete(a),r=!0})),n.postMessage({type:"requestPart",messageId:a,params:t}),c}self.addEventListener("message",(e=>{const{type:t,messageId:s,result:n}=e.data;if("partResponse"===t){const e=h.get(s);e&&e.resolve(n)}}));const g=1048576;class m{constructor(){this.queue=[]}push(e){this.queue.push(e)}async pop(){return await this.queue.shift()}get size(){return this.queue.length}}var w=function(e){return e.True="1",e.False="0",e}(w||{});let y=(new Date).valueOf();const v=new Set,S={};function R(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 b(e){if(e.custom.msg_id)return parseInt(e.custom.msg_id,10)}async function I(){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 E(e){const t=(await I())[0];t&&t.postMessage({type:"playNotificationSound",payload:{id:e}})}function P({chatId:e,messageId:t,body:s,title:n,icon:a,reaction:i,isSilent:o,shouldReplaceHistory:r}){const c=(new Date).valueOf()-y<1e3,l={body:s,data:{chatId:e,messageId:t,reaction:i,count:1,shouldReplaceHistory:r},icon:a||"icon-192x192.png",badge:"icon-192x192.png",tag:String(c?0:e||0),vibrate:[200,100,200]};return Promise.all([i||o?void 0:E(String(t)||e||""),self.registration.showNotification(n,l)])}async function T(e,t){if(t.chatId&&(e.postMessage({type:"focusMessage",payload:t}),!e.focused))try{await e.focus()}catch(e){}}self.addEventListener("sync",(()=>{y=Date.now()}));class L{constructor(){this.promise=new Promise(((e,t)=>{this.reject=t,this.resolve=e}))}static resolved(e){const t=new L;return t.resolve(e),t}}const U=new Map;const M=/\.(wasm|html)$/,N=/[\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([i(3e3),Promise.all([self.caches.delete(s),self.clients.claim()])]))})),self.addEventListener("fetch",(e=>{const{url:n}=e.request,a=self.registration.scope;if(!n.startsWith(a))return!1;const{pathname:i,protocol:c}=new URL(n),{pathname:l}=new URL(a);if(i.includes("/progressive/"))return e.respondWith(async function(e){const{url:s}=e.request,n=u(s),a=e.request.headers.get("range"),i=/^bytes=(\d+)-(\d+)?$/g.exec(a||""),o=Number(i[1]);let r=Number(i[2]);(!r||r-o+1>f)&&(r=o+f-1);const c=new URL(s);if(0===o&&1===r){const e=c.searchParams.get("fileSize"),t=e&&Number(e),s=c.searchParams.get("mimeType");if(t&&s)return new Response(new Uint8Array(2).buffer,{status:206,statusText:"Partial Content",headers:[["Content-Range",`bytes 0-1/${t}`],["Accept-Ranges","bytes"],["Content-Length","2"],["Content-Type",s]]})}c.searchParams.set("start",String(o)),c.searchParams.set("end",String(r));const l=c.href,[d,h]=await async function(e,s){const n=e?`${t}_${e}`:t,a=await self.caches.open(n);return Promise.all([a.match(`${s}&type=arrayBuffer`).then((e=>e?e.arrayBuffer():void 0)),a.match(`${s}&type=headers`).then((e=>e?e.json():void 0))])}(n,l);if(d)return new Response(d,{status:206,statusText:"Partial Content",headers:h});let g;try{g=await p(e,{url:s,start:o,end:r})}catch(e){}if(!g)return new Response("",{status:500,statusText:"Failed to fetch progressive part"});const{arrayBuffer:m,fullSize:w,mimeType:y}=g,v=Math.min(r-o+1,m.byteLength);r=o+v-1;const S=m.slice(0,v),R=[["Content-Range",`bytes ${o}-${r}/${w}`],["Accept-Ranges","bytes"],["Content-Length",String(v)],["Content-Type",y]];return v<=524288&&r<2097151&&async function(e,s,n,a){const i=e?`${t}_${e}`:t,o=await self.caches.open(i);Promise.all([o.put(new Request(`${s}&type=arrayBuffer`),new Response(n)),o.put(new Request(`${s}&type=headers`),new Response(JSON.stringify(a)))])}(n,l,S,R),new Response(S,{status:206,statusText:"Partial Content",headers:R})}(e)),!0;if(i.includes("/download/"))return e.respondWith(async function(e){const{url:t}=e.request;let s;try{s=await p(e,{url:t,start:0,end:65536})}catch(e){}if(!s)return new Response("",{status:500,statusText:"Failed to fetch file to download"});const n=e.request.url.match(/filename=(.*)/),a=n?`filename="${decodeURIComponent(n[1])}"`:"",{fullSize:i,mimeType:o}=s,r=[["Content-Length",String(i)],["Content-Type",o],["Content-Disposition",`attachment; ${a}`]],c=new m,l=s=>(c.push(p(e,{url:t,start:s,end:s+g-1}).then((e=>e?.arrayBuffer))),s+g);let u=0;const d=new ReadableStream({start(){for(let e=0;e<8&&!(u>=i);e++)u=l(u)},async pull(e){const t=await c.pop();t?(e.enqueue(new Uint8Array(t)),t.byteLength<g?e.close():u<i&&(u=l(u))):e.close()}});return new Response(d,{status:200,statusText:"OK",headers:r})}(e)),!0;if(i.includes("/share/")&&e.respondWith(async function(e){if("POST"===e.request.method)try{!async function(e,t){const s=await self.clients.get(t);s&&(await function(e){const t=U.get(e);if(t)return t.promise;const s=new L;return U.set(e,s),s.promise}(t),s.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)),"http:"===c||"https:"===c){if(i===l||i.match(M))return e.respondWith(async function(e){const t=await r((()=>fetch(e.request)),3e3);if(!t?.ok)return o(e);const n=t.clone();return self.caches.open(s).then((t=>t?.put(e.request,n))),t}(e)),!0;if(i.match(N))return e.respondWith(o(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===w.True)return;const s=function(e){let t=e.title||"Telegram Web A";const s=e.custom?.silent===w.True;return s&&(t+=" 🔕"),{chatId:R(e),messageId:b(e),body:e.description,isSilent:s,title:t}}(t);v.has(s.messageId)?v.delete(s.messageId):e.waitUntil(P(s))})),self.addEventListener("notificationclick",(function(e){const t=self.registration.scope;e.notification.close();const{data:s}=e.notification;e.waitUntil((async()=>{const e=await I();if(await Promise.all(e.map((e=>(S[e.id]=s,T(e,s))))),self.clients.openWindow&&!(e.length>0)){S[0]=s;try{const e=await self.clients.openWindow(t);e&&(S[e.id]=s)}catch(e){}}})())})),self.addEventListener("message",(e=>{(function(e){if(!e.data)return;const t=e.source;if("clientReady"===e.data.type){const s=S[t.id]||S[0];s&&(delete S[t.id],delete S[0],e.waitUntil(T(t,s)))}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())),v.add(t.messageId),P(t)))())}"closeMessageNotifications"===e.data.type&&e.waitUntil(async function({chatId:e,lastReadInboxMessageId:t}){const s=await self.registration.getNotifications(),n=t||Number.MAX_VALUE;s.forEach((t=>{("0"===t.tag||t.data.chatId===e&&t.data.messageId<=n)&&t.close()}))}(e.data.payload))})(e),function(e){const{source:t,data:s}=e;if(t&&"clientReady"===s.type){const{id:e}=t,s=U.get(e);s?s.resolve():U.set(e,L.resolved())}}(e)}))})();
//# sourceMappingURL=2715.6b222c9c8bd239aaa413.js.map