@xiboplayer/pwa 0.1.0 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{cache-proxy-Cx4Z8XMC.js → cache-proxy-D6-jdEoS.js} +2 -2
- package/dist/assets/{cache-proxy-Cx4Z8XMC.js.map → cache-proxy-D6-jdEoS.js.map} +1 -1
- package/dist/assets/cms-api-kzy_Sw-u.js.map +1 -1
- package/dist/assets/index-BPNsrSEv.js.map +1 -1
- package/dist/assets/index-CTmjUTVM.js.map +1 -1
- package/dist/assets/{index-BEhNaWZ4.js → index-Dv_i6_Lf.js} +2 -2
- package/dist/assets/{index-BEhNaWZ4.js.map → index-Dv_i6_Lf.js.map} +1 -1
- package/dist/assets/index-HL3kcMoq.js +2 -0
- package/dist/assets/index-HL3kcMoq.js.map +1 -0
- package/dist/assets/index-_q2HbdAU.js.map +1 -1
- package/dist/assets/index-_uzldOpz.js.map +1 -1
- package/dist/assets/{main-C4ABDfkq.js → main-DhC5BKp3.js} +4 -4
- package/dist/assets/main-DhC5BKp3.js.map +1 -0
- package/dist/index.html +2 -2
- package/dist/sw-pwa.js +1 -1
- package/dist/sw-pwa.js.map +1 -1
- package/package.json +20 -18
- package/dist/assets/index-BY2j60YZ.js +0 -2
- package/dist/assets/index-BY2j60YZ.js.map +0 -1
- package/dist/assets/main-C4ABDfkq.js.map +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as H,c as O,C as K,d as q,L as G,b as V,f as Z,g as Y,i as Q,m as X,r as J,s as ee,u as te}from"./cms-api-kzy_Sw-u.js";class L{constructor(){this.events=new Map}on(a,s){this.events.has(a)||this.events.set(a,[]),this.events.get(a).push(s)}once(a,s){const c=(...l)=>{s(...l),this.off(a,c)};this.on(a,c)}off(a,s){if(!this.events.has(a))return;const c=this.events.get(a),l=c.indexOf(s);l!==-1&&c.splice(l,1)}emit(a,...s){if(!this.events.has(a))return;const c=this.events.get(a).slice();for(const l of c)l(...s)}removeAllListeners(a){a?this.events.delete(a):this.events.clear()}}const le=Object.freeze(Object.defineProperty({__proto__:null,CmsApiClient:K,CmsApiError:q,EventEmitter:L,LOG_LEVELS:G,applyCmsLogLevel:V,config:H,createLogger:O,fetchWithRetry:Z,getLogLevel:Y,isDebug:Q,mapCmsLogLevel:X,registerLogSink:J,setLogLevel:ee,unregisterLogSink:te},Symbol.toStringTag,{value:"Module"}));function re(E){return E&&E.__esModule&&Object.prototype.hasOwnProperty.call(E,"default")?E.default:E}var N={exports:{}};(function(E,a){(function(s){E.exports=s()})(function(s){var c=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];function l(i,o){var t=i[0],e=i[1],n=i[2],r=i[3];t+=(e&n|~e&r)+o[0]-680876936|0,t=(t<<7|t>>>25)+e|0,r+=(t&e|~t&n)+o[1]-389564586|0,r=(r<<12|r>>>20)+t|0,n+=(r&t|~r&e)+o[2]+606105819|0,n=(n<<17|n>>>15)+r|0,e+=(n&r|~n&t)+o[3]-1044525330|0,e=(e<<22|e>>>10)+n|0,t+=(e&n|~e&r)+o[4]-176418897|0,t=(t<<7|t>>>25)+e|0,r+=(t&e|~t&n)+o[5]+1200080426|0,r=(r<<12|r>>>20)+t|0,n+=(r&t|~r&e)+o[6]-1473231341|0,n=(n<<17|n>>>15)+r|0,e+=(n&r|~n&t)+o[7]-45705983|0,e=(e<<22|e>>>10)+n|0,t+=(e&n|~e&r)+o[8]+1770035416|0,t=(t<<7|t>>>25)+e|0,r+=(t&e|~t&n)+o[9]-1958414417|0,r=(r<<12|r>>>20)+t|0,n+=(r&t|~r&e)+o[10]-42063|0,n=(n<<17|n>>>15)+r|0,e+=(n&r|~n&t)+o[11]-1990404162|0,e=(e<<22|e>>>10)+n|0,t+=(e&n|~e&r)+o[12]+1804603682|0,t=(t<<7|t>>>25)+e|0,r+=(t&e|~t&n)+o[13]-40341101|0,r=(r<<12|r>>>20)+t|0,n+=(r&t|~r&e)+o[14]-1502002290|0,n=(n<<17|n>>>15)+r|0,e+=(n&r|~n&t)+o[15]+1236535329|0,e=(e<<22|e>>>10)+n|0,t+=(e&r|n&~r)+o[1]-165796510|0,t=(t<<5|t>>>27)+e|0,r+=(t&n|e&~n)+o[6]-1069501632|0,r=(r<<9|r>>>23)+t|0,n+=(r&e|t&~e)+o[11]+643717713|0,n=(n<<14|n>>>18)+r|0,e+=(n&t|r&~t)+o[0]-373897302|0,e=(e<<20|e>>>12)+n|0,t+=(e&r|n&~r)+o[5]-701558691|0,t=(t<<5|t>>>27)+e|0,r+=(t&n|e&~n)+o[10]+38016083|0,r=(r<<9|r>>>23)+t|0,n+=(r&e|t&~e)+o[15]-660478335|0,n=(n<<14|n>>>18)+r|0,e+=(n&t|r&~t)+o[4]-405537848|0,e=(e<<20|e>>>12)+n|0,t+=(e&r|n&~r)+o[9]+568446438|0,t=(t<<5|t>>>27)+e|0,r+=(t&n|e&~n)+o[14]-1019803690|0,r=(r<<9|r>>>23)+t|0,n+=(r&e|t&~e)+o[3]-187363961|0,n=(n<<14|n>>>18)+r|0,e+=(n&t|r&~t)+o[8]+1163531501|0,e=(e<<20|e>>>12)+n|0,t+=(e&r|n&~r)+o[13]-1444681467|0,t=(t<<5|t>>>27)+e|0,r+=(t&n|e&~n)+o[2]-51403784|0,r=(r<<9|r>>>23)+t|0,n+=(r&e|t&~e)+o[7]+1735328473|0,n=(n<<14|n>>>18)+r|0,e+=(n&t|r&~t)+o[12]-1926607734|0,e=(e<<20|e>>>12)+n|0,t+=(e^n^r)+o[5]-378558|0,t=(t<<4|t>>>28)+e|0,r+=(t^e^n)+o[8]-2022574463|0,r=(r<<11|r>>>21)+t|0,n+=(r^t^e)+o[11]+1839030562|0,n=(n<<16|n>>>16)+r|0,e+=(n^r^t)+o[14]-35309556|0,e=(e<<23|e>>>9)+n|0,t+=(e^n^r)+o[1]-1530992060|0,t=(t<<4|t>>>28)+e|0,r+=(t^e^n)+o[4]+1272893353|0,r=(r<<11|r>>>21)+t|0,n+=(r^t^e)+o[7]-155497632|0,n=(n<<16|n>>>16)+r|0,e+=(n^r^t)+o[10]-1094730640|0,e=(e<<23|e>>>9)+n|0,t+=(e^n^r)+o[13]+681279174|0,t=(t<<4|t>>>28)+e|0,r+=(t^e^n)+o[0]-358537222|0,r=(r<<11|r>>>21)+t|0,n+=(r^t^e)+o[3]-722521979|0,n=(n<<16|n>>>16)+r|0,e+=(n^r^t)+o[6]+76029189|0,e=(e<<23|e>>>9)+n|0,t+=(e^n^r)+o[9]-640364487|0,t=(t<<4|t>>>28)+e|0,r+=(t^e^n)+o[12]-421815835|0,r=(r<<11|r>>>21)+t|0,n+=(r^t^e)+o[15]+530742520|0,n=(n<<16|n>>>16)+r|0,e+=(n^r^t)+o[2]-995338651|0,e=(e<<23|e>>>9)+n|0,t+=(n^(e|~r))+o[0]-198630844|0,t=(t<<6|t>>>26)+e|0,r+=(e^(t|~n))+o[7]+1126891415|0,r=(r<<10|r>>>22)+t|0,n+=(t^(r|~e))+o[14]-1416354905|0,n=(n<<15|n>>>17)+r|0,e+=(r^(n|~t))+o[5]-57434055|0,e=(e<<21|e>>>11)+n|0,t+=(n^(e|~r))+o[12]+1700485571|0,t=(t<<6|t>>>26)+e|0,r+=(e^(t|~n))+o[3]-1894986606|0,r=(r<<10|r>>>22)+t|0,n+=(t^(r|~e))+o[10]-1051523|0,n=(n<<15|n>>>17)+r|0,e+=(r^(n|~t))+o[1]-2054922799|0,e=(e<<21|e>>>11)+n|0,t+=(n^(e|~r))+o[8]+1873313359|0,t=(t<<6|t>>>26)+e|0,r+=(e^(t|~n))+o[15]-30611744|0,r=(r<<10|r>>>22)+t|0,n+=(t^(r|~e))+o[6]-1560198380|0,n=(n<<15|n>>>17)+r|0,e+=(r^(n|~t))+o[13]+1309151649|0,e=(e<<21|e>>>11)+n|0,t+=(n^(e|~r))+o[4]-145523070|0,t=(t<<6|t>>>26)+e|0,r+=(e^(t|~n))+o[11]-1120210379|0,r=(r<<10|r>>>22)+t|0,n+=(t^(r|~e))+o[2]+718787259|0,n=(n<<15|n>>>17)+r|0,e+=(r^(n|~t))+o[9]-343485551|0,e=(e<<21|e>>>11)+n|0,i[0]=t+i[0]|0,i[1]=e+i[1]|0,i[2]=n+i[2]|0,i[3]=r+i[3]|0}function h(i){var o=[],t;for(t=0;t<64;t+=4)o[t>>2]=i.charCodeAt(t)+(i.charCodeAt(t+1)<<8)+(i.charCodeAt(t+2)<<16)+(i.charCodeAt(t+3)<<24);return o}function u(i){var o=[],t;for(t=0;t<64;t+=4)o[t>>2]=i[t]+(i[t+1]<<8)+(i[t+2]<<16)+(i[t+3]<<24);return o}function w(i){var o=i.length,t=[1732584193,-271733879,-1732584194,271733878],e,n,r,p,b,S;for(e=64;e<=o;e+=64)l(t,h(i.substring(e-64,e)));for(i=i.substring(e-64),n=i.length,r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],e=0;e<n;e+=1)r[e>>2]|=i.charCodeAt(e)<<(e%4<<3);if(r[e>>2]|=128<<(e%4<<3),e>55)for(l(t,r),e=0;e<16;e+=1)r[e]=0;return p=o*8,p=p.toString(16).match(/(.*?)(.{0,8})$/),b=parseInt(p[2],16),S=parseInt(p[1],16)||0,r[14]=b,r[15]=S,l(t,r),t}function g(i){var o=i.length,t=[1732584193,-271733879,-1732584194,271733878],e,n,r,p,b,S;for(e=64;e<=o;e+=64)l(t,u(i.subarray(e-64,e)));for(i=e-64<o?i.subarray(e-64):new Uint8Array(0),n=i.length,r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],e=0;e<n;e+=1)r[e>>2]|=i[e]<<(e%4<<3);if(r[e>>2]|=128<<(e%4<<3),e>55)for(l(t,r),e=0;e<16;e+=1)r[e]=0;return p=o*8,p=p.toString(16).match(/(.*?)(.{0,8})$/),b=parseInt(p[2],16),S=parseInt(p[1],16)||0,r[14]=b,r[15]=S,l(t,r),t}function $(i){var o="",t;for(t=0;t<4;t+=1)o+=c[i>>t*8+4&15]+c[i>>t*8&15];return o}function C(i){var o;for(o=0;o<i.length;o+=1)i[o]=$(i[o]);return i.join("")}C(w("hello")),typeof ArrayBuffer<"u"&&!ArrayBuffer.prototype.slice&&function(){function i(o,t){return o=o|0||0,o<0?Math.max(o+t,0):Math.min(o,t)}ArrayBuffer.prototype.slice=function(o,t){var e=this.byteLength,n=i(o,e),r=e,p,b,S,_;return t!==s&&(r=i(t,e)),n>r?new ArrayBuffer(0):(p=r-n,b=new ArrayBuffer(p),S=new Uint8Array(b),_=new Uint8Array(this,n,p),S.set(_),b)}}();function m(i){return/[\u0080-\uFFFF]/.test(i)&&(i=unescape(encodeURIComponent(i))),i}function v(i,o){var t=i.length,e=new ArrayBuffer(t),n=new Uint8Array(e),r;for(r=0;r<t;r+=1)n[r]=i.charCodeAt(r);return o?n:e}function R(i){return String.fromCharCode.apply(null,new Uint8Array(i))}function A(i,o,t){var e=new Uint8Array(i.byteLength+o.byteLength);return e.set(new Uint8Array(i)),e.set(new Uint8Array(o),i.byteLength),e}function y(i){var o=[],t=i.length,e;for(e=0;e<t-1;e+=2)o.push(parseInt(i.substr(e,2),16));return String.fromCharCode.apply(String,o)}function d(){this.reset()}return d.prototype.append=function(i){return this.appendBinary(m(i)),this},d.prototype.appendBinary=function(i){this._buff+=i,this._length+=i.length;var o=this._buff.length,t;for(t=64;t<=o;t+=64)l(this._hash,h(this._buff.substring(t-64,t)));return this._buff=this._buff.substring(t-64),this},d.prototype.end=function(i){var o=this._buff,t=o.length,e,n=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],r;for(e=0;e<t;e+=1)n[e>>2]|=o.charCodeAt(e)<<(e%4<<3);return this._finish(n,t),r=C(this._hash),i&&(r=y(r)),this.reset(),r},d.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},d.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash.slice()}},d.prototype.setState=function(i){return this._buff=i.buff,this._length=i.length,this._hash=i.hash,this},d.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},d.prototype._finish=function(i,o){var t=o,e,n,r;if(i[t>>2]|=128<<(t%4<<3),t>55)for(l(this._hash,i),t=0;t<16;t+=1)i[t]=0;e=this._length*8,e=e.toString(16).match(/(.*?)(.{0,8})$/),n=parseInt(e[2],16),r=parseInt(e[1],16)||0,i[14]=n,i[15]=r,l(this._hash,i)},d.hash=function(i,o){return d.hashBinary(m(i),o)},d.hashBinary=function(i,o){var t=w(i),e=C(t);return o?y(e):e},d.ArrayBuffer=function(){this.reset()},d.ArrayBuffer.prototype.append=function(i){var o=A(this._buff.buffer,i),t=o.length,e;for(this._length+=i.byteLength,e=64;e<=t;e+=64)l(this._hash,u(o.subarray(e-64,e)));return this._buff=e-64<t?new Uint8Array(o.buffer.slice(e-64)):new Uint8Array(0),this},d.ArrayBuffer.prototype.end=function(i){var o=this._buff,t=o.length,e=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],n,r;for(n=0;n<t;n+=1)e[n>>2]|=o[n]<<(n%4<<3);return this._finish(e,t),r=C(this._hash),i&&(r=y(r)),this.reset(),r},d.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},d.ArrayBuffer.prototype.getState=function(){var i=d.prototype.getState.call(this);return i.buff=R(i.buff),i},d.ArrayBuffer.prototype.setState=function(i){return i.buff=v(i.buff,!0),d.prototype.setState.call(this,i)},d.ArrayBuffer.prototype.destroy=d.prototype.destroy,d.ArrayBuffer.prototype._finish=d.prototype._finish,d.ArrayBuffer.hash=function(i,o){var t=g(new Uint8Array(i)),e=C(t);return o?y(e):e},d})})(N);var ne=N.exports;const oe=re(ne),B="xibo-media-v1",ae="xibo-player",se=1,x="files",z=4,k=typeof window<"u"&&window.location.pathname.replace(/\/[^/]*$/,"").replace(/\/$/,"")||"/player/pwa";class ie{constructor(){this.cache=null,this.db=null,this.dependants=new Map}extractFilename(a){try{return new URL(a).searchParams.get("file")||"unknown"}catch{return"unknown"}}rewriteUrl(a){if(!a)return a;try{const s=new URL(a),c=new URL(H.cmsAddress);if(s.origin!==c.origin)return console.log(`[Cache] Rewriting URL: ${s.origin} → ${c.origin}`),s.protocol=c.protocol,s.hostname=c.hostname,s.port=c.port,s.toString()}catch{}return a}async init(){this.cache=await caches.open(B),this.db=await this.openDB()}openDB(){return new Promise((a,s)=>{const c=indexedDB.open(ae,se);c.onerror=()=>s(c.error),c.onsuccess=()=>a(c.result),c.onupgradeneeded=l=>{const h=l.target.result;h.objectStoreNames.contains(x)||h.createObjectStore(x,{keyPath:"id"}).createIndex("type","type",{unique:!1})}})}async getFile(a){return new Promise((s,c)=>{const u=this.db.transaction(x,"readonly").objectStore(x).get(a);u.onsuccess=()=>s(u.result),u.onerror=()=>c(u.error)})}async saveFile(a){return new Promise((s,c)=>{const u=this.db.transaction(x,"readwrite").objectStore(x).put(a);u.onsuccess=()=>s(),u.onerror=()=>c(u.error)})}async getAllFiles(){return new Promise((a,s)=>{const h=this.db.transaction(x,"readonly").objectStore(x).getAll();h.onsuccess=()=>a(h.result),h.onerror=()=>s(h.error)})}async downloadFile(a){var i;const{id:s,type:c,path:l,md5:h,download:u}=a;if(typeof navigator<"u"&&((i=navigator.serviceWorker)!=null&&i.controller))return console.log(`[Cache] Service Worker active - skipping direct download for ${c}/${s}`),console.log("[Cache] File will be downloaded by Service Worker in background"),{id:s,type:c,path:l,md5:h||"pending",size:0,cachedAt:Date.now(),isServiceWorkerDownload:!0};if(!l||l==="null"||l==="undefined")return console.log(`[Cache] Skipping ${c}/${s} - no download URL (will be generated on-demand)`),null;const w=await this.getFile(s),g=this.getCacheKey(c,s);if(w)if(w.md5===h){const o=await this.cache.match(g);if(o&&c==="media"){const t=await o.blob(),e=o.headers.get("Content-Type");if(e==="text/plain"||t.size<100)console.warn(`[Cache] Bad cache detected for ${c}/${s} (${e}, ${t.size} bytes) - re-downloading`),await this.cache.delete(g);else return console.log(`[Cache] ${c}/${s} already cached`),w}else return console.log(`[Cache] ${c}/${s} already cached`),w}else console.warn(`[Cache] ${c}/${s} MD5 changed (cached: ${w.md5}, expected: ${h}) - re-downloading`),await this.cache.delete(g);console.log(`[Cache] Downloading ${c}/${s} from ${l}`);const $=this.rewriteUrl(l);console.log(`[Cache] Using URL: ${$}`);const C=await fetch($,{method:"HEAD"});if(C.status===202)return console.warn(`[Cache] ${c}/${s} still downloading in background (HTTP 202) - will retry on next collection`),{id:s,type:c,path:l,md5:h||"pending",size:0,cachedAt:Date.now(),isPending:!0};const m=parseInt(C.headers.get("Content-Length")||"0"),v=m>100*1024*1024;console.log(`[Cache] File size: ${(m/1024/1024).toFixed(1)} MB ${v?"(large file)":""}`);const R=c==="media"?this.extractFilename(l):s;let A,y;if(v){console.log(`[Cache] Large file detected (${(m/1024/1024).toFixed(1)} MB), caching in background`),this.downloadLargeFileInBackground($,g,m,R,s,c,l,h).catch(t=>console.warn(`[Cache] Background download failed for ${s}:`,t));const o={id:s,type:c,path:l,md5:h||"pending",size:m,cachedAt:Date.now(),isBackgroundDownload:!0};return await this.saveFile(o),console.log(`[Cache] ${c}/${s} downloading in background (${m} bytes)`),o}else{this.notifyDownloadProgress(R,0,m);const o=await fetch($);if(o.status===202)return console.warn(`[Cache] ${c}/${s} still downloading in background (HTTP 202) - will retry on next collection`),{id:s,type:c,path:l,md5:h||"pending",size:0,cachedAt:Date.now(),isPending:!0};if(!o.ok)throw new Error(`Failed to download ${l}: ${o.status}`);const t=await o.blob(),e=await t.arrayBuffer();A=oe.ArrayBuffer.hash(e),h&&A!==h&&(console.warn(`[Cache] MD5 mismatch for ${c}/${s}:`),console.warn(`[Cache] Expected: ${h}`),console.warn(`[Cache] Got: ${A}`),console.warn("[Cache] Accepting file anyway (kiosk mode - renderer will validate)"),A=h),await this.cache.put(g,new Response(t,{headers:{"Content-Type":o.headers.get("Content-Type")||"application/octet-stream","Content-Length":t.size}})),y=t.size,this.notifyDownloadProgress(R,y,m,!0),console.log(`[Cache] Cached ${c}/${s} (${y} bytes, MD5: ${A})`)}const d={id:s,type:c,path:l,md5:A,size:y,cachedAt:Date.now()};return await this.saveFile(d),d}getCacheKey(a,s,c=null){return`${k}/cache/${a}/${c||s}`}async getCachedFile(a,s){const c=this.getCacheKey(a,s),l=await this.cache.match(c);return l?await l.blob():null}async getCachedResponse(a,s){const c=this.getCacheKey(a,s);return await this.cache.match(c)}async getCachedFileText(a,s){const c=this.getCacheKey(a,s),l=await this.cache.match(c);return l?await l.text():null}async cacheWidgetHtml(a,s,c,l){const h=`${k}/cache/widget/${a}/${s}/${c}`,u=await caches.open(B),w='<base href="/player/cache/media/">';let g=l;l.includes("<head>")?g=l.replace("<head>","<head>"+w):l.includes("<HEAD>")?g=l.replace("<HEAD>","<HEAD>"+w):g=w+l;const $=/https?:\/\/[^"'\s)]+xmds\.php\?[^"'\s)]*file=([^&"'\s)]+)[^"'\s)]*/g,C=[];g=g.replace($,(A,y)=>{const d=`${k}/cache/static/${y}`;return C.push({filename:y,originalUrl:A}),console.log(`[Cache] Rewrote widget URL: ${y} → ${d}`),d});const m="<style>img,video{object-position:center center}</style>";g.includes("</head>")?g=g.replace("</head>",m+"</head>"):g.includes("</HEAD>")&&(g=g.replace("</HEAD>",m+"</HEAD>")),g=g.replace(/hostAddress\s*:\s*["']https?:\/\/[^"']+["']/g,`hostAddress: "${k}/ic"`),console.log("[Cache] Injected base tag and rewrote CMS URLs in widget HTML");const v=new URL(h,window.location.origin),R=new Response(g,{headers:{"Content-Type":"text/html; charset=utf-8","Access-Control-Allow-Origin":"*"}});if(await u.put(v,R),console.log(`[Cache] Stored widget HTML at ${h} (${g.length} bytes)`),C.length>0){const y=await caches.open("xibo-static-v1");await Promise.all(C.map(async({filename:d,originalUrl:i})=>{const o=`${k}/cache/static/${d}`;if(!await y.match(o))try{const e=await fetch(i);if(!e.ok){console.warn(`[Cache] Failed to fetch static resource: ${d} (HTTP ${e.status})`);return}const n=d.split(".").pop().toLowerCase(),r={js:"application/javascript",css:"text/css",otf:"font/otf",ttf:"font/ttf",woff:"font/woff",woff2:"font/woff2",eot:"application/vnd.ms-fontobject",svg:"image/svg+xml"}[n]||"application/octet-stream";if(n==="css"){let p=await e.text();const b=[],S=/url\((['"]?)(https?:\/\/[^'")\s]+\?[^'")\s]*file=([^&'")\s]+\.(?:woff2?|ttf|otf|eot|svg))[^'")\s]*)\1\)/gi;p=p.replace(S,(_,P,W,U)=>(b.push({filename:U,originalUrl:W}),console.log(`[Cache] Rewrote font URL in CSS: ${U}`),`url(${P}${k}/cache/static/${encodeURIComponent(U)}${P})`)),await y.put(o,new Response(p,{headers:{"Content-Type":"text/css"}})),console.log(`[Cache] Cached CSS with ${b.length} rewritten font URLs: ${d}`),await Promise.all(b.map(async({filename:_,originalUrl:P})=>{const W=`${k}/cache/static/${encodeURIComponent(_)}`;if(!await y.match(W))try{const D=await fetch(P);if(!D.ok){console.warn(`[Cache] Failed to fetch font: ${_} (HTTP ${D.status})`);return}const F=await D.blob(),j=_.split(".").pop().toLowerCase(),M={otf:"font/otf",ttf:"font/ttf",woff:"font/woff",woff2:"font/woff2",eot:"application/vnd.ms-fontobject",svg:"image/svg+xml"}[j]||"application/octet-stream";await y.put(W,new Response(F,{headers:{"Content-Type":M}})),console.log(`[Cache] Cached font: ${_} (${M}, ${F.size} bytes)`)}catch(D){console.warn(`[Cache] Failed to cache font: ${_}`,D)}}))}else{const p=await e.blob();await y.put(o,new Response(p,{headers:{"Content-Type":r}})),console.log(`[Cache] Cached static resource: ${d} (${r}, ${p.size} bytes)`)}}catch(e){console.warn(`[Cache] Failed to cache static resource: ${d}`,e)}}))}return h}addDependant(a,s){const c=String(a);this.dependants.has(c)||this.dependants.set(c,new Set),this.dependants.get(c).add(String(s))}removeLayoutDependants(a){const s=String(a),c=[];for(const[l,h]of this.dependants)h.delete(s),h.size===0&&(this.dependants.delete(l),c.push(l));return c.length>0&&console.log(`[Cache] ${c.length} media files orphaned after layout ${a} removed:`,c),c}isMediaReferenced(a){const s=this.dependants.get(String(a));return s?s.size>0:!1}async downloadLargeFileInBackground(a,s,c,l,h,u,w,g){var m;let C=0;console.log(`[Cache] Background download started: ${l}`),this.notifyDownloadProgress(l,0,c);try{const v=[];for(let r=0;r<c;r+=52428800){const p=Math.min(r+52428800-1,c-1);v.push({start:r,end:p,index:v.length})}console.log(`[Cache] Downloading ${v.length} chunks in parallel (${z} concurrent)`);const R=new Map;let A=0;const y=async r=>{const p=`bytes=${r.start}-${r.end}`;try{const b=await fetch(a,{headers:{Range:p}});if(!b.ok&&b.status!==206)throw new Error(`Chunk ${r.index} failed: ${b.status}`);const S=await b.blob();R.set(r.index,S),C+=S.size;const _=(C/c*100).toFixed(1);return console.log(`[Cache] Chunk ${r.index}/${v.length-1} complete (${_}%)`),this.notifyDownloadProgress(l,C,c),S}catch(b){throw console.error(`[Cache] Chunk ${r.index} failed:`,b),b}},d=async()=>{for(;A<v.length;){const r=v[A++];await y(r)}},i=[];for(let r=0;r<z;r++)i.push(d());await Promise.all(i);const o=[];for(let r=0;r<v.length;r++)o.push(R.get(r));const t=new Blob(o),e=((m=o[0])==null?void 0:m.type)||"video/mp4";await this.cache.put(s,new Response(t,{headers:{"Content-Type":e,"Content-Length":t.size,"Accept-Ranges":"bytes"}}));const n={id:h,type:u,path:w,md5:g||"background",size:t.size,cachedAt:Date.now(),isBackgroundDownload:!1,cached:!0};await this.saveFile(n),this.notifyDownloadProgress(l,C,c,!0),console.log(`[Cache] Background download complete: ${l} (${t.size} bytes in ${o.length} chunks)`),window.dispatchEvent(new CustomEvent("media-cached",{detail:{filename:l,id:h,type:u,size:t.size}}))}catch(v){console.error(`[Cache] Background download failed for ${l}:`,v),this.notifyDownloadProgress(l,C,c,!1,!0)}}notifyDownloadProgress(a,s,c,l=!1,h=!1){const u=new CustomEvent("download-progress",{detail:{filename:a,loaded:s,total:c,percent:c>0?s/c*100:0,complete:l,error:h}});window.dispatchEvent(u)}async clearAll(){return await caches.delete(B),this.cache=await caches.open(B),new Promise((a,s)=>{const h=this.db.transaction(x,"readwrite").objectStore(x).clear();h.onsuccess=()=>a(),h.onerror=()=>s(h.error)})}}const he=new ie,f=O("CacheProxy"),T=typeof window<"u"&&window.location.pathname.replace(/\/[^/]*$/,"").replace(/\/$/,"")||"/player/pwa";class I extends L{constructor(){super(),this.controller=null,this.fetchReady=!1,this.fetchReadyPromise=null,this.fetchReadyResolve=null}async init(){if(this.fetchReadyPromise=new Promise(a=>{this.fetchReadyResolve=a}),navigator.serviceWorker.addEventListener("message",a=>{var s;((s=a.data)==null?void 0:s.type)==="SW_READY"&&(f.info("Received SW_READY signal - fetch handler is ready"),this.fetchReady=!0,this.fetchReadyResolve())}),"serviceWorker"in navigator){const a=await navigator.serviceWorker.getRegistration();if(a&&a.active&&a.active.state==="activated"){f.info("Using active Service Worker (controller not required)"),this.controller=navigator.serviceWorker.controller||a.active,this.controller.postMessage({type:"PING"}),f.info("Service Worker backend initialized, waiting for fetch readiness...");return}if(await navigator.serviceWorker.ready,this.controller=navigator.serviceWorker.controller,!this.controller)throw new Error("Service Worker not controlling page");this.controller.postMessage({type:"PING"}),f.info("Service Worker backend initialized, waiting for fetch readiness...")}else throw new Error("Service Worker not supported")}async getFile(a,s){this.fetchReady||(f.debug(`Waiting for SW fetch handler to be ready before fetching ${a}/${s}...`),await this.fetchReadyPromise,f.debug("SW fetch handler ready, proceeding with fetch"));const c=`${T}/cache/${a}/${s}`;f.debug(`getFile(${a}, ${s}) → fetching ${c}`),f.debug("About to call fetch()...");try{f.debug(`Calling fetch(${c})...`);const l=await fetch(c);if(f.debug("fetch returned, status:",l.status,l.statusText),!l.ok){if(f.debug(`Response not OK (${l.status}), returning null`),l.status===404)return null;throw new Error(`Failed to get file: ${l.status}`)}f.debug("Response OK, getting blob...");const h=await l.blob();return f.debug("Got blob, size:",h.size),h}catch(l){return f.error("getFile EXCEPTION:",l),f.error("Error name:",l.name),f.error("Error message:",l.message),null}}async hasFile(a,s){this.fetchReady||await this.fetchReadyPromise;const c=`${T}/cache/${a}/${s}`;try{return(await fetch(c,{method:"HEAD"})).ok}catch{return!1}}async requestDownload(a){if(!this.controller)throw new Error("Service Worker not available");return new Promise((s,c)=>{const l=new MessageChannel;l.port1.onmessage=h=>{const{success:u,error:w,enqueuedCount:g,activeCount:$,queuedCount:C}=h.data;u?(f.info("Download request acknowledged:",g,"files"),f.info("Queue state:",$,"active,",C,"queued"),s()):c(new Error(w||"Service Worker download failed"))},this.controller.postMessage({type:"DOWNLOAD_FILES",data:{files:a}},[l.port2])})}async prioritizeDownload(a,s){if(this.controller)return new Promise(c=>{const l=new MessageChannel;l.port1.onmessage=h=>c(h.data),this.controller.postMessage({type:"PRIORITIZE_DOWNLOAD",data:{fileType:a,fileId:s}},[l.port2])})}async isCached(a,s){const c=`${T}/cache/${a}/${s}`;try{return(await fetch(c,{method:"HEAD"})).ok}catch{return!1}}}class de extends L{constructor(){super(),this.backend=null,this.backendType="service-worker"}async init(){var l,h;if(!("serviceWorker"in navigator))throw new Error("Service Worker not supported - PWA requires Service Worker");f.debug("Checking Service Worker state..."),f.debug("controller =",navigator.serviceWorker.controller);const a=await navigator.serviceWorker.getRegistration();if(f.debug("registration =",a),f.debug("active =",a==null?void 0:a.active),f.debug("installing =",a==null?void 0:a.installing),f.debug("waiting =",a==null?void 0:a.waiting),a&&a.active&&!a.installing&&!a.waiting){f.info("Active Service Worker found (no updates pending)"),f.debug("SW state =",a.active.state),navigator.serviceWorker.controller||(f.debug("Not controlling yet, waiting 200ms for claim..."),await new Promise(u=>setTimeout(u,200)),f.debug("After wait, controller =",navigator.serviceWorker.controller)),this.backend=new I,await this.backend.init(),f.info("Service Worker backend ready (fast path)");return}a&&(a.installing||a.waiting)&&(f.info("New Service Worker detected, waiting for it to activate..."),f.debug("installing =",(l=a.installing)==null?void 0:l.state),f.debug("waiting =",(h=a.waiting)==null?void 0:h.state)),f.info("No active Service Worker, waiting for registration...");const s=navigator.serviceWorker.ready,c=new Promise((u,w)=>setTimeout(()=>w(new Error("Service Worker ready timeout after 10s")),1e4));try{await Promise.race([s,c]),f.debug("Service Worker ready promise resolved")}catch(u){throw f.error("Service Worker wait failed:",u),new Error("Service Worker not ready - please reload page")}await new Promise(u=>setTimeout(u,100)),f.debug("After claim wait, controller =",navigator.serviceWorker.controller),this.backend=new I,await this.backend.init(),f.info("Service Worker backend ready (slow path)")}async getFile(a,s){if(!this.backend)throw new Error("CacheProxy not initialized");return await this.backend.getFile(a,s)}async hasFile(a,s){if(!this.backend)throw new Error("CacheProxy not initialized");return await this.backend.hasFile(a,s)}async requestDownload(a){if(!this.backend)throw new Error("CacheProxy not initialized");return await this.backend.requestDownload(a)}async prioritizeDownload(a,s){var c;if((c=this.backend)!=null&&c.prioritizeDownload)return await this.backend.prioritizeDownload(a,s)}async isCached(a,s){if(!this.backend)throw new Error("CacheProxy not initialized");return await this.backend.isCached(a,s)}getBackendType(){return this.backendType}isUsingServiceWorker(){return this.backendType==="service-worker"}async deleteFiles(a){if(!this.backend)throw new Error("CacheProxy not initialized");return new Promise((s,c)=>{const l=new MessageChannel;l.port1.onmessage=h=>{const{success:u,error:w,deleted:g,total:$}=h.data;u?s({deleted:g,total:$}):c(new Error(w||"Delete failed"))},navigator.serviceWorker.controller.postMessage({type:"DELETE_FILES",data:{files:a}},[l.port2]),setTimeout(()=>s({deleted:0,total:a.length}),5e3)})}async prewarmVideoChunks(a){var c;if(!a||a.length===0)return{warmed:0,total:0};const s=(c=navigator.serviceWorker)==null?void 0:c.controller;return s?new Promise(l=>{const h=new MessageChannel;h.port1.onmessage=u=>{const{success:w,warmed:g,total:$}=u.data;l(w?{warmed:g,total:$}:{warmed:0,total:a.length})},s.postMessage({type:"PREWARM_VIDEO_CHUNKS",data:{mediaIds:a}},[h.port2]),setTimeout(()=>l({warmed:0,total:a.length}),2e3)}):{warmed:0,total:a.length}}async getDownloadProgress(){if(!this.backend)throw new Error("CacheProxy not initialized");return new Promise(a=>{const s=new MessageChannel;s.port1.onmessage=c=>{const{success:l,progress:h}=c.data;a(l?h:{})},navigator.serviceWorker.controller.postMessage({type:"GET_DOWNLOAD_PROGRESS"},[s.port2]),setTimeout(()=>a({}),1e3)})}}export{de as C,L as E,ie as a,he as c,le as i};
|
|
2
|
-
//# sourceMappingURL=cache-proxy-
|
|
1
|
+
import{a as O,c as H,C as K,d as q,L as G,b as Z,f as V,g as Y,i as Q,m as X,r as J,s as ee,u as te}from"./cms-api-kzy_Sw-u.js";class B{constructor(){this.events=new Map}on(a,s){this.events.has(a)||this.events.set(a,[]),this.events.get(a).push(s)}once(a,s){const c=(...l)=>{s(...l),this.off(a,c)};this.on(a,c)}off(a,s){if(!this.events.has(a))return;const c=this.events.get(a),l=c.indexOf(s);l!==-1&&c.splice(l,1)}emit(a,...s){if(!this.events.has(a))return;const c=this.events.get(a).slice();for(const l of c)l(...s)}removeAllListeners(a){a?this.events.delete(a):this.events.clear()}}const le=Object.freeze(Object.defineProperty({__proto__:null,CmsApiClient:K,CmsApiError:q,EventEmitter:B,LOG_LEVELS:G,applyCmsLogLevel:Z,config:O,createLogger:H,fetchWithRetry:V,getLogLevel:Y,isDebug:Q,mapCmsLogLevel:X,registerLogSink:J,setLogLevel:ee,unregisterLogSink:te},Symbol.toStringTag,{value:"Module"}));function re(E){return E&&E.__esModule&&Object.prototype.hasOwnProperty.call(E,"default")?E.default:E}var N={exports:{}};(function(E,a){(function(s){E.exports=s()})(function(s){var c=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];function l(i,o){var t=i[0],e=i[1],n=i[2],r=i[3];t+=(e&n|~e&r)+o[0]-680876936|0,t=(t<<7|t>>>25)+e|0,r+=(t&e|~t&n)+o[1]-389564586|0,r=(r<<12|r>>>20)+t|0,n+=(r&t|~r&e)+o[2]+606105819|0,n=(n<<17|n>>>15)+r|0,e+=(n&r|~n&t)+o[3]-1044525330|0,e=(e<<22|e>>>10)+n|0,t+=(e&n|~e&r)+o[4]-176418897|0,t=(t<<7|t>>>25)+e|0,r+=(t&e|~t&n)+o[5]+1200080426|0,r=(r<<12|r>>>20)+t|0,n+=(r&t|~r&e)+o[6]-1473231341|0,n=(n<<17|n>>>15)+r|0,e+=(n&r|~n&t)+o[7]-45705983|0,e=(e<<22|e>>>10)+n|0,t+=(e&n|~e&r)+o[8]+1770035416|0,t=(t<<7|t>>>25)+e|0,r+=(t&e|~t&n)+o[9]-1958414417|0,r=(r<<12|r>>>20)+t|0,n+=(r&t|~r&e)+o[10]-42063|0,n=(n<<17|n>>>15)+r|0,e+=(n&r|~n&t)+o[11]-1990404162|0,e=(e<<22|e>>>10)+n|0,t+=(e&n|~e&r)+o[12]+1804603682|0,t=(t<<7|t>>>25)+e|0,r+=(t&e|~t&n)+o[13]-40341101|0,r=(r<<12|r>>>20)+t|0,n+=(r&t|~r&e)+o[14]-1502002290|0,n=(n<<17|n>>>15)+r|0,e+=(n&r|~n&t)+o[15]+1236535329|0,e=(e<<22|e>>>10)+n|0,t+=(e&r|n&~r)+o[1]-165796510|0,t=(t<<5|t>>>27)+e|0,r+=(t&n|e&~n)+o[6]-1069501632|0,r=(r<<9|r>>>23)+t|0,n+=(r&e|t&~e)+o[11]+643717713|0,n=(n<<14|n>>>18)+r|0,e+=(n&t|r&~t)+o[0]-373897302|0,e=(e<<20|e>>>12)+n|0,t+=(e&r|n&~r)+o[5]-701558691|0,t=(t<<5|t>>>27)+e|0,r+=(t&n|e&~n)+o[10]+38016083|0,r=(r<<9|r>>>23)+t|0,n+=(r&e|t&~e)+o[15]-660478335|0,n=(n<<14|n>>>18)+r|0,e+=(n&t|r&~t)+o[4]-405537848|0,e=(e<<20|e>>>12)+n|0,t+=(e&r|n&~r)+o[9]+568446438|0,t=(t<<5|t>>>27)+e|0,r+=(t&n|e&~n)+o[14]-1019803690|0,r=(r<<9|r>>>23)+t|0,n+=(r&e|t&~e)+o[3]-187363961|0,n=(n<<14|n>>>18)+r|0,e+=(n&t|r&~t)+o[8]+1163531501|0,e=(e<<20|e>>>12)+n|0,t+=(e&r|n&~r)+o[13]-1444681467|0,t=(t<<5|t>>>27)+e|0,r+=(t&n|e&~n)+o[2]-51403784|0,r=(r<<9|r>>>23)+t|0,n+=(r&e|t&~e)+o[7]+1735328473|0,n=(n<<14|n>>>18)+r|0,e+=(n&t|r&~t)+o[12]-1926607734|0,e=(e<<20|e>>>12)+n|0,t+=(e^n^r)+o[5]-378558|0,t=(t<<4|t>>>28)+e|0,r+=(t^e^n)+o[8]-2022574463|0,r=(r<<11|r>>>21)+t|0,n+=(r^t^e)+o[11]+1839030562|0,n=(n<<16|n>>>16)+r|0,e+=(n^r^t)+o[14]-35309556|0,e=(e<<23|e>>>9)+n|0,t+=(e^n^r)+o[1]-1530992060|0,t=(t<<4|t>>>28)+e|0,r+=(t^e^n)+o[4]+1272893353|0,r=(r<<11|r>>>21)+t|0,n+=(r^t^e)+o[7]-155497632|0,n=(n<<16|n>>>16)+r|0,e+=(n^r^t)+o[10]-1094730640|0,e=(e<<23|e>>>9)+n|0,t+=(e^n^r)+o[13]+681279174|0,t=(t<<4|t>>>28)+e|0,r+=(t^e^n)+o[0]-358537222|0,r=(r<<11|r>>>21)+t|0,n+=(r^t^e)+o[3]-722521979|0,n=(n<<16|n>>>16)+r|0,e+=(n^r^t)+o[6]+76029189|0,e=(e<<23|e>>>9)+n|0,t+=(e^n^r)+o[9]-640364487|0,t=(t<<4|t>>>28)+e|0,r+=(t^e^n)+o[12]-421815835|0,r=(r<<11|r>>>21)+t|0,n+=(r^t^e)+o[15]+530742520|0,n=(n<<16|n>>>16)+r|0,e+=(n^r^t)+o[2]-995338651|0,e=(e<<23|e>>>9)+n|0,t+=(n^(e|~r))+o[0]-198630844|0,t=(t<<6|t>>>26)+e|0,r+=(e^(t|~n))+o[7]+1126891415|0,r=(r<<10|r>>>22)+t|0,n+=(t^(r|~e))+o[14]-1416354905|0,n=(n<<15|n>>>17)+r|0,e+=(r^(n|~t))+o[5]-57434055|0,e=(e<<21|e>>>11)+n|0,t+=(n^(e|~r))+o[12]+1700485571|0,t=(t<<6|t>>>26)+e|0,r+=(e^(t|~n))+o[3]-1894986606|0,r=(r<<10|r>>>22)+t|0,n+=(t^(r|~e))+o[10]-1051523|0,n=(n<<15|n>>>17)+r|0,e+=(r^(n|~t))+o[1]-2054922799|0,e=(e<<21|e>>>11)+n|0,t+=(n^(e|~r))+o[8]+1873313359|0,t=(t<<6|t>>>26)+e|0,r+=(e^(t|~n))+o[15]-30611744|0,r=(r<<10|r>>>22)+t|0,n+=(t^(r|~e))+o[6]-1560198380|0,n=(n<<15|n>>>17)+r|0,e+=(r^(n|~t))+o[13]+1309151649|0,e=(e<<21|e>>>11)+n|0,t+=(n^(e|~r))+o[4]-145523070|0,t=(t<<6|t>>>26)+e|0,r+=(e^(t|~n))+o[11]-1120210379|0,r=(r<<10|r>>>22)+t|0,n+=(t^(r|~e))+o[2]+718787259|0,n=(n<<15|n>>>17)+r|0,e+=(r^(n|~t))+o[9]-343485551|0,e=(e<<21|e>>>11)+n|0,i[0]=t+i[0]|0,i[1]=e+i[1]|0,i[2]=n+i[2]|0,i[3]=r+i[3]|0}function h(i){var o=[],t;for(t=0;t<64;t+=4)o[t>>2]=i.charCodeAt(t)+(i.charCodeAt(t+1)<<8)+(i.charCodeAt(t+2)<<16)+(i.charCodeAt(t+3)<<24);return o}function u(i){var o=[],t;for(t=0;t<64;t+=4)o[t>>2]=i[t]+(i[t+1]<<8)+(i[t+2]<<16)+(i[t+3]<<24);return o}function w(i){var o=i.length,t=[1732584193,-271733879,-1732584194,271733878],e,n,r,p,b,S;for(e=64;e<=o;e+=64)l(t,h(i.substring(e-64,e)));for(i=i.substring(e-64),n=i.length,r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],e=0;e<n;e+=1)r[e>>2]|=i.charCodeAt(e)<<(e%4<<3);if(r[e>>2]|=128<<(e%4<<3),e>55)for(l(t,r),e=0;e<16;e+=1)r[e]=0;return p=o*8,p=p.toString(16).match(/(.*?)(.{0,8})$/),b=parseInt(p[2],16),S=parseInt(p[1],16)||0,r[14]=b,r[15]=S,l(t,r),t}function g(i){var o=i.length,t=[1732584193,-271733879,-1732584194,271733878],e,n,r,p,b,S;for(e=64;e<=o;e+=64)l(t,u(i.subarray(e-64,e)));for(i=e-64<o?i.subarray(e-64):new Uint8Array(0),n=i.length,r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],e=0;e<n;e+=1)r[e>>2]|=i[e]<<(e%4<<3);if(r[e>>2]|=128<<(e%4<<3),e>55)for(l(t,r),e=0;e<16;e+=1)r[e]=0;return p=o*8,p=p.toString(16).match(/(.*?)(.{0,8})$/),b=parseInt(p[2],16),S=parseInt(p[1],16)||0,r[14]=b,r[15]=S,l(t,r),t}function $(i){var o="",t;for(t=0;t<4;t+=1)o+=c[i>>t*8+4&15]+c[i>>t*8&15];return o}function C(i){var o;for(o=0;o<i.length;o+=1)i[o]=$(i[o]);return i.join("")}C(w("hello")),typeof ArrayBuffer<"u"&&!ArrayBuffer.prototype.slice&&function(){function i(o,t){return o=o|0||0,o<0?Math.max(o+t,0):Math.min(o,t)}ArrayBuffer.prototype.slice=function(o,t){var e=this.byteLength,n=i(o,e),r=e,p,b,S,_;return t!==s&&(r=i(t,e)),n>r?new ArrayBuffer(0):(p=r-n,b=new ArrayBuffer(p),S=new Uint8Array(b),_=new Uint8Array(this,n,p),S.set(_),b)}}();function m(i){return/[\u0080-\uFFFF]/.test(i)&&(i=unescape(encodeURIComponent(i))),i}function v(i,o){var t=i.length,e=new ArrayBuffer(t),n=new Uint8Array(e),r;for(r=0;r<t;r+=1)n[r]=i.charCodeAt(r);return o?n:e}function R(i){return String.fromCharCode.apply(null,new Uint8Array(i))}function A(i,o,t){var e=new Uint8Array(i.byteLength+o.byteLength);return e.set(new Uint8Array(i)),e.set(new Uint8Array(o),i.byteLength),e}function y(i){var o=[],t=i.length,e;for(e=0;e<t-1;e+=2)o.push(parseInt(i.substr(e,2),16));return String.fromCharCode.apply(String,o)}function d(){this.reset()}return d.prototype.append=function(i){return this.appendBinary(m(i)),this},d.prototype.appendBinary=function(i){this._buff+=i,this._length+=i.length;var o=this._buff.length,t;for(t=64;t<=o;t+=64)l(this._hash,h(this._buff.substring(t-64,t)));return this._buff=this._buff.substring(t-64),this},d.prototype.end=function(i){var o=this._buff,t=o.length,e,n=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],r;for(e=0;e<t;e+=1)n[e>>2]|=o.charCodeAt(e)<<(e%4<<3);return this._finish(n,t),r=C(this._hash),i&&(r=y(r)),this.reset(),r},d.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},d.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash.slice()}},d.prototype.setState=function(i){return this._buff=i.buff,this._length=i.length,this._hash=i.hash,this},d.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},d.prototype._finish=function(i,o){var t=o,e,n,r;if(i[t>>2]|=128<<(t%4<<3),t>55)for(l(this._hash,i),t=0;t<16;t+=1)i[t]=0;e=this._length*8,e=e.toString(16).match(/(.*?)(.{0,8})$/),n=parseInt(e[2],16),r=parseInt(e[1],16)||0,i[14]=n,i[15]=r,l(this._hash,i)},d.hash=function(i,o){return d.hashBinary(m(i),o)},d.hashBinary=function(i,o){var t=w(i),e=C(t);return o?y(e):e},d.ArrayBuffer=function(){this.reset()},d.ArrayBuffer.prototype.append=function(i){var o=A(this._buff.buffer,i),t=o.length,e;for(this._length+=i.byteLength,e=64;e<=t;e+=64)l(this._hash,u(o.subarray(e-64,e)));return this._buff=e-64<t?new Uint8Array(o.buffer.slice(e-64)):new Uint8Array(0),this},d.ArrayBuffer.prototype.end=function(i){var o=this._buff,t=o.length,e=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],n,r;for(n=0;n<t;n+=1)e[n>>2]|=o[n]<<(n%4<<3);return this._finish(e,t),r=C(this._hash),i&&(r=y(r)),this.reset(),r},d.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},d.ArrayBuffer.prototype.getState=function(){var i=d.prototype.getState.call(this);return i.buff=R(i.buff),i},d.ArrayBuffer.prototype.setState=function(i){return i.buff=v(i.buff,!0),d.prototype.setState.call(this,i)},d.ArrayBuffer.prototype.destroy=d.prototype.destroy,d.ArrayBuffer.prototype._finish=d.prototype._finish,d.ArrayBuffer.hash=function(i,o){var t=g(new Uint8Array(i)),e=C(t);return o?y(e):e},d})})(N);var ne=N.exports;const oe=re(ne),U="xibo-media-v1",ae="xibo-player",se=1,k="files",z=4,x=typeof window<"u"&&window.location.pathname.replace(/\/[^/]*$/,"").replace(/\/$/,"")||"/player/pwa";class ie{constructor(){this.cache=null,this.db=null,this.dependants=new Map}extractFilename(a){try{return new URL(a).searchParams.get("file")||"unknown"}catch{return"unknown"}}rewriteUrl(a){if(!a)return a;try{const s=new URL(a),c=new URL(O.cmsAddress);if(s.origin!==c.origin)return console.log(`[Cache] Rewriting URL: ${s.origin} → ${c.origin}`),s.protocol=c.protocol,s.hostname=c.hostname,s.port=c.port,s.toString()}catch{}return a}async init(){this.cache=await caches.open(U),this.db=await this.openDB()}openDB(){return new Promise((a,s)=>{const c=indexedDB.open(ae,se);c.onerror=()=>s(c.error),c.onsuccess=()=>a(c.result),c.onupgradeneeded=l=>{const h=l.target.result;h.objectStoreNames.contains(k)||h.createObjectStore(k,{keyPath:"id"}).createIndex("type","type",{unique:!1})}})}async getFile(a){return new Promise((s,c)=>{const u=this.db.transaction(k,"readonly").objectStore(k).get(a);u.onsuccess=()=>s(u.result),u.onerror=()=>c(u.error)})}async saveFile(a){return new Promise((s,c)=>{const u=this.db.transaction(k,"readwrite").objectStore(k).put(a);u.onsuccess=()=>s(),u.onerror=()=>c(u.error)})}async getAllFiles(){return new Promise((a,s)=>{const h=this.db.transaction(k,"readonly").objectStore(k).getAll();h.onsuccess=()=>a(h.result),h.onerror=()=>s(h.error)})}async downloadFile(a){var i;const{id:s,type:c,path:l,md5:h,download:u}=a;if(typeof navigator<"u"&&((i=navigator.serviceWorker)!=null&&i.controller))return console.log(`[Cache] Service Worker active - skipping direct download for ${c}/${s}`),console.log("[Cache] File will be downloaded by Service Worker in background"),{id:s,type:c,path:l,md5:h||"pending",size:0,cachedAt:Date.now(),isServiceWorkerDownload:!0};if(!l||l==="null"||l==="undefined")return console.log(`[Cache] Skipping ${c}/${s} - no download URL (will be generated on-demand)`),null;const w=await this.getFile(s),g=this.getCacheKey(c,s);if(w)if(w.md5===h){const o=await this.cache.match(g);if(o&&c==="media"){const t=await o.blob(),e=o.headers.get("Content-Type");if(e==="text/plain"||t.size<100)console.warn(`[Cache] Bad cache detected for ${c}/${s} (${e}, ${t.size} bytes) - re-downloading`),await this.cache.delete(g);else return console.log(`[Cache] ${c}/${s} already cached`),w}else return console.log(`[Cache] ${c}/${s} already cached`),w}else console.warn(`[Cache] ${c}/${s} MD5 changed (cached: ${w.md5}, expected: ${h}) - re-downloading`),await this.cache.delete(g);console.log(`[Cache] Downloading ${c}/${s} from ${l}`);const $=this.rewriteUrl(l);console.log(`[Cache] Using URL: ${$}`);const C=await fetch($,{method:"HEAD"});if(C.status===202)return console.warn(`[Cache] ${c}/${s} still downloading in background (HTTP 202) - will retry on next collection`),{id:s,type:c,path:l,md5:h||"pending",size:0,cachedAt:Date.now(),isPending:!0};const m=parseInt(C.headers.get("Content-Length")||"0"),v=m>100*1024*1024;console.log(`[Cache] File size: ${(m/1024/1024).toFixed(1)} MB ${v?"(large file)":""}`);const R=c==="media"?this.extractFilename(l):s;let A,y;if(v){console.log(`[Cache] Large file detected (${(m/1024/1024).toFixed(1)} MB), caching in background`),this.downloadLargeFileInBackground($,g,m,R,s,c,l,h).catch(t=>console.warn(`[Cache] Background download failed for ${s}:`,t));const o={id:s,type:c,path:l,md5:h||"pending",size:m,cachedAt:Date.now(),isBackgroundDownload:!0};return await this.saveFile(o),console.log(`[Cache] ${c}/${s} downloading in background (${m} bytes)`),o}else{this.notifyDownloadProgress(R,0,m);const o=await fetch($);if(o.status===202)return console.warn(`[Cache] ${c}/${s} still downloading in background (HTTP 202) - will retry on next collection`),{id:s,type:c,path:l,md5:h||"pending",size:0,cachedAt:Date.now(),isPending:!0};if(!o.ok)throw new Error(`Failed to download ${l}: ${o.status}`);const t=await o.blob(),e=await t.arrayBuffer();A=oe.ArrayBuffer.hash(e),h&&A!==h&&(console.warn(`[Cache] MD5 mismatch for ${c}/${s}:`),console.warn(`[Cache] Expected: ${h}`),console.warn(`[Cache] Got: ${A}`),console.warn("[Cache] Accepting file anyway (kiosk mode - renderer will validate)"),A=h),await this.cache.put(g,new Response(t,{headers:{"Content-Type":o.headers.get("Content-Type")||"application/octet-stream","Content-Length":t.size}})),y=t.size,this.notifyDownloadProgress(R,y,m,!0),console.log(`[Cache] Cached ${c}/${s} (${y} bytes, MD5: ${A})`)}const d={id:s,type:c,path:l,md5:A,size:y,cachedAt:Date.now()};return await this.saveFile(d),d}getCacheKey(a,s,c=null){return`${x}/cache/${a}/${c||s}`}async getCachedFile(a,s){const c=this.getCacheKey(a,s),l=await this.cache.match(c);return l?await l.blob():null}async getCachedResponse(a,s){const c=this.getCacheKey(a,s);return await this.cache.match(c)}async getCachedFileText(a,s){const c=this.getCacheKey(a,s),l=await this.cache.match(c);return l?await l.text():null}async cacheWidgetHtml(a,s,c,l){const h=`${x}/cache/widget/${a}/${s}/${c}`,u=await caches.open(U),w='<base href="/player/cache/media/">';let g=l;l.includes("<head>")?g=l.replace("<head>","<head>"+w):l.includes("<HEAD>")?g=l.replace("<HEAD>","<HEAD>"+w):g=w+l;const $=/https?:\/\/[^"'\s)]+xmds\.php\?[^"'\s)]*file=([^&"'\s)]+)[^"'\s)]*/g,C=[];g=g.replace($,(A,y)=>{const d=`${x}/cache/static/${y}`;return C.push({filename:y,originalUrl:A}),console.log(`[Cache] Rewrote widget URL: ${y} → ${d}`),d});const m="<style>img,video{object-position:center center}</style>";g.includes("</head>")?g=g.replace("</head>",m+"</head>"):g.includes("</HEAD>")&&(g=g.replace("</HEAD>",m+"</HEAD>")),g=g.replace(/hostAddress\s*:\s*["']https?:\/\/[^"']+["']/g,`hostAddress: "${x}/ic"`),console.log("[Cache] Injected base tag and rewrote CMS URLs in widget HTML");const v=new URL(h,window.location.origin),R=new Response(g,{headers:{"Content-Type":"text/html; charset=utf-8","Access-Control-Allow-Origin":"*"}});if(await u.put(v,R),console.log(`[Cache] Stored widget HTML at ${h} (${g.length} bytes)`),C.length>0){const y=await caches.open("xibo-static-v1");await Promise.all(C.map(async({filename:d,originalUrl:i})=>{const o=`${x}/cache/static/${d}`;if(!await y.match(o))try{const e=await fetch(i);if(!e.ok){console.warn(`[Cache] Failed to fetch static resource: ${d} (HTTP ${e.status})`);return}const n=d.split(".").pop().toLowerCase(),r={js:"application/javascript",css:"text/css",otf:"font/otf",ttf:"font/ttf",woff:"font/woff",woff2:"font/woff2",eot:"application/vnd.ms-fontobject",svg:"image/svg+xml"}[n]||"application/octet-stream";if(n==="css"){let p=await e.text();const b=[],S=/url\((['"]?)(https?:\/\/[^'")\s]+\?[^'")\s]*file=([^&'")\s]+\.(?:woff2?|ttf|otf|eot|svg))[^'")\s]*)\1\)/gi;p=p.replace(S,(_,P,W,L)=>(b.push({filename:L,originalUrl:W}),console.log(`[Cache] Rewrote font URL in CSS: ${L}`),`url(${P}${x}/cache/static/${encodeURIComponent(L)}${P})`)),await y.put(o,new Response(p,{headers:{"Content-Type":"text/css"}})),console.log(`[Cache] Cached CSS with ${b.length} rewritten font URLs: ${d}`),await Promise.all(b.map(async({filename:_,originalUrl:P})=>{const W=`${x}/cache/static/${encodeURIComponent(_)}`;if(!await y.match(W))try{const D=await fetch(P);if(!D.ok){console.warn(`[Cache] Failed to fetch font: ${_} (HTTP ${D.status})`);return}const F=await D.blob(),j=_.split(".").pop().toLowerCase(),M={otf:"font/otf",ttf:"font/ttf",woff:"font/woff",woff2:"font/woff2",eot:"application/vnd.ms-fontobject",svg:"image/svg+xml"}[j]||"application/octet-stream";await y.put(W,new Response(F,{headers:{"Content-Type":M}})),console.log(`[Cache] Cached font: ${_} (${M}, ${F.size} bytes)`)}catch(D){console.warn(`[Cache] Failed to cache font: ${_}`,D)}}))}else{const p=await e.blob();await y.put(o,new Response(p,{headers:{"Content-Type":r}})),console.log(`[Cache] Cached static resource: ${d} (${r}, ${p.size} bytes)`)}}catch(e){console.warn(`[Cache] Failed to cache static resource: ${d}`,e)}}))}return h}addDependant(a,s){const c=String(a);this.dependants.has(c)||this.dependants.set(c,new Set),this.dependants.get(c).add(String(s))}removeLayoutDependants(a){const s=String(a),c=[];for(const[l,h]of this.dependants)h.delete(s),h.size===0&&(this.dependants.delete(l),c.push(l));return c.length>0&&console.log(`[Cache] ${c.length} media files orphaned after layout ${a} removed:`,c),c}isMediaReferenced(a){const s=this.dependants.get(String(a));return s?s.size>0:!1}async downloadLargeFileInBackground(a,s,c,l,h,u,w,g){var m;let C=0;console.log(`[Cache] Background download started: ${l}`),this.notifyDownloadProgress(l,0,c);try{const v=[];for(let r=0;r<c;r+=52428800){const p=Math.min(r+52428800-1,c-1);v.push({start:r,end:p,index:v.length})}console.log(`[Cache] Downloading ${v.length} chunks in parallel (${z} concurrent)`);const R=new Map;let A=0;const y=async r=>{const p=`bytes=${r.start}-${r.end}`;try{const b=await fetch(a,{headers:{Range:p}});if(!b.ok&&b.status!==206)throw new Error(`Chunk ${r.index} failed: ${b.status}`);const S=await b.blob();R.set(r.index,S),C+=S.size;const _=(C/c*100).toFixed(1);return console.log(`[Cache] Chunk ${r.index}/${v.length-1} complete (${_}%)`),this.notifyDownloadProgress(l,C,c),S}catch(b){throw console.error(`[Cache] Chunk ${r.index} failed:`,b),b}},d=async()=>{for(;A<v.length;){const r=v[A++];await y(r)}},i=[];for(let r=0;r<z;r++)i.push(d());await Promise.all(i);const o=[];for(let r=0;r<v.length;r++)o.push(R.get(r));const t=new Blob(o),e=((m=o[0])==null?void 0:m.type)||"video/mp4";await this.cache.put(s,new Response(t,{headers:{"Content-Type":e,"Content-Length":t.size,"Accept-Ranges":"bytes"}}));const n={id:h,type:u,path:w,md5:g||"background",size:t.size,cachedAt:Date.now(),isBackgroundDownload:!1,cached:!0};await this.saveFile(n),this.notifyDownloadProgress(l,C,c,!0),console.log(`[Cache] Background download complete: ${l} (${t.size} bytes in ${o.length} chunks)`),window.dispatchEvent(new CustomEvent("media-cached",{detail:{filename:l,id:h,type:u,size:t.size}}))}catch(v){console.error(`[Cache] Background download failed for ${l}:`,v),this.notifyDownloadProgress(l,C,c,!1,!0)}}notifyDownloadProgress(a,s,c,l=!1,h=!1){const u=new CustomEvent("download-progress",{detail:{filename:a,loaded:s,total:c,percent:c>0?s/c*100:0,complete:l,error:h}});window.dispatchEvent(u)}async clearAll(){return await caches.delete(U),this.cache=await caches.open(U),new Promise((a,s)=>{const h=this.db.transaction(k,"readwrite").objectStore(k).clear();h.onsuccess=()=>a(),h.onerror=()=>s(h.error)})}}const he=new ie,f=H("CacheProxy"),T=typeof window<"u"&&window.location.pathname.replace(/\/[^/]*$/,"").replace(/\/$/,"")||"/player/pwa";class I extends B{constructor(){super(),this.controller=null,this.fetchReady=!1,this.fetchReadyPromise=null,this.fetchReadyResolve=null}async init(){if(this.fetchReadyPromise=new Promise(a=>{this.fetchReadyResolve=a}),navigator.serviceWorker.addEventListener("message",a=>{var s;((s=a.data)==null?void 0:s.type)==="SW_READY"&&(f.info("Received SW_READY signal - fetch handler is ready"),this.fetchReady=!0,this.fetchReadyResolve())}),"serviceWorker"in navigator){const a=await navigator.serviceWorker.getRegistration();if(a&&a.active&&a.active.state==="activated"){f.info("Using active Service Worker (controller not required)"),this.controller=navigator.serviceWorker.controller||a.active,this.controller.postMessage({type:"PING"}),f.info("Service Worker backend initialized, waiting for fetch readiness...");return}if(await navigator.serviceWorker.ready,this.controller=navigator.serviceWorker.controller,!this.controller)throw new Error("Service Worker not controlling page");this.controller.postMessage({type:"PING"}),f.info("Service Worker backend initialized, waiting for fetch readiness...")}else throw new Error("Service Worker not supported")}async getFile(a,s){this.fetchReady||(f.debug(`Waiting for SW fetch handler to be ready before fetching ${a}/${s}...`),await this.fetchReadyPromise,f.debug("SW fetch handler ready, proceeding with fetch"));const c=`${T}/cache/${a}/${s}`;f.debug(`getFile(${a}, ${s}) → fetching ${c}`),f.debug("About to call fetch()...");try{f.debug(`Calling fetch(${c})...`);const l=await fetch(c);if(f.debug("fetch returned, status:",l.status,l.statusText),!l.ok){if(f.debug(`Response not OK (${l.status}), returning null`),l.status===404)return null;throw new Error(`Failed to get file: ${l.status}`)}f.debug("Response OK, getting blob...");const h=await l.blob();return f.debug("Got blob, size:",h.size),h}catch(l){return f.error("getFile EXCEPTION:",l),f.error("Error name:",l.name),f.error("Error message:",l.message),null}}async hasFile(a,s){this.fetchReady||await this.fetchReadyPromise;const c=`${T}/cache/${a}/${s}`;try{return(await fetch(c,{method:"HEAD"})).ok}catch{return!1}}async requestDownload(a){if(!this.controller)throw new Error("Service Worker not available");return new Promise((s,c)=>{const l=new MessageChannel;l.port1.onmessage=h=>{const{success:u,error:w,enqueuedCount:g,activeCount:$,queuedCount:C}=h.data;u?(f.info("Download request acknowledged:",g,"files"),f.info("Queue state:",$,"active,",C,"queued"),s()):c(new Error(w||"Service Worker download failed"))},this.controller.postMessage({type:"DOWNLOAD_FILES",data:{files:a}},[l.port2])})}async prioritizeDownload(a,s){if(this.controller)return new Promise(c=>{const l=new MessageChannel;l.port1.onmessage=h=>c(h.data),this.controller.postMessage({type:"PRIORITIZE_DOWNLOAD",data:{fileType:a,fileId:s}},[l.port2])})}async isCached(a,s){const c=`${T}/cache/${a}/${s}`;try{return(await fetch(c,{method:"HEAD"})).ok}catch{return!1}}async prioritizeLayoutFiles(a){this.controller&&this.controller.postMessage({type:"PRIORITIZE_LAYOUT_FILES",data:{mediaIds:a}})}}class de extends B{constructor(){super(),this.backend=null,this.backendType="service-worker"}async init(){var l,h;if(!("serviceWorker"in navigator))throw new Error("Service Worker not supported - PWA requires Service Worker");f.debug("Checking Service Worker state..."),f.debug("controller =",navigator.serviceWorker.controller);const a=await navigator.serviceWorker.getRegistration();if(f.debug("registration =",a),f.debug("active =",a==null?void 0:a.active),f.debug("installing =",a==null?void 0:a.installing),f.debug("waiting =",a==null?void 0:a.waiting),a&&a.active&&!a.installing&&!a.waiting){f.info("Active Service Worker found (no updates pending)"),f.debug("SW state =",a.active.state),navigator.serviceWorker.controller||(f.debug("Not controlling yet, waiting 200ms for claim..."),await new Promise(u=>setTimeout(u,200)),f.debug("After wait, controller =",navigator.serviceWorker.controller)),this.backend=new I,await this.backend.init(),f.info("Service Worker backend ready (fast path)");return}a&&(a.installing||a.waiting)&&(f.info("New Service Worker detected, waiting for it to activate..."),f.debug("installing =",(l=a.installing)==null?void 0:l.state),f.debug("waiting =",(h=a.waiting)==null?void 0:h.state)),f.info("No active Service Worker, waiting for registration...");const s=navigator.serviceWorker.ready,c=new Promise((u,w)=>setTimeout(()=>w(new Error("Service Worker ready timeout after 10s")),1e4));try{await Promise.race([s,c]),f.debug("Service Worker ready promise resolved")}catch(u){throw f.error("Service Worker wait failed:",u),new Error("Service Worker not ready - please reload page")}await new Promise(u=>setTimeout(u,100)),f.debug("After claim wait, controller =",navigator.serviceWorker.controller),this.backend=new I,await this.backend.init(),f.info("Service Worker backend ready (slow path)")}async getFile(a,s){if(!this.backend)throw new Error("CacheProxy not initialized");return await this.backend.getFile(a,s)}async hasFile(a,s){if(!this.backend)throw new Error("CacheProxy not initialized");return await this.backend.hasFile(a,s)}async requestDownload(a){if(!this.backend)throw new Error("CacheProxy not initialized");return await this.backend.requestDownload(a)}async prioritizeDownload(a,s){var c;if((c=this.backend)!=null&&c.prioritizeDownload)return await this.backend.prioritizeDownload(a,s)}async isCached(a,s){if(!this.backend)throw new Error("CacheProxy not initialized");return await this.backend.isCached(a,s)}async prioritizeLayoutFiles(a){var s;if((s=this.backend)!=null&&s.prioritizeLayoutFiles)return await this.backend.prioritizeLayoutFiles(a)}getBackendType(){return this.backendType}isUsingServiceWorker(){return this.backendType==="service-worker"}async deleteFiles(a){if(!this.backend)throw new Error("CacheProxy not initialized");return new Promise((s,c)=>{const l=new MessageChannel;l.port1.onmessage=h=>{const{success:u,error:w,deleted:g,total:$}=h.data;u?s({deleted:g,total:$}):c(new Error(w||"Delete failed"))},navigator.serviceWorker.controller.postMessage({type:"DELETE_FILES",data:{files:a}},[l.port2]),setTimeout(()=>s({deleted:0,total:a.length}),5e3)})}async prewarmVideoChunks(a){var c;if(!a||a.length===0)return{warmed:0,total:0};const s=(c=navigator.serviceWorker)==null?void 0:c.controller;return s?new Promise(l=>{const h=new MessageChannel;h.port1.onmessage=u=>{const{success:w,warmed:g,total:$}=u.data;l(w?{warmed:g,total:$}:{warmed:0,total:a.length})},s.postMessage({type:"PREWARM_VIDEO_CHUNKS",data:{mediaIds:a}},[h.port2]),setTimeout(()=>l({warmed:0,total:a.length}),2e3)}):{warmed:0,total:a.length}}async getDownloadProgress(){if(!this.backend)throw new Error("CacheProxy not initialized");return new Promise(a=>{const s=new MessageChannel;s.port1.onmessage=c=>{const{success:l,progress:h}=c.data;a(l?h:{})},navigator.serviceWorker.controller.postMessage({type:"GET_DOWNLOAD_PROGRESS"},[s.port2]),setTimeout(()=>a({}),1e3)})}}export{de as C,B as E,ie as a,he as c,le as i};
|
|
2
|
+
//# sourceMappingURL=cache-proxy-D6-jdEoS.js.map
|