tweb/public/sw.04ffa51e8d749197145b.chu...

2 lines
24 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(()=>{"use strict";var e,t,n={410:(e,t,n)=>{n.d(t,{GO:()=>r,ZP:()=>s});const o=n(1267).Z.debug,r="undefined"!=typeof window?window:self,s=o},4762:(e,t,n)=>{n.d(t,{IS_FIREFOX:()=>i,IS_MOBILE:()=>a,IS_SAFARI:()=>s});var o=n(6761);const r=navigator?navigator.userAgent:null,s=(navigator.userAgent.search(/OS X|iPhone|iPad|iOS/i),navigator.userAgent.toLowerCase().indexOf("android"),/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor),(/iPad|iPhone|iPod/.test(navigator.platform)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1)&&o.Z.MSStream,!!("safari"in o.Z)||!(!r||!(/\b(iPad|iPhone|iPod)\b/.test(r)||r.match("Safari")&&!r.match("Chrome")))),i=navigator.userAgent.toLowerCase().indexOf("firefox")>-1,a=(void 0===navigator.maxTouchPoints||navigator.maxTouchPoints>0)&&-1!=navigator.userAgent.search(/iOS|iPhone OS|Android|BlackBerry|BB10|Series ?[64]0|J2ME|MIDP|opera mini|opera mobi|mobi.+Gecko|Windows Phone/i)},1352:(e,t,n)=>{n.d(t,{FK:()=>i,N5:()=>r,SU:()=>o,kC:()=>s});const o="undefined"!=typeof ServiceWorkerGlobalScope&&self instanceof ServiceWorkerGlobalScope,r="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope&&!o,s=r||o,i=()=>self.clients.matchAll({includeUncontrolled:!1,type:"window"}),a=(e,...t)=>{try{e.postMessage(...t)}catch(e){console.error("[worker] postMessage error:",e,t)}},c=(e,...t)=>{i().then((n=>{n.length&&n.slice(e?0:-1).forEach((e=>{a(e,...t)}))}))};o&&c.bind(null,!1),o&&c.bind(null,!0)},5003:(e,t,n)=>{n.d(t,{kg:()=>f,v9:()=>o});var o,r=n(410),s=n(4762),i=n(1352),a=n(5289);!function(e){e[e.None=0]="None",e[e.Error=1]="Error",e[e.Warn=2]="Warn",e[e.Log=4]="Log",e[e.Debug=8]="Debug"}(o||(o={}));const c=[o.None,o.Error,o.Warn,o.Log,o.Debug],l=!(s.IS_SAFARI||s.IS_FIREFOX),u="",h="",d=[["debug",o.Debug],["info",o.Log],["warn",o.Warn],["error",o.Error],["assert",o.Error],["trace",o.Log],["group",o.Log],["groupCollapsed",o.Log],["groupEnd",o.Log]];function f(e,t=o.Log|o.Warn|o.Error,n=!1,s=""){let g;r.ZP||n||(t=o.Error),l?s||(i.SU?s=u:i.N5&&(s=h)):s="";const p=s;s=s?`%s ${s}%s`:"%s";const m=function(...n){return t&o.Log&&console.log(s,(0,a.Z)(),e,...n)};return d.forEach((([n,o])=>{m[n]=function(...r){return t&o&&console[n](s,(0,a.Z)(),e,...r)}})),m.setPrefix=function(t){g=t,e="["+t+"]"},m.setPrefix(e),m.setLevel=function(e){t=c.slice(0,e+1).reduce(((e,t)=>e|t),0)},m.bindPrefix=function(e){return f(`${g}] [${e}`,t,n,p)},m}},8592:(e,t,n)=>{n.d(t,{Vp:()=>H,cM:()=>X,j6:()=>ee});var o=n(5003);function r(e){return new Promise((t=>{setTimeout(t,e)}))}const s=self,i="cachedAssets";function a(e){return e.ok&&200===e.status}function c(e){return Promise.race([e,r(1e4).then((()=>Promise.reject()))])}function l(){}function u(){const e={isFulfilled:!1,isRejected:!1,notify:()=>{},notifyAll:(...t)=>{e.lastNotify=t,e.listeners.forEach((e=>e(...t)))},listeners:[],addNotifyListener:t=>{e.lastNotify&&t(...e.lastNotify),e.listeners.push(t)}},t=new Promise(((n,o)=>{e.resolve=e=>{t.isFulfilled||t.isRejected||(t.isFulfilled=!0,n(e))},e.reject=(...e)=>{t.isRejected||t.isFulfilled||(t.isRejected=!0,o(...e))}}));return t.catch(l).finally((()=>{t.notify=t.notifyAll=t.lastNotify=null,t.listeners.length=0,t.cancel&&(t.cancel=l)})),Object.assign(t,e),t}var h=n(6761),d=n(1267);function f(e,t=""){Array.isArray(e)||(e=[e]);const n=function(e){return-1===["image/jpeg","image/png","image/gif","image/svg+xml","image/webp","image/bmp","video/mp4","video/webm","video/quicktime","audio/ogg","audio/mpeg","audio/mp4","audio/wav","application/json","application/pdf"].indexOf(e)?"application/octet-stream":e}(t);return new Blob(e,{type:n})}class g{constructor(e,t,n){this.mimeType=e,this.size=t,this.saveFileCallback=n,this.bytes=new Uint8Array(t)}write(e,t){return n=this,o=void 0,s=function*(){const n=t+e.byteLength;if(n>this.bytes.byteLength){const e=new Uint8Array(n);e.set(this.bytes,0),this.bytes=e}this.bytes.set(e,t)},new((r=void 0)||(r=Promise))((function(e,t){function i(e){try{c(s.next(e))}catch(e){t(e)}}function a(e){try{c(s.throw(e))}catch(e){t(e)}}function c(t){var n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r((function(e){e(n)}))).then(i,a)}c((s=s.apply(n,o||[])).next())}));var n,o,r,s}truncate(){this.bytes=new Uint8Array}trim(e){this.bytes=this.bytes.slice(0,e)}finalize(e=!0){const t=f(this.bytes,this.mimeType);return e&&this.saveFileCallback&&this.saveFileCallback(t),t}getParts(){return this.bytes}replaceParts(e){this.bytes=e}}var p=n(5471);class m{constructor(e){this.dbName=e,this.useStorage=!0,d.Z.test&&(this.dbName+="_test"),m.STORAGES.length&&(this.useStorage=m.STORAGES[0].useStorage),this.openDatabase(),m.STORAGES.push(this)}openDatabase(){var e;return null!==(e=this.openDbPromise)&&void 0!==e?e:this.openDbPromise=caches.open(this.dbName)}delete(e){return this.timeoutOperation((t=>t.delete("/"+e)))}deleteAll(){return caches.delete(this.dbName)}get(e){return this.timeoutOperation((t=>t.match("/"+e)))}save(e,t){return this.timeoutOperation((n=>n.put("/"+e,t)))}getFile(e,t="blob"){return this.get(e).then((e=>{if(!e)throw(0,p.Z)("NO_ENTRY_FOUND");return e[t]()}))}saveFile(e,t){t instanceof Blob||(t=f(t));const n=new Response(t,{headers:{"Content-Length":""+t.size}});return this.save(e,n).then((()=>t))}timeoutOperation(e){return this.useStorage?new Promise(((t,n)=>{return o=this,r=void 0,i=function*(){let o=!1;const r=setTimeout((()=>{n(),o=!0}),15e3);try{const n=yield this.openDatabase();if(!n)throw this.useStorage=!1,this.openDbPromise=void 0,"no cache?";const r=yield e(n);if(o)return;t(r)}catch(e){n(e)}clearTimeout(r)},new((s=void 0)||(s=Promise))((function(e,t){function n(e){try{c(i.next(e))}catch(e){t(e)}}function a(e){try{c(i.throw(e))}catch(e){t(e)}}function c(t){var o;t.done?e(t.value):(o=t.value,o instanceof s?o:new s((function(e){e(o)}))).then(n,a)}c((i=i.apply(o,r||[])).next())}));var o,r,s,i})):Promise.reject((0,p.Z)("STORAGE_OFFLINE"))}prepareWriting(e,t,n){return{deferred:u(),getWriter:()=>new g(n,t,(t=>this.saveFile(e,t).catch((()=>t))))}}static toggleStorage(e,t){return Promise.all(this.STORAGES.map((n=>{if(n.useStorage=e,t)return e?void 0:n.deleteAll()})))}}m.STORAGES=[];const v=new Map,w=new m("cachedStreamChunks"),b="Time-Cached";setInterval((()=>w.timeoutOperation((e=>e.keys().then((t=>{const n=new Map,o=Date.now()/1e3|0;for(const e of t){const t=e.url.match(/\/(\d+?)\?/);t&&!n.has(t[1])&&n.set(t[1],e)}const r=[];for(const[t,s]of n){const n=e.match(s).then((n=>{if(+n.headers.get(b)+86400<=o)return X("will delete stream chunk:",t),e.delete(s,{ignoreSearch:!0,ignoreVary:!0})}));r.push(n)}return Promise.all(r)}))))),18e5),setInterval((()=>{const e=H();for(const[t,n]of v)if(t!==e){for(const e in n)n[e].reject();v.delete(t)}}),12e4);const y=new Map;class S{constructor(e){this.info=e,this.loadedOffsets=new Set,this.destroy=()=>{y.delete(this.id)},this.id=S.getId(e),y.set(this.id,this),this.limitPart=e.size>78643200?O:P,this.destroyDebounced=function(e,t,n=!0,o=!0){let r,s,i,a,c=!1;const u=t=>{const n=i,o=a;try{n(e.apply(null,t))}catch(e){console.error("debounce error",e),o(e)}},d=(...e)=>{s||(s=new Promise(((e,t)=>(i=e,a=t)))),r?(clearTimeout(r),c=!0,a(),s=new Promise(((e,t)=>(i=e,a=t)))):n&&(u(e),c=!1);const d=h.Z.setTimeout((()=>{!o||n&&!c||u(e),r===d&&(r=s=i=a=void 0,c=!1)}),t);return r=d,s.catch(l),s};return d.clearTimeout=()=>{r&&(h.Z.clearTimeout(r),a(),r=s=i=a=void 0,c=!1)},d.isDebounced=()=>!!r,d}(this.destroy,15e4,!1,!0)}requestFilePartFromWorker(e,t,n=!1){return o=this,r=void 0,i=function*(){const o={docId:this.id,dcId:this.info.dcId,offset:e,limit:t},r=JSON.stringify(o),s=H();let i=v.get(s);i||v.set(s,i={});let a=i[r];if(a)return a.then((e=>e.bytes));this.loadedOffsets.add(e),a=i[r]=u(),ee.invoke("requestFilePart",o,void 0,s).then(a.resolve,a.reject).finally((()=>{i[r]===a&&(delete i[r],Object.keys(i).length||v.delete(s))}));const c=a.then((e=>e.bytes));return this.saveChunkToCache(c,e,t),!n&&this.preloadChunks(e,e+15*this.limitPart),c},new((s=void 0)||(s=Promise))((function(e,t){function n(e){try{c(i.next(e))}catch(e){t(e)}}function a(e){try{c(i.throw(e))}catch(e){t(e)}}function c(t){var o;t.done?e(t.value):(o=t.value,o instanceof s?o:new s((function(e){e(o)}))).then(n,a)}c((i=i.apply(o,r||[])).next())}));var o,r,s,i}requestFilePartFromCache(e,t,n){const o=this.getChunkKey(e,t);return w.getFile(o).then((e=>n?new Uint8Array:function(e){return function(e){return function(e,t){return new Promise((t=>{const n=new FileReader;n.addEventListener("loadend",(e=>{t(e.target.result)})),n.readAsArrayBuffer(e)}))}(e)}(e).then((e=>new Uint8Array(e)))}(e)),(e=>{e.type}))}requestFilePart(e,t,n){return this.requestFilePartFromCache(e,t,n).then((o=>o||this.requestFilePartFromWorker(e,t,n)))}saveChunkToCache(e,t,n){return e.then((e=>{const o=this.getChunkKey(t,n),r=new Response(e,{headers:{"Content-Length":""+e.length,"Content-Type":"application/octet-stream",[b]:""+(Date.now()/1e3|0)}});return w.save(o,r)}))}preloadChunk(e){this.loadedOffsets.has(e)||(this.loadedOffsets.add(e),this.requestFilePart(e,this.limitPart,!0))}preloadChunks(e,t){if(t>this.info.size&&(t=this.info.size),e)for(;e<t;e+=this.limitPart)this.preloadChunk(e);else this.preloadChunk(k(e,this.limitPart))}requestRange(e){this.destroyDebounced();const t=function(e,t,n){return 0===e[0]&&1===e[1]?new Response(new Uint8Array(2).buffer,{status:206,statusText:"Partial Content",headers:{"Accept-Ranges":"bytes","Content-Range":`bytes 0-1/${n||"*"}`,"Content-Length":"2","Content-Type":t||"video/mp4"}}):null}(e,this.info.mimeType,this.info.size);if(t)return t;let[n,o]=e;const r=o&&o<this.limitPart?function(e){return Math.pow(2,Math.ceil(Math.log(e)/Math.log(2)))}(o-n+1):this.limitPart,s=k(n,r);return o||(o=Math.min(n+r,this.info.size-1)),this.requestFilePart(s,r).then((e=>{n===s&&o===s+r||(e=e.slice(n-s,o-s+1));const t={"Accept-Ranges":"bytes","Content-Range":`bytes ${n}-${n+e.byteLength-1}/${this.info.size||"*"}`,"Content-Length":`${e.byteLength}`};return this.info.mimeType&&(t["Content-Type"]=this.info.mimeType),new Response(e,{status:206,statusText:"Partial Content",headers:t})}))}getChunkKey(e,t){return this.id+"?offset="+e+"&limit="+t}static get(e){var t;return null!==(t=y.get(this.getId(e)))&&void 0!==t?t:new S(e)}static getId(e){return e.location.id}}const P=524288,O=1048576;function k(e,t=2048){return e-e%t}var A=n(4762);function C(e,t){const n=Object.keys,o=typeof e;return e&&t&&"object"===o&&o===typeof t?n(e).length===n(t).length&&n(e).every((n=>C(e[n],t[n]))):e===t}class E{constructor(e){!function(e,t){if(t)for(const n in t)void 0!==t[n]&&(e[n]=t[n])}(this,e),d.Z.test&&(this.name+="_test"),this.storageIsAvailable=!0,this.log=(0,o.kg)(["IDB",e.name].join("-")),this.log("constructor"),this.openDatabase(!0),E.INSTANCES.push(this)}isAvailable(){return this.storageIsAvailable}openDatabase(e=!1){if(this.openDbPromise&&!e)return this.openDbPromise;const t=(e,t)=>{var n;const o=Array.from(e.indexNames);for(const t of o)e.deleteIndex(t);if(null===(n=t.indexes)||void 0===n?void 0:n.length)for(const n of t.indexes)e.indexNames.contains(n.indexName)||e.createIndex(n.indexName,n.keyPath,n.objectParameters)};try{var n=indexedDB.open(this.name,this.version);if(!n)return Promise.reject()}catch(e){return this.log.error("error opening db",e.message),this.storageIsAvailable=!1,Promise.reject(e)}let o=!1;return setTimeout((()=>{o||n.onerror((0,p.Z)("IDB_CREATE_TIMEOUT"))}),3e3),this.openDbPromise=new Promise(((e,r)=>{n.onsuccess=t=>{o=!0;const s=n.result;let i=!1;this.log("Opened"),s.onerror=e=>{this.storageIsAvailable=!1,this.log.error("Error creating/accessing IndexedDB database",e),r(e)},s.onclose=e=>{this.log.error("closed:",e),!i&&this.openDatabase()},s.onabort=e=>{this.log.error("abort:",e);const t=e.target;this.openDatabase(i=!0),t.onerror&&t.onerror(e),s.close()},s.onversionchange=e=>{this.log.error("onversionchange, lol?")},e(this.db=s)},n.onerror=e=>{o=!0,this.storageIsAvailable=!1,this.log.error("Error creating/accessing IndexedDB database",e),r(e)},n.onupgradeneeded=e=>{o=!0,this.log.warn("performing idb upgrade from",e.oldVersion,"to",e.newVersion);const n=e.target,r=n.result;this.stores.forEach((e=>{if(r.objectStoreNames.contains(e.name)){const o=n.transaction.objectStore(e.name);t(o,e)}else((e,n)=>{const o=e.createObjectStore(n.name);t(o,n)})(r,e)}))}}))}static create(e){var t;return null!==(t=this.INSTANCES.find((t=>t.name===e.name)))&&void 0!==t?t:new E(e)}static closeDatabases(e){this.INSTANCES.forEach((t=>{if(e&&e===t)return;const n=t.db;n&&(n.onclose=()=>{},n.close())}))}}E.INSTANCES=[];class T{constructor(e,t){this.storeName=t,this.log=(0,o.kg)(["IDB",e.name,t].join("-")),this.idb=E.create(e)}delete(e,t){return Array.isArray(e)||(e=[].concat(e)),this.getObjectStore("readwrite",(t=>e.map((e=>t.delete(e)))),"",t)}clear(e){return this.getObjectStore("readwrite",(e=>e.clear()),"",e)}save(e,t,n){return Array.isArray(e)||(e=[].concat(e),t=[].concat(t)),this.getObjectStore("readwrite",(n=>e.map(((e,o)=>n.put(t[o],e)))),"",n)}get(e,t){return Array.isArray(e)||(e=[].concat(e)),e.length?this.getObjectStore("readonly",(t=>e.map((e=>t.get(e)))),"",t):Promise.resolve([])}getObjectStore(e,t,n,o=this.storeName){let r;return n&&(r=performance.now(),this.log(n+": start")),this.idb.openDatabase().then((s=>new Promise(((i,a)=>{const c=s.transaction([o],e),l=()=>{clearTimeout(d),a(c.error)},u=()=>{clearTimeout(d),n&&this.log(n+": end",performance.now()-r);const e=p.map((e=>e.result));i(g?e:e[0])};c.onerror=l;const h="readwrite"===e;h&&(c.oncomplete=()=>u());const d=setTimeout((()=>{this.log.error("transaction not finished",c,n)}),1e4),f=t(c.objectStore(o)),g=Array.isArray(f),p=g?f:[].concat(f);if(h)return;const m=p.length;let v=m;const w=()=>{c.error||--v||u()};for(let e=0;e<m;++e){const t=p[e];t.onerror=l,t.onsuccess=w}}))))}getAll(e){return this.getObjectStore("readonly",(e=>e.getAll()),"",e)}}const j=self,x=location.protocol+"//"+location.hostname+location.pathname.split("/").slice(0,-1).join("/")+"/";let I=0,_=!A.IS_MOBILE;const D={push_mute_until:0,push_lang:{push_message_nopreview:"You have a new message",push_action_mute1d:"Mute for 24H",push_action_settings:"Settings"},push_settings:{}},F=new class{constructor(e,t,n){this.defaults=n,this.cache={},this.storage=new T(e,t)}getDefault(e){const t=this.defaults[e];return"function"==typeof t?t():t}get(e){return this.cache.hasOwnProperty(e)?this.cache[e]:this.storage.get(e).then((e=>e),(()=>{})).then((t=>this.cache.hasOwnProperty(e)?this.cache[e]:(null!=t||(t=this.getDefault(e)),this.cache[e]=t)))}getCached(e){const t=this.get(e);if(t instanceof Promise)throw"no property";return t}set(e,t){var n,o,r,s,i;return o=this,r=void 0,i=function*(){if(!C(null!==(n=this.cache[e])&&void 0!==n?n:this.defaults[e],t)){this.cache[e]=t;try{this.storage.save(e,t)}catch(e){}}},new((s=void 0)||(s=Promise))((function(e,t){function n(e){try{c(i.next(e))}catch(e){t(e)}}function a(e){try{c(i.throw(e))}catch(e){t(e)}}function c(t){var o;t.done?e(t.value):(o=t.value,o instanceof s?o:new s((function(e){e(o)}))).then(n,a)}c((i=i.apply(o,r||[])).next())}))}}({name:"tweb",version:7,stores:[{name:"session"},{name:"stickerSets"},{name:"users"},{name:"chats"},{name:"dialogs"},{name:"messages"}]},"session",D);for(const e in D)F.get(e);j.addEventListener("push",(e=>{const t=e.data.json();X("push",Object.assign({},t));try{if(!t.badge)throw"no badge";const[n,o,r]=[F.getCached("push_mute_until"),F.getCached("push_settings"),F.getCached("push_lang")],s=Date.now();if(L()&&n&&s<n)throw`Supress notification because mute for ${Math.ceil((n-s)/6e4)} min`;if(Date.now()-I<=11500&&_)throw"Supress notification because some instance is alive";const i=function(e,t,n){const o="assets/img/logo_filled_rounded.png";let r,s=e.title||"Telegram",i=e.description||"";e.custom&&(r=e.custom.channel_id?""+-e.custom.channel_id:e.custom.chat_id?""+-e.custom.chat_id:e.custom.from_id||""),e.custom.peerId=""+r;let a="peer"+r;(null==t?void 0:t.nopreview)&&(s="Telegram",i=n.push_message_nopreview,a="unknown_peer"),X("show notify",s,i,o,e);const c=[{action:"mute1d",title:n.push_action_mute1d}];return j.registration.showNotification(s,{body:i,icon:o,tag:a,data:e,actions:c,badge:"assets/img/masked.svg",silent:"1"===e.custom.silent}).catch((e=>{X.error("Show notification promise",e)}))}(t,o,r);e.waitUntil(i)}catch(e){X(e)}})),j.addEventListener("notificationclick",(e=>{const t=e.notification;X("On notification click: ",t.tag),t.close();const n=e.action;if("mute1d"===n&&L())return X("[SW] mute for 1d"),void F.set("push_mute_until",Date.now()+864e5);const o=t.data;if(!o)return;const r=j.clients.matchAll({type:"window"}).then((e=>{o.action=n,R=o;for(let t=0;t<e.length;t++){const n=e[t];if("focus"in n)return n.focus(),ee.invokeVoid("pushClick",R,n),void(R=void 0)}if(j.clients.openWindow)return Promise.resolve(F.get("push_settings")).then((e=>j.clients.openWindow(e.baseUrl||x)))})).catch((e=>{X.error("Clients.matchAll error",e)}));e.waitUntil(r)})),j.addEventListener("notificationclose",(function(e){var t;t=e.notification,N.delete(t)}));const N=new Set;let R;function L(){return A.IS_FIREFOX}var W=n(153),M=n(410);class q extends W.Z{constructor(){super("SERVICE"),M.GO&&(M.GO.serviceMessagePort=this)}}var Z=n(1352);const U=new Map,G=(0,p.Z)("UNKNOWN");self.downloadMap=U;const B={download:e=>{const{id:t}=e;if(U.has(t))return Promise.reject(G);const n=new CountQueuingStrategy({highWaterMark:1}),o=u();let r;o.then((()=>{setTimeout((()=>{U.delete(t)}),5e3)}),(()=>{U.delete(t)}));const s=new ReadableStream({start:e=>{r=e},cancel:e=>{o.reject(G)}},n),i=Object.assign(Object.assign({},e),{readableStream:s,promise:o,controller:r});return U.set(t,i),o.catch((()=>{throw G}))},downloadChunk:({id:e,chunk:t})=>{const n=U.get(e);return n?n.controller.enqueue(t):Promise.reject()},downloadFinalize:e=>{const t=U.get(e);return t?(t.promise.resolve(),t.controller.close()):Promise.reject()},downloadCancel:e=>{const t=U.get(e);if(t)return t.promise.reject(),t.controller.error()}};function z(e,t){const n=r(100).then((()=>{const e=U.get(t);if(!e||e.used)return;e.used=!0;const n=e.readableStream;return new Response(n,{headers:e.headers})}));e.respondWith(n)}function $(){if(U.size)for(const[e,t]of U)t.controller.error()}const V={};function K(e,t){const n=e.request.formData().then((t=>(function(e,t){var n,o,r,s,i;o=this,r=void 0,i=function*(){try{X("share data",e);const o=function(e){return{files:e.getAll("files"),title:e.get("title"),text:e.get("text"),url:e.get("url")}}(e);(null!==(n=V[t])&&void 0!==n?n:V[t]=[]).push(o)}catch(e){X.warn("something wrong with the data",e)}},new((s=void 0)||(s=Promise))((function(e,t){function n(e){try{c(i.next(e))}catch(e){t(e)}}function a(e){try{c(i.throw(e))}catch(e){t(e)}}function c(t){var o;t.done?e(t.value):(o=t.value,o instanceof s?o:new s((function(e){e(o)}))).then(n,a)}c((i=i.apply(o,r||[])).next())}))}(t,e.resultingClientId),Response.redirect(".."))));e.respondWith(n)}const X=(0,o.kg)("SW",o.v9.Error|o.v9.Debug|o.v9.Log|o.v9.Warn,!0),J=self;let Y;const H=()=>Y,Q=e=>{X("window connected",e.id,"windows before",oe.size),"none"!==e.frameType?(X("windows",Array.from(oe)),ee.invokeVoid("hello",void 0,e),(e=>{oe.size||Y||(X("sending message port for mtproto"),(e=>{const t=new MessageChannel;ee.attachPort(Y=t.port1),ee.invokeVoid("port",void 0,e,[t.port2])})(e))})(e),oe.set(e.id,e),function(e){const t=V[e.id];t&&(delete V[e.id],X("releasing share events to client:",e.id,"length:",t.length),t.forEach((t=>{ee.invokeVoid("share",t,e)})))}(e)):X.warn("maybe a bugged Safari starting window",e.id)},ee=new q;ee.addMultipleEventsListeners({notificationsClear:function(e){for(const e of N)try{e.close()}catch(e){}let t;return t="getNotifications"in j.registration?j.registration.getNotifications({tag:e}).then((e=>{for(let t=0,n=e.length;t<n;++t)try{e[t].close()}catch(e){}})).catch((e=>{X.error("Offline register SW error",e)})):Promise.resolve(),N.clear(),t},toggleStorages:({enabled:e,clearWrite:t})=>{m.toggleStorage(e,t)},pushPing:(e,t)=>{!function(e,t){I=Date.now(),_=e.localNotifications,R&&t&&(ee.invokeVoid("pushClick",R,t),R=void 0),e.lang&&F.set("push_lang",e.lang),e.settings&&F.set("push_settings",e.settings)}(e,t)},hello:(e,t)=>{Q(t)}});const{onDownloadFetch:te,onClosedWindows:ne}=function(e){return e.addMultipleEventsListeners(B),{onDownloadFetch:z,onClosedWindows:$}}(ee);(0,Z.FK)().then((e=>{X(`got ${e.length} windows from the start`),e.forEach((e=>{Q(e)}))}));const oe=new Map;self.connectedWindows=oe,function(e,t,n){const o=(t,n)=>{e.attachListenPort(t),n&&e.attachSendPort(n)};e.setOnPortDisconnect((e=>{X("something has disconnected",e),e instanceof WindowClient&&oe.has(e.id)?(oe.delete(e.id),X("window disconnected, left",oe.size),oe.size||(X.warn("no windows left"),Y&&(ee.detachPort(Y),Y=void 0),ne())):X.warn("it is not a window")})),"undefined"!=typeof SharedWorkerGlobalScope?h.Z.addEventListener("connect",(e=>o(e.source,e.source))):"undefined"!=typeof ServiceWorkerGlobalScope?o(h.Z,null):o(h.Z,h.Z)}(ee);const re=e=>{if(!A.IS_SAFARI&&0===e.request.url.indexOf(location.origin+"/")&&e.request.url.match(/\.(js|css|jpe?g|json|wasm|png|mp3|svg|tgs|ico|woff2?|ttf|webmanifest?)(?:\?.*)?$/))return e.respondWith(function(e){return t=this,n=void 0,r=function*(){try{const t=yield c(s.caches.open(i)),n=yield c(t.match(e.request,{ignoreVary:!0}));if(n&&a(n))return n;const o={Vary:"*"};let r=yield fetch(e.request,{headers:o});if(a(r))t.put(e.request,r.clone());else if(304===r.status){const n=e.request.url.replace(/\?.+$/,"")+"?"+(1e5*Math.random()|0);r=yield fetch(n,{headers:o}),a(r)&&t.put(e.request,r.clone())}return r}catch(t){return fetch(e.request)}},new((o=void 0)||(o=Promise))((function(e,s){function i(e){try{c(r.next(e))}catch(e){s(e)}}function a(e){try{c(r.throw(e))}catch(e){s(e)}}function c(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o((function(e){e(n)}))).then(i,a)}c((r=r.apply(t,n||[])).next())}));var t,n,o,r}(e));try{const[t,n]=e.request.url.split("/").slice(-2);switch(t){case"stream":!function(e,t){const n=function(e){if(!e)return[0,0];const[,t]=e.split("="),n=t.split(", "),[o,r]=n[0].split("-");return[+o,+r||0]}(e.request.headers.get("Range")),o=JSON.parse(decodeURIComponent(t)),r=S.get(o);e.respondWith(Promise.race([(45e3,new Promise((e=>{setTimeout((()=>{e(new Response("",{status:408,statusText:"Request timed out."}))}),45e3)}))),r.requestRange(n)]))}(e,n);break;case"download":te(e,n);break;case"share":K(e);break;case"ping":e.respondWith(new Response("pong"))}}catch(t){X.error("fetch error",t),e.respondWith(new Response("",{status:500,statusText:"Internal Server Error",headers:{"Cache-Control":"no-cache"}}))}},se=()=>{J.onfetch=re};J.addEventListener("install",(e=>{X("installing"),e.waitUntil(J.skipWaiting().then((()=>X("skipped waiting"))))})),J.addEventListener("activate",(e=>{X("activating",J),e.waitUntil(J.caches.delete(i).then((()=>X("cleared assets cache")))),e.waitUntil(J.clients.claim().then((()=>X("claimed clients"))))})),J.onoffline=J.ononline=se,se()}},o={};function r(e){var t=o[e];if(void 0!==t)return t.exports;var s=o[e]={exports:{}};return n[e](s,s.exports,r),s.exports}r.m=n,r.x=()=>{var e=r.O(void 0,[85],(()=>r(8592)));return r.O(e)},e=[],r.O=(t,n,o,s)=>{if(!n){var i=1/0;for(u=0;u<e.length;u++){for(var[n,o,s]=e[u],a=!0,c=0;c<n.length;c++)(!1&s||i>=s)&&Object.keys(r.O).every((e=>r.O[e](n[c])))?n.splice(c--,1):(a=!1,s<i&&(i=s));if(a){e.splice(u--,1);var l=o();void 0!==l&&(t=l)}}return t}s=s||0;for(var u=e.length;u>0&&e[u-1][2]>s;u--)e[u]=e[u-1];e[u]=[n,o,s]},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.f={},r.e=e=>Promise.all(Object.keys(r.f).reduce(((t,n)=>(r.f[n](e,t),t)),[])),r.u=e=>e+".952a9f12a6b3dcdd3f0e.bundle.js",r.miniCssF=e=>{},r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e;r.g.importScripts&&(e=r.g.location+"");var t=r.g.document;if(!e&&t&&(t.currentScript&&(e=t.currentScript.src),!e)){var n=t.getElementsByTagName("script");n.length&&(e=n[n.length-1].src)}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),r.p=e})(),(()=>{if(void 0!==r){var e=r.u,t=r.e,n={},o={};r.u=function(t){return e(t)+(n.hasOwnProperty(t)?"?"+n[t]:"")},r.e=function(s){return t(s).catch((function(t){var i=o.hasOwnProperty(s)?o[s]:999999;if(i<1){var a=e(s);throw t.message="Loading chunk "+s+" failed after 999999 retries.\n("+a+")",t.request=a,t}return new Promise((function(e){setTimeout((function(){var t=Date.now();n[s]=t,o[s]=i-1,e(r.e(s))}),3e3)}))}))}}})(),(()=>{var e={670:1};r.f.i=(t,n)=>{e[t]||importScripts(r.p+r.u(t))};var t=this.webpackChunktweb=this.webpackChunktweb||[],n=t.push.bind(t);t.push=t=>{var[o,s,i]=t;for(var a in s)r.o(s,a)&&(r.m[a]=s[a]);for(i&&i(r);o.length;)e[o.pop()]=1;n(t)}})(),t=r.x,r.x=()=>r.e(85).then(t),r.x()})();
//# sourceMappingURL=sw.04ffa51e8d749197145b.chunk.js.map