Repository navigation
Expand file tree
/
Copy pathbrowser.min.js
More file actions
4 lines (3 loc) · 2.5 KB
/
Copy pathbrowser.min.js
File metadata and controls
4 lines (3 loc) · 2.5 KB
1
2
3
4
/** @license https://bddjr.github.io/tinyhmacmd5/lic */
{let r=[],n=Math,t=n.floor,e=r=>16*t((r+72)/64),o=(o,f,a=0,l=e(f),c=1732584193,i=271733878,d,g,h=[c,~i,~c,i],u=[...h])=>{for(o[l-1]=0|f/2**29,o[t(f/4)]|=128<<(o[l-2]=f<<3);a<o.length;){for(l=0;l<64;)h[g&=3]=0|((i=0|h[g]+(c=h[3&++g],i=h[3&++g],d=h[3&++g],(f=l>>4<<2)?f>4?f>8?i^(c|~d):c^i^d:c&d|i&~d:c&i|~c&d)+(0|o[a+(l*(29521>>f)+(1296>>f)&15)])+(d="',16%).4$+07&*/5".charCodeAt(3&l|f),r[63-l++]??=0|2**32*n.abs(n.sin(l))))<<d|i>>>64-d)+c;for(;g;a+=4)u[--g]=h[g]=0|u[g]+h[g]}return h},f=(r,n,t=("string"==typeof r?r=(new TextEncoder).encode(r):r).length,o=new Int32Array(e(4*n+t)),f=0)=>{for(;f<t;)o[n++]=r[f++]|r[f++]<<8|r[f++]<<16|r[f++]<<24;return[o,t]};var md5=(r,n,t)=>{var e=16,a=null!=n,[l,c]=f(r,a*e),i=[],d=t?new Uint8Array(e):"";if(a){let[r,t]=f(n,0);for(t>64&&(r=o(r,t));e;)i[--e]=1785358954^(l[e]=909522486^r[e]);e=16,l=i.concat(o(l,64+c)),c=80}for(l=o(l,c);e;t?d[e]=i:d=(i>>4&&"")+i.toString(16)+d)i=l[--e>>2]>>8*e&255;return d}}
class CCWFetch{token="";allowGuestId=!0;_hmacKey="";_usingGuestId=!1;_guestId="";async healthCheck(t="https://community-web.ccw.site/health/check"){this._hmacKey="",this._usingGuestId=!1;let e=await this.POST(t);if(200!=e.status)throw Error(`CCWFetch healthCheck: HTTP ${e.status} ${e.statusText}`);let s=await e.json();if(200!=s.status){if(!this.token&&this.allowGuestId){let h="";for(;h.length<32;)h+=(0|16*Math.random()).toString(16);if(this._guestId=h,this._usingGuestId=!0,e=await this.POST(t),200!=e.status)throw Error(`CCWFetch healthCheck: HTTP ${e.status} ${e.statusText}`);s=await e.json()}if(200!=s.status)throw Error(`CCWFetch healthCheck: ${s.msg}`)}const h=s.body;this._hmacKey=h.reduce((t,{traceId:e})=>e[parseInt(e[0],16)+1]+t,"")}async fetch(t,e,s,h){if((h=null==h?{}:Object.assign({},h)).method=t,h.headers=new Headers(h.headers??{}),h.headers.has("content-type")||h.headers.set("content-type","application/json"),this.token)h.headers.set("token",this.token);else if(this._usingGuestId&&this.allowGuestId)h.headers.set("guest-id",this._guestId);else if(h.credentials??="include",navigator.userAgent.includes("gandi-desktop"))try{const{token:t}=electron.ipcRenderer.sendSync("auth:get-token");t&&h.headers.set("token",t)}catch(t){console.error(t)}if(s){"object"==typeof s&&(s=JSON.stringify(s)),h.body=s,this._hmacKey||await this.healthCheck();const t=""+Date.now();h.headers.set("b",t),h.headers.set("a",md5("ccw"+s+t,this._hmacKey))}return fetch(e,h)}POST(t,e,s){return this.fetch("POST",t,e,s)}GET(t,e){return this.fetch("GET",t,null,e)}}