2 lines
11 KiB
JavaScript
2 lines
11 KiB
JavaScript
(()=>{"use strict";const e="account",t=!1,n="tt-media-progressive",s="tt-assets",a=("undefined"!=typeof window&&window.innerHeight,Math.round(450),new Set(["newMessage","newScheduledMessage","deleteMessages","deleteScheduledMessages","deleteHistory","deleteParticipantHistory"]),new Set(["image/png","image/jpeg","image/gif"])),o=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([...a,...o]),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 r(e){const t=await c((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 o=await fetch(e.request);return o.ok&&n&&n.put(e.request,o.clone()),o}async function c(e,t){let n=!1;try{return await Promise.race([i(t).then((()=>n?void 0:Promise.reject(new Error("TIMEOUT")))),e()])}catch(e){return void console.error(e)}finally{n=!0}}const l="SharedWorker"in globalThis,u=(Intl,new URL("tg://host").host,globalThis,"undefined"!=typeof WorkerGlobalScope&&globalThis.self instanceof WorkerGlobalScope?globalThis.self.name:void 0);function d(t){const n=new URL(t).searchParams.get(e),s=n?Number(n):1;if(s&&!Number.isNaN(s)&&1!==s)return s}if((u?Number(new URLSearchParams(u).get(e)):void 0)||l&&d(globalThis.location.href),"object"==typeof window){const e=new BroadcastChannel("tt-version");e.postMessage({version:"10.9.50"}),e.addEventListener("message",(t=>{const{version:n}=t.data;n&&(-1===f("10.9.50",n)&&window.location.reload(),1===f("10.9.50",n)&&e.postMessage({version:"10.9.50"}))}))}function f(e,t){return e.startsWith(`${t}-`)?-1:t.startsWith(`${e}-`)?1:e.localeCompare(t,void 0,{numeric:!0,sensitivity:"case",caseFirst:"upper"})}const p=524288,h=6e4,m=new Map;async function g(e,t){const n=t.url.includes("/download/"),s=await(n?async function(e){const t=d(e);return(await self.clients.matchAll()).find((e=>"window"===e.type&&"top-level"===e.frameType&&d(e.url)===t))}(t.url):self.clients.get(e.clientId));if(!s)return;const a=Date.now().toString(36)+Math.random().toString(36).slice(2),o={};let r=!1;const c=Promise.race([i(h).then((()=>r?void 0:Promise.reject(new Error("ERROR_PART_TIMEOUT")))),new Promise(((e,t)=>{Object.assign(o,{resolve:e,reject:t})}))]);return m.set(a,o),c.catch((()=>{})).finally((()=>{m.delete(a),r=!0})),s.postMessage({type:"requestPart",messageId:a,params:t}),c}self.addEventListener("message",(e=>{const{type:t,messageId:n,result:s}=e.data;if("partResponse"===t){const e=m.get(n);e&&e.resolve(s)}}));const w=1048576;class y{constructor(){var e,t,n,s;e=this,n=void 0,(t="symbol"==typeof(s=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var s=n.call(e,"string");if("object"!=typeof s)return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(t="queue"))?s:s+"")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}}var v=function(e){return e.True="1",e.False="0",e}(v||{});let S=(new Date).valueOf();const b=new Set,R={};function E(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 P(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 T(e){const t=(await I())[0];t&&t.postMessage({type:"playNotificationSound",payload:{id:e}})}function L({chatId:e,messageId:t,body:n,title:s,icon:a,reaction:o,isSilent:i,shouldReplaceHistory:r}){const c=(new Date).valueOf()-S<1e3,l={body:n,data:{chatId:e,messageId:t,reaction:o,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([o||i?void 0:T(String(t)||e||""),self.registration.showNotification(s,l)])}async function U(e,n){if(n.chatId&&(e.postMessage({type:"focusMessage",payload:n}),!e.focused))try{await e.focus()}catch(e){t&&console.warn("[SW] ",e)}}function C(e,t,n){var s;return(t="symbol"==typeof(s=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var s=n.call(e,"string");if("object"!=typeof s)return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(t))?s:s+"")in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}self.addEventListener("sync",(()=>{S=Date.now()}));class M{constructor(){C(this,"promise",void 0),C(this,"reject",void 0),C(this,"resolve",void 0),this.promise=new Promise(((e,t)=>{this.reject=t,this.resolve=e}))}static resolved(e){const t=new M;return t.resolve(e),t}}const A=new Map;const N=/\.(wasm|html)$/,q=/[\da-f]{20}.*\.(js|css|woff2?|svg|png|jpg|jpeg|tgs|json|wasm)$/;self.addEventListener("install",(e=>{t&&console.log("ServiceWorker installed"),e.waitUntil(self.skipWaiting())})),self.addEventListener("activate",(e=>{t&&console.log("ServiceWorker activated"),e.waitUntil(Promise.race([i(3e3),Promise.all([self.caches.delete(s),self.clients.claim()])]))})),self.addEventListener("fetch",(e=>{const{url:a}=e.request,o=self.registration.scope;if(!a.startsWith(o))return!1;const{pathname:i,protocol:l}=new URL(a),{pathname:u}=new URL(o);if(i.includes("/progressive/"))return e.respondWith(async function(e){const{url:s}=e.request,a=d(s),o=e.request.headers.get("range"),i=/^bytes=(\d+)-(\d+)?$/g.exec(o||""),r=Number(i[1]),c=Number(i[2]);let l=c;(!l||l-r+1>p)&&(l=r+p-1);const u=new URL(s);if(0===r&&1===l){const e=u.searchParams.get("fileSize"),t=e&&Number(e),n=u.searchParams.get("mimeType");if(t&&n)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",n]]})}u.searchParams.set("start",String(r)),u.searchParams.set("end",String(l));const f=u.href,[h,m]=await async function(e,t){const s=e?`${n}_${e}`:n,a=await self.caches.open(s);return Promise.all([a.match(`${t}&type=arrayBuffer`).then((e=>e?e.arrayBuffer():void 0)),a.match(`${t}&type=headers`).then((e=>e?e.json():void 0))])}(a,f);if(t&&console.log(`FETCH PROGRESSIVE ${f} (request: ${r}-${c}) CACHED: ${Boolean(h)}`),h)return new Response(h,{status:206,statusText:"Partial Content",headers:m});let w;try{w=await g(e,{url:s,start:r,end:l})}catch(e){t&&console.error("FETCH PROGRESSIVE",e)}if(!w)return new Response("",{status:500,statusText:"Failed to fetch progressive part"});const{arrayBuffer:y,fullSize:v,mimeType:S}=w,b=Math.min(l-r+1,y.byteLength);l=r+b-1;const R=y.slice(0,b),E=[["Content-Range",`bytes ${r}-${l}/${v}`],["Accept-Ranges","bytes"],["Content-Length",String(b)],["Content-Type",S]];return b<=524288&&l<2097151&&async function(e,t,s,a){const o=e?`${n}_${e}`:n,i=await self.caches.open(o);Promise.all([i.put(new Request(`${t}&type=arrayBuffer`),new Response(s)),i.put(new Request(`${t}&type=headers`),new Response(JSON.stringify(a)))])}(a,f,R,E),new Response(R,{status:206,statusText:"Partial Content",headers:E})}(e)),!0;if(i.includes("/download/"))return e.respondWith(async function(e){const{url:n}=e.request;let s;try{s=await g(e,{url:n,start:0,end:65536})}catch(e){t&&console.error("FETCH DOWNLOAD",e)}if(!s)return new Response("",{status:500,statusText:"Failed to fetch file to download"});const a=e.request.url.match(/filename=(.*)/),o=a?`filename="${decodeURIComponent(a[1])}"`:"",{fullSize:i,mimeType:r}=s,c=[["Content-Length",String(i)],["Content-Type",r],["Content-Disposition",`attachment; ${o}`]],l=new y,u=t=>(l.push(g(e,{url:n,start:t,end:t+w-1}).then((e=>e?.arrayBuffer))),t+w);let d=0;const f=new ReadableStream({start(){for(let e=0;e<8&&!(d>=i);e++)d=u(d)},async pull(e){const t=await l.pop();t?(e.enqueue(new Uint8Array(t)),t.byteLength<w?e.close():d<i&&(d=u(d))):e.close()}});return new Response(f,{status:200,statusText:"OK",headers:c})}(e)),!0;if(i.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=A.get(e);if(t)return t.promise;const n=new M;return A.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)),"http:"===l||"https:"===l){if(i===u||i.match(N))return e.respondWith(async function(e){const t=await c((()=>fetch(e.request)),3e3);if(!t?.ok)return r(e);const n=t.clone();return self.caches.open(s).then((t=>t?.put(e.request,n))),t}(e)),!0;if(i.match(q))return e.respondWith(r(e)),!0}return!1})),self.addEventListener("push",(function(e){t&&(console.log("[SW] Push received event",e),e.data&&console.log("[SW] Push received with data",e.data.json()));const n=function(e){try{return e.data.json()}catch(n){return void(t&&console.log("[SW] Unable to parse push notification data",e.data))}}(e);if(!n||n.mute===v.True)return;const s=function(e){let t=e.title||"Telegram Web A";const n=e.custom?.silent===v.True;return n&&(t+=" 🔕"),{chatId:E(e),messageId:P(e),body:e.description,isSilent:n,title:t}}(n);b.has(s.messageId)?b.delete(s.messageId):e.waitUntil(L(s))})),self.addEventListener("notificationclick",(function(e){const n=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=>(R[e.id]=s,U(e,s))))),self.clients.openWindow&&!(e.length>0)){R[0]=s;try{const e=await self.clients.openWindow(n);e&&(R[e.id]=s)}catch(e){t&&console.warn("[SW] ",e)}}})())})),self.addEventListener("message",(e=>{(function(e){if(!e.data)return;const t=e.source;if("clientReady"===e.data.type){const n=R[t.id]||R[0];n&&(delete R[t.id],delete R[0],e.waitUntil(U(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())),b.add(t.messageId),L(t)))())}"closeMessageNotifications"===e.data.type&&e.waitUntil(async function({chatId:e,lastReadInboxMessageId:t}){const n=await self.registration.getNotifications(),s=t||Number.MAX_VALUE;n.forEach((t=>{("0"===t.tag||t.data.chatId===e&&t.data.messageId<=s)&&t.close()}))}(e.data.payload))})(e),function(e){const{source:t,data:n}=e;if(t&&"clientReady"===n.type){const{id:e}=t,n=A.get(e);n?n.resolve():A.set(e,M.resolved())}}(e)}))})();
|
|
//# sourceMappingURL=2715.6a1a12206dadd89382ad.js.map
|