update sw: improved fuzzy matching rules, support for per-collection rules for ziparchive

This commit is contained in:
Ilya Kreymer
2020-05-16 20:41:03 -07:00
parent e995acfdbd
commit 6a85bd801e
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -827,7 +827,7 @@ const n=new WeakMap,s=Object(r.d)(e=>t=>{if(!(t instanceof r.b))throw new Error(
<button class="modal-close is-large" aria-label="close"></button>
</div>
`:""}
`}onReAuthed(e){this.reauthWait=(async()=>{const t=e.detail.headers;await fetch(`/wabac/api/${this.collInfo.coll}/updateAuth`,{method:"POST",body:JSON.stringify({headers:t})});this.showAuth&&(this.onRefresh(null,!0),this.showAuth=!1)})()}}class ae extends a.a{constructor(){super(),this.state="trypublic",this.sourceUrl="",this.scriptLoaded=!1,this.error=!1}static get properties(){return{state:{type:String},sourceUrl:{type:String},error:{type:Boolean},reauth:{type:Boolean}}}updated(e){e.has("sourceUrl")&&(this.error=!1,this.state="trypublic",this.tryPublicAccess().then(e=>{e||(this.state="tryauto",this.requestUpdate())}))}async tryPublicAccess(){try{const e=this.sourceUrl,t="https://gdrive-proxy.webrecorder.workers.dev/g/"+e.slice("googledrive://".length);let i=null;try{i=await fetch(t)}catch(e){return!1}const a=await i.json();if(!a.url||!a.name||!a.size)return!1;if(a.size>15e6)return!1;const o=a.url;try{const e=new AbortController,t=e.signal;if(i=await fetch(o,{signal:t}),e.abort(),200!=i.status)return!1}catch(e){return!1}const r=a.name,n={publicUrl:o},s=Number(a.size);return this.dispatchEvent(new CustomEvent("load-ready",{detail:{name:r,extra:n,size:s,sourceUrl:e}})),!0}catch(e){return!1}}onLoad(){this.scriptLoaded=!0,this.gauth("none",e=>{"immediate_failed"===e.error?"implicitonly"!==this.state&&(this.state="trymanual"):this.authed(e)})}onClickAuth(){this.gauth("select_account",e=>{e.error||this.authed(e)})}async authed(e){const t=this.sourceUrl,i="https://www.googleapis.com/drive/v3/files/"+t.slice("googledrive://".length),a={Authorization:"Bearer "+e.access_token},o=await fetch(i+"?fields=name,size&supportsAllDrives=true",{headers:a});if(404===o.status||403==o.status)return"implicitonly"!==this.state&&(this.state="trymanual"),void(this.error=!0);this.error=!1;const r=await o.json(),n=r.name,s=Number(r.size);this.dispatchEvent(new CustomEvent("load-ready",{detail:{sourceUrl:t,headers:a,size:s,name:n}}))}static get styles(){return Z(a.b``)}render(){return a.c`
`}onReAuthed(e){this.reauthWait=(async()=>{const t=e.detail.headers;await fetch(`/wabac/api/${this.collInfo.coll}/updateAuth`,{method:"POST",body:JSON.stringify({headers:t})});this.showAuth&&(this.onRefresh(null,!0),this.showAuth=!1)})()}}class ae extends a.a{constructor(){super(),this.state="trypublic",this.sourceUrl="",this.scriptLoaded=!1,this.error=!1}static get properties(){return{state:{type:String},sourceUrl:{type:String},error:{type:Boolean},reauth:{type:Boolean}}}updated(e){e.has("sourceUrl")&&(this.error=!1,this.state="trypublic",this.tryPublicAccess().then(e=>{e||(this.state="tryauto",this.requestUpdate())}))}async tryPublicAccess(){try{const e=this.sourceUrl,t="https://helper-proxy.webrecorder.workers.dev/g/"+e.slice("googledrive://".length);let i=null;try{i=await fetch(t)}catch(e){return!1}const a=await i.json();if(!a.url||!a.name||!a.size)return!1;if(a.size>15e6)return!1;const o=a.url;try{const e=new AbortController,t=e.signal;if(i=await fetch(o,{signal:t}),e.abort(),200!=i.status)return!1}catch(e){return!1}const r=a.name,n={publicUrl:o},s=Number(a.size);return this.dispatchEvent(new CustomEvent("load-ready",{detail:{name:r,extra:n,size:s,sourceUrl:e}})),!0}catch(e){return!1}}onLoad(){this.scriptLoaded=!0,this.gauth("none",e=>{"immediate_failed"===e.error?"implicitonly"!==this.state&&(this.state="trymanual"):this.authed(e)})}onClickAuth(){this.gauth("select_account",e=>{e.error||this.authed(e)})}async authed(e){const t=this.sourceUrl,i="https://www.googleapis.com/drive/v3/files/"+t.slice("googledrive://".length),a={Authorization:"Bearer "+e.access_token},o=await fetch(i+"?fields=name,size&supportsAllDrives=true",{headers:a});if(404===o.status||403==o.status)return"implicitonly"!==this.state&&(this.state="trymanual"),void(this.error=!0);this.error=!1;const r=await o.json(),n=r.name,s=Number(r.size);this.dispatchEvent(new CustomEvent("load-ready",{detail:{sourceUrl:t,headers:a,size:s,name:n}}))}static get styles(){return Z(a.b``)}render(){return a.c`
${this.script()}
${"trymanual"!==this.state?a.c`
<p>Connecting to Google Drive...</p>