3 lines
21 KiB
JavaScript
3 lines
21 KiB
JavaScript
try{self["workbox:core:7.2.0"]&&_()}catch{}try{self["workbox:cacheable-response:7.2.0"]&&_()}catch{}class ee{constructor(e={}){this._statuses=e.statuses,this._headers=e.headers}isResponseCacheable(e){let t=!0;return this._statuses&&(t=this._statuses.includes(e.status)),this._headers&&t&&(t=Object.keys(this._headers).some(n=>e.headers.get(n)===this._headers[n])),t}}class C{constructor(e){this.cacheWillUpdate=async({response:t})=>this._cacheableResponse.isResponseCacheable(t)?t:null,this._cacheableResponse=new ee(e)}}try{self["workbox:core:7.2.0"]&&_()}catch{}const te=(s,...e)=>{let t=s;return e.length>0&&(t+=` :: ${JSON.stringify(e)}`),t},se=te;let ne=class extends Error{constructor(e,t){const n=se(e,t);super(n),this.name=e,this.details=t}};function Q(s){s.then(()=>{})}const ae=(s,e)=>e.some(t=>s instanceof t);let H,K;function re(){return H||(H=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function ie(){return K||(K=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const G=new WeakMap,M=new WeakMap,J=new WeakMap,O=new WeakMap,U=new WeakMap;function oe(s){const e=new Promise((t,n)=>{const a=()=>{s.removeEventListener("success",i),s.removeEventListener("error",r)},i=()=>{t(f(s.result)),a()},r=()=>{n(s.error),a()};s.addEventListener("success",i),s.addEventListener("error",r)});return e.then(t=>{t instanceof IDBCursor&&G.set(t,s)}).catch(()=>{}),U.set(e,s),e}function ce(s){if(M.has(s))return;const e=new Promise((t,n)=>{const a=()=>{s.removeEventListener("complete",i),s.removeEventListener("error",r),s.removeEventListener("abort",r)},i=()=>{t(),a()},r=()=>{n(s.error||new DOMException("AbortError","AbortError")),a()};s.addEventListener("complete",i),s.addEventListener("error",r),s.addEventListener("abort",r)});M.set(s,e)}let v={get(s,e,t){if(s instanceof IDBTransaction){if(e==="done")return M.get(s);if(e==="objectStoreNames")return s.objectStoreNames||J.get(s);if(e==="store")return t.objectStoreNames[1]?void 0:t.objectStore(t.objectStoreNames[0])}return f(s[e])},set(s,e,t){return s[e]=t,!0},has(s,e){return s instanceof IDBTransaction&&(e==="done"||e==="store")?!0:e in s}};function le(s){v=s(v)}function he(s){return s===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(e,...t){const n=s.call(T(this),e,...t);return J.set(n,e.sort?e.sort():[e]),f(n)}:ie().includes(s)?function(...e){return s.apply(T(this),e),f(G.get(this))}:function(...e){return f(s.apply(T(this),e))}}function ue(s){return typeof s=="function"?he(s):(s instanceof IDBTransaction&&ce(s),ae(s,re())?new Proxy(s,v):s)}function f(s){if(s instanceof IDBRequest)return oe(s);if(O.has(s))return O.get(s);const e=ue(s);return e!==s&&(O.set(s,e),U.set(e,s)),e}const T=s=>U.get(s);function de(s,e,{blocked:t,upgrade:n,blocking:a,terminated:i}={}){const r=indexedDB.open(s,e),o=f(r);return n&&r.addEventListener("upgradeneeded",c=>{n(f(r.result),c.oldVersion,c.newVersion,f(r.transaction),c)}),t&&r.addEventListener("blocked",c=>t(c.oldVersion,c.newVersion,c)),o.then(c=>{i&&c.addEventListener("close",()=>i()),a&&c.addEventListener("versionchange",l=>a(l.oldVersion,l.newVersion,l))}).catch(()=>{}),o}function fe(s,{blocked:e}={}){const t=indexedDB.deleteDatabase(s);return e&&t.addEventListener("blocked",n=>e(n.oldVersion,n)),f(t).then(()=>{})}const pe=["get","getKey","getAll","getAllKeys","count"],me=["put","add","delete","clear"],A=new Map;function $(s,e){if(!(s instanceof IDBDatabase&&!(e in s)&&typeof e=="string"))return;if(A.get(e))return A.get(e);const t=e.replace(/FromIndex$/,""),n=e!==t,a=me.includes(t);if(!(t in(n?IDBIndex:IDBObjectStore).prototype)||!(a||pe.includes(t)))return;const i=async function(r,...o){const c=this.transaction(r,a?"readwrite":"readonly");let l=c.store;return n&&(l=l.index(o.shift())),(await Promise.all([l[t](...o),a&&c.done]))[0]};return A.set(e,i),i}le(s=>({...s,get:(e,t,n)=>$(e,t)||s.get(e,t,n),has:(e,t)=>!!$(e,t)||s.has(e,t)}));try{self["workbox:expiration:7.2.0"]&&_()}catch{}const ge="workbox-expiration",x="cache-entries",q=s=>{const e=new URL(s,location.href);return e.hash="",e.href};class we{constructor(e){this._db=null,this._cacheName=e}_upgradeDb(e){const t=e.createObjectStore(x,{keyPath:"id"});t.createIndex("cacheName","cacheName",{unique:!1}),t.createIndex("timestamp","timestamp",{unique:!1})}_upgradeDbAndDeleteOldDbs(e){this._upgradeDb(e),this._cacheName&&fe(this._cacheName)}async setTimestamp(e,t){e=q(e);const n={url:e,timestamp:t,cacheName:this._cacheName,id:this._getId(e)},i=(await this.getDb()).transaction(x,"readwrite",{durability:"relaxed"});await i.store.put(n),await i.done}async getTimestamp(e){const n=await(await this.getDb()).get(x,this._getId(e));return n==null?void 0:n.timestamp}async expireEntries(e,t){const n=await this.getDb();let a=await n.transaction(x).store.index("timestamp").openCursor(null,"prev");const i=[];let r=0;for(;a;){const c=a.value;c.cacheName===this._cacheName&&(e&&c.timestamp<e||t&&r>=t?i.push(a.value):r++),a=await a.continue()}const o=[];for(const c of i)await n.delete(x,c.id),o.push(c.url);return o}_getId(e){return this._cacheName+"|"+q(e)}async getDb(){return this._db||(this._db=await de(ge,1,{upgrade:this._upgradeDbAndDeleteOldDbs.bind(this)})),this._db}}class _e{constructor(e,t={}){this._isRunning=!1,this._rerunRequested=!1,this._maxEntries=t.maxEntries,this._maxAgeSeconds=t.maxAgeSeconds,this._matchOptions=t.matchOptions,this._cacheName=e,this._timestampModel=new we(e)}async expireEntries(){if(this._isRunning){this._rerunRequested=!0;return}this._isRunning=!0;const e=this._maxAgeSeconds?Date.now()-this._maxAgeSeconds*1e3:0,t=await this._timestampModel.expireEntries(e,this._maxEntries),n=await self.caches.open(this._cacheName);for(const a of t)await n.delete(a,this._matchOptions);this._isRunning=!1,this._rerunRequested&&(this._rerunRequested=!1,Q(this.expireEntries()))}async updateTimestamp(e){await this._timestampModel.setTimestamp(e,Date.now())}async isURLExpired(e){if(this._maxAgeSeconds){const t=await this._timestampModel.getTimestamp(e),n=Date.now()-this._maxAgeSeconds*1e3;return t!==void 0?t<n:!0}else return!1}async delete(){this._rerunRequested=!1,await this._timestampModel.expireEntries(1/0)}}const u={googleAnalytics:"googleAnalytics",precache:"precache-v2",prefix:"workbox",runtime:"runtime",suffix:typeof registration<"u"?registration.scope:""},S=s=>[u.prefix,s,u.suffix].filter(e=>e&&e.length>0).join("-"),ye=s=>{for(const e of Object.keys(u))s(e)},be={updateDetails:s=>{ye(e=>{typeof s[e]=="string"&&(u[e]=s[e])})},getGoogleAnalyticsName:s=>s||S(u.googleAnalytics),getPrecacheName:s=>s||S(u.precache),getPrefix:()=>u.prefix,getRuntimeName:s=>s||S(u.runtime),getSuffix:()=>u.suffix},xe=new Set;function Ee(s){xe.add(s)}class R{constructor(e={}){this.cachedResponseWillBeUsed=async({event:t,request:n,cacheName:a,cachedResponse:i})=>{if(!i)return null;const r=this._isResponseDateFresh(i),o=this._getCacheExpiration(a);Q(o.expireEntries());const c=o.updateTimestamp(n.url);if(t)try{t.waitUntil(c)}catch{}return r?i:null},this.cacheDidUpdate=async({cacheName:t,request:n})=>{const a=this._getCacheExpiration(t);await a.updateTimestamp(n.url),await a.expireEntries()},this._config=e,this._maxAgeSeconds=e.maxAgeSeconds,this._cacheExpirations=new Map,e.purgeOnQuotaError&&Ee(()=>this.deleteCacheAndMetadata())}_getCacheExpiration(e){if(e===be.getRuntimeName())throw new ne("expire-custom-caches-only");let t=this._cacheExpirations.get(e);return t||(t=new _e(e,this._config),this._cacheExpirations.set(e,t)),t}_isResponseDateFresh(e){if(!this._maxAgeSeconds)return!0;const t=this._getDateHeaderTimestamp(e);if(t===null)return!0;const n=Date.now();return t>=n-this._maxAgeSeconds*1e3}_getDateHeaderTimestamp(e){if(!e.headers.has("date"))return null;const t=e.headers.get("date"),a=new Date(t).getTime();return isNaN(a)?null:a}async deleteCacheAndMetadata(){for(const[e,t]of this._cacheExpirations)await self.caches.delete(e),await t.delete();this._cacheExpirations=new Map}}try{self["workbox:core:7.2.0"]&&_()}catch{}try{self["workbox:navigation-preload:7.2.0"]&&_()}catch{}function Ce(){return!!(self.registration&&self.registration.navigationPreload)}function Re(s){Ce()&&self.addEventListener("activate",e=>{e.waitUntil(self.registration.navigationPreload.enable().then(()=>{s&&self.registration.navigationPreload.setHeaderValue(s)}))})}try{self["workbox:core:7.2.0"]&&_()}catch{}const ke=(s,...e)=>{let t=s;return e.length>0&&(t+=` :: ${JSON.stringify(e)}`),t},De=ke;let L=class extends Error{constructor(e,t){const n=De(e,t);super(n),this.name=e,this.details=t}};try{self["workbox:routing:7.2.0"]&&_()}catch{}const z="GET",N=s=>s&&typeof s=="object"?s:{handle:s};class p{constructor(e,t,n=z){this.handler=N(t),this.match=e,this.method=n}setCatchHandler(e){this.catchHandler=N(e)}}class j extends p{constructor(e,t,n){const a=({url:i})=>{const r=e.exec(i.href);if(r&&!(i.origin!==location.origin&&r.index!==0))return r.slice(1)};super(a,t,n)}}class Ne{constructor(){this._routes=new Map,this._defaultHandlerMap=new Map}get routes(){return this._routes}addFetchListener(){self.addEventListener("fetch",e=>{const{request:t}=e,n=this.handleRequest({request:t,event:e});n&&e.respondWith(n)})}addCacheListener(){self.addEventListener("message",e=>{if(e.data&&e.data.type==="CACHE_URLS"){const{payload:t}=e.data,n=Promise.all(t.urlsToCache.map(a=>{typeof a=="string"&&(a=[a]);const i=new Request(...a);return this.handleRequest({request:i,event:e})}));e.waitUntil(n),e.ports&&e.ports[0]&&n.then(()=>e.ports[0].postMessage(!0))}})}handleRequest({request:e,event:t}){const n=new URL(e.url,location.href);if(!n.protocol.startsWith("http"))return;const a=n.origin===location.origin,{params:i,route:r}=this.findMatchingRoute({event:t,request:e,sameOrigin:a,url:n});let o=r&&r.handler;const c=e.method;if(!o&&this._defaultHandlerMap.has(c)&&(o=this._defaultHandlerMap.get(c)),!o)return;let l;try{l=o.handle({url:n,request:e,event:t,params:i})}catch(h){l=Promise.reject(h)}const m=r&&r.catchHandler;return l instanceof Promise&&(this._catchHandler||m)&&(l=l.catch(async h=>{if(m)try{return await m.handle({url:n,request:e,event:t,params:i})}catch(I){I instanceof Error&&(h=I)}if(this._catchHandler)return this._catchHandler.handle({url:n,request:e,event:t});throw h})),l}findMatchingRoute({url:e,sameOrigin:t,request:n,event:a}){const i=this._routes.get(n.method)||[];for(const r of i){let o;const c=r.match({url:e,sameOrigin:t,request:n,event:a});if(c)return o=c,(Array.isArray(o)&&o.length===0||c.constructor===Object&&Object.keys(c).length===0||typeof c=="boolean")&&(o=void 0),{route:r,params:o}}return{}}setDefaultHandler(e,t=z){this._defaultHandlerMap.set(t,N(e))}setCatchHandler(e){this._catchHandler=N(e)}registerRoute(e){this._routes.has(e.method)||this._routes.set(e.method,[]),this._routes.get(e.method).push(e)}unregisterRoute(e){if(!this._routes.has(e.method))throw new L("unregister-route-but-not-found-with-method",{method:e.method});const t=this._routes.get(e.method).indexOf(e);if(t>-1)this._routes.get(e.method).splice(t,1);else throw new L("unregister-route-route-not-registered")}}let E;const Ie=()=>(E||(E=new Ne,E.addFetchListener(),E.addCacheListener()),E);function k(s,e,t){let n;if(typeof s=="string"){const i=new URL(s,location.href),r=({url:o})=>o.href===i.href;n=new p(r,e,t)}else if(s instanceof RegExp)n=new j(s,e,t);else if(typeof s=="function")n=new p(s,e,t);else if(s instanceof p)n=s;else throw new L("unsupported-route-type",{moduleName:"workbox-routing",funcName:"registerRoute",paramName:"capture"});return Ie().registerRoute(n),n}try{self["workbox:core:7.2.0"]&&_()}catch{}const Oe=(s,...e)=>{let t=s;return e.length>0&&(t+=` :: ${JSON.stringify(e)}`),t},Te=Oe;class y extends Error{constructor(e,t){const n=Te(e,t);super(n),this.name=e,this.details=t}}const d={googleAnalytics:"googleAnalytics",precache:"precache-v2",prefix:"workbox",runtime:"runtime",suffix:typeof registration<"u"?registration.scope:""},P=s=>[d.prefix,s,d.suffix].filter(e=>e&&e.length>0).join("-"),Ae=s=>{for(const e of Object.keys(d))s(e)},Se={updateDetails:s=>{Ae(e=>{typeof s[e]=="string"&&(d[e]=s[e])})},getGoogleAnalyticsName:s=>s||P(d.googleAnalytics),getPrecacheName:s=>s||P(d.precache),getPrefix:()=>d.prefix,getRuntimeName:s=>s||P(d.runtime),getSuffix:()=>d.suffix},Pe=s=>new URL(String(s),location.href).href.replace(new RegExp(`^${location.origin}`),"");function V(s,e){const t=new URL(s);for(const n of e)t.searchParams.delete(n);return t.href}async function Me(s,e,t,n){const a=V(e.url,t);if(e.url===a)return s.match(e,n);const i=Object.assign(Object.assign({},n),{ignoreSearch:!0}),r=await s.keys(e,i);for(const o of r){const c=V(o.url,t);if(a===c)return s.match(o,n)}}class ve{constructor(){this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}const Le=new Set;async function Ue(){for(const s of Le)await s()}function je(s){return new Promise(e=>setTimeout(e,s))}try{self["workbox:strategies:7.2.0"]&&_()}catch{}function D(s){return typeof s=="string"?new Request(s):s}class We{constructor(e,t){this._cacheKeys={},Object.assign(this,t),this.event=t.event,this._strategy=e,this._handlerDeferred=new ve,this._extendLifetimePromises=[],this._plugins=[...e.plugins],this._pluginStateMap=new Map;for(const n of this._plugins)this._pluginStateMap.set(n,{});this.event.waitUntil(this._handlerDeferred.promise)}async fetch(e){const{event:t}=this;let n=D(e);if(n.mode==="navigate"&&t instanceof FetchEvent&&t.preloadResponse){const r=await t.preloadResponse;if(r)return r}const a=this.hasCallback("fetchDidFail")?n.clone():null;try{for(const r of this.iterateCallbacks("requestWillFetch"))n=await r({request:n.clone(),event:t})}catch(r){if(r instanceof Error)throw new y("plugin-error-request-will-fetch",{thrownErrorMessage:r.message})}const i=n.clone();try{let r;r=await fetch(n,n.mode==="navigate"?void 0:this._strategy.fetchOptions);for(const o of this.iterateCallbacks("fetchDidSucceed"))r=await o({event:t,request:i,response:r});return r}catch(r){throw a&&await this.runCallbacks("fetchDidFail",{error:r,event:t,originalRequest:a.clone(),request:i.clone()}),r}}async fetchAndCachePut(e){const t=await this.fetch(e),n=t.clone();return this.waitUntil(this.cachePut(e,n)),t}async cacheMatch(e){const t=D(e);let n;const{cacheName:a,matchOptions:i}=this._strategy,r=await this.getCacheKey(t,"read"),o=Object.assign(Object.assign({},i),{cacheName:a});n=await caches.match(r,o);for(const c of this.iterateCallbacks("cachedResponseWillBeUsed"))n=await c({cacheName:a,matchOptions:i,cachedResponse:n,request:r,event:this.event})||void 0;return n}async cachePut(e,t){const n=D(e);await je(0);const a=await this.getCacheKey(n,"write");if(!t)throw new y("cache-put-with-no-response",{url:Pe(a.url)});const i=await this._ensureResponseSafeToCache(t);if(!i)return!1;const{cacheName:r,matchOptions:o}=this._strategy,c=await self.caches.open(r),l=this.hasCallback("cacheDidUpdate"),m=l?await Me(c,a.clone(),["__WB_REVISION__"],o):null;try{await c.put(a,l?i.clone():i)}catch(h){if(h instanceof Error)throw h.name==="QuotaExceededError"&&await Ue(),h}for(const h of this.iterateCallbacks("cacheDidUpdate"))await h({cacheName:r,oldResponse:m,newResponse:i.clone(),request:a,event:this.event});return!0}async getCacheKey(e,t){const n=`${e.url} | ${t}`;if(!this._cacheKeys[n]){let a=e;for(const i of this.iterateCallbacks("cacheKeyWillBeUsed"))a=D(await i({mode:t,request:a,event:this.event,params:this.params}));this._cacheKeys[n]=a}return this._cacheKeys[n]}hasCallback(e){for(const t of this._strategy.plugins)if(e in t)return!0;return!1}async runCallbacks(e,t){for(const n of this.iterateCallbacks(e))await n(t)}*iterateCallbacks(e){for(const t of this._strategy.plugins)if(typeof t[e]=="function"){const n=this._pluginStateMap.get(t);yield i=>{const r=Object.assign(Object.assign({},i),{state:n});return t[e](r)}}}waitUntil(e){return this._extendLifetimePromises.push(e),e}async doneWaiting(){let e;for(;e=this._extendLifetimePromises.shift();)await e}destroy(){this._handlerDeferred.resolve(null)}async _ensureResponseSafeToCache(e){let t=e,n=!1;for(const a of this.iterateCallbacks("cacheWillUpdate"))if(t=await a({request:this.request,response:t,event:this.event})||void 0,n=!0,!t)break;return n||t&&t.status!==200&&(t=void 0),t}}class W{constructor(e={}){this.cacheName=Se.getRuntimeName(e.cacheName),this.plugins=e.plugins||[],this.fetchOptions=e.fetchOptions,this.matchOptions=e.matchOptions}handle(e){const[t]=this.handleAll(e);return t}handleAll(e){e instanceof FetchEvent&&(e={event:e,request:e.request});const t=e.event,n=typeof e.request=="string"?new Request(e.request):e.request,a="params"in e?e.params:void 0,i=new We(this,{event:t,request:n,params:a}),r=this._getResponse(i,n,t),o=this._awaitComplete(r,i,n,t);return[r,o]}async _getResponse(e,t,n){await e.runCallbacks("handlerWillStart",{event:n,request:t});let a;try{if(a=await this._handle(t,e),!a||a.type==="error")throw new y("no-response",{url:t.url})}catch(i){if(i instanceof Error){for(const r of e.iterateCallbacks("handlerDidError"))if(a=await r({error:i,event:n,request:t}),a)break}if(!a)throw i}for(const i of e.iterateCallbacks("handlerWillRespond"))a=await i({event:n,request:t,response:a});return a}async _awaitComplete(e,t,n,a){let i,r;try{i=await e}catch{}try{await t.runCallbacks("handlerDidRespond",{event:a,request:n,response:i}),await t.doneWaiting()}catch(o){o instanceof Error&&(r=o)}if(await t.runCallbacks("handlerDidComplete",{event:a,request:n,response:i,error:r}),t.destroy(),r)throw r}}class X extends W{async _handle(e,t){let n=await t.cacheMatch(e),a;if(!n)try{n=await t.fetchAndCachePut(e)}catch(i){i instanceof Error&&(a=i)}if(!n)throw new y("no-response",{url:e.url,error:a});return n}}const Y={cacheWillUpdate:async({response:s})=>s.status===200||s.status===0?s:null};class Z extends W{constructor(e={}){super(e),this.plugins.some(t=>"cacheWillUpdate"in t)||this.plugins.unshift(Y),this._networkTimeoutSeconds=e.networkTimeoutSeconds||0}async _handle(e,t){const n=[],a=[];let i;if(this._networkTimeoutSeconds){const{id:c,promise:l}=this._getTimeoutPromise({request:e,logs:n,handler:t});i=c,a.push(l)}const r=this._getNetworkPromise({timeoutId:i,request:e,logs:n,handler:t});a.push(r);const o=await t.waitUntil((async()=>await t.waitUntil(Promise.race(a))||await r)());if(!o)throw new y("no-response",{url:e.url});return o}_getTimeoutPromise({request:e,logs:t,handler:n}){let a;return{promise:new Promise(r=>{a=setTimeout(async()=>{r(await n.cacheMatch(e))},this._networkTimeoutSeconds*1e3)}),id:a}}async _getNetworkPromise({timeoutId:e,request:t,logs:n,handler:a}){let i,r;try{r=await a.fetchAndCachePut(t)}catch(o){o instanceof Error&&(i=o)}return e&&clearTimeout(e),(i||!r)&&(r=await a.cacheMatch(t)),r}}class Be extends W{constructor(e={}){super(e),this.plugins.some(t=>"cacheWillUpdate"in t)||this.plugins.unshift(Y)}async _handle(e,t){const n=t.fetchAndCachePut(e).catch(()=>{});t.waitUntil(n);let a=await t.cacheMatch(e),i;if(!a)try{a=await n}catch(r){r instanceof Error&&(i=r)}if(!a)throw new y("no-response",{url:e.url,error:i});return a}}Re();self.__WB_DISABLE_DEV_LOGS=!0;const Fe=new p(({request:s,sameOrigin:e})=>{const t=s.url.includes("/icons/");return e&&t},new X({cacheName:"icons",plugins:[new R({maxEntries:300,maxAgeSeconds:3*24*60*60,purgeOnQuotaError:!0}),new C({statuses:[0,200]})]}));k(Fe);const He=new p(({request:s,sameOrigin:e})=>{const t=s.destination==="style"||s.destination==="script",n=/-[0-9a-z-]{4,}\./i.test(s.url);return e&&t&&n},new Z({cacheName:"assets",networkTimeoutSeconds:5,plugins:[new R({maxEntries:30,purgeOnQuotaError:!0}),new C({statuses:[0,200]})]}));k(He);const Ke=new p(({request:s,sameOrigin:e})=>{const t=!e,n=s.destination==="image",a=s.url.includes("/avatars/"),i=s.url.includes("/custom/_emojis"),r=s.url.includes("/emoji/");return t&&n&&(a||i||r)},new X({cacheName:"remote-images",plugins:[new R({maxEntries:30,purgeOnQuotaError:!0}),new C({statuses:[0,200]})]}));k(Ke);const $e=new j(/^https?:\/\/[^\/]+\/api\/v\d+\/(custom_emojis|lists\/\d+|announcements)$/,new Be({cacheName:"api-extended",plugins:[new R({maxAgeSeconds:12*60*60,purgeOnQuotaError:!0}),new C({statuses:[0,200]})]}));k($e);const qe=new j(/^https?:\/\/[^\/]+\/api\/v\d+\/(statuses\/\d+\/context)/,new Z({cacheName:"api",networkTimeoutSeconds:5,plugins:[new R({maxEntries:30,maxAgeSeconds:5*60,purgeOnQuotaError:!0}),new C({statuses:[0,200]})]}));k(qe);self.addEventListener("push",s=>{const{data:e}=s;if(e){const t=e.json();console.log("PUSH payload",t);const{access_token:n,title:a,body:i,icon:r,notification_id:o,notification_type:c,preferred_locale:l}=t;navigator.setAppBadge&&c==="mention"&&navigator.setAppBadge(1),s.waitUntil(self.registration.showNotification(a,{body:i,icon:r,dir:"auto",badge:"/logo-badge-72.png",lang:l,tag:o,timestamp:Date.now(),data:{access_token:n,notification_type:c}}))}});self.addEventListener("notificationclick",s=>{const e=s.notification;console.log("NOTIFICATION CLICK payload",e);const{badge:t,body:n,data:a,dir:i,icon:r,lang:o,tag:c,timestamp:l,title:m}=e,{access_token:h,notification_type:I}=a,b=`/#/notifications?id=${c}&access_token=${btoa(h)}`;s.waitUntil((async()=>{var B;const g=await self.clients.matchAll({type:"window",includeUncontrolled:!0});if(console.log("NOTIFICATION CLICK clients 1",g),g.length&&"navigate"in g[0]){console.log("NOTIFICATION CLICK clients 2",g);const w=g.find(F=>F.focused||F.visibilityState==="visible")||g[0];console.log("NOTIFICATION CLICK navigate",b),w?(console.log("NOTIFICATION CLICK postMessage",w),w.focus(),(B=w.postMessage)==null||B.call(w,{type:"notification",id:c,accessToken:h})):(console.log("NOTIFICATION CLICK openWindow",b),await self.clients.openWindow(b))}else console.log("NOTIFICATION CLICK openWindow",b),await self.clients.openWindow(b);await s.notification.close()})())});
|
|
//# sourceMappingURL=sw.js.map
|