From 4af79833551906e095ecfbc04891d964644765d1 Mon Sep 17 00:00:00 2001 From: Ilya Kreymer Date: Thu, 7 May 2020 11:19:46 -0700 Subject: [PATCH] fix reauth redirect --- dist/frontend.js | 2 +- src/frontend.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/frontend.js b/dist/frontend.js index ca93dc9..50a019b 100644 --- a/dist/frontend.js +++ b/dist/frontend.js @@ -236,7 +236,7 @@ const ae=new WeakMap,re=v(e=>t=>{if(!(t instanceof A))throw new Error("unsafeHTM `:""===this.sourceUrl?M` - `:void 0}firstUpdated(){this.initRoute()}updated(e){e.has("sourceUrl")&&(this.sourceLoaded=!1)}async onReAuthed(e){this.pageParams.get("redirUrl");const{coll:t}=await de(this.sourceUrl),i=e.detail.headers;await fetch(`/wabac/api/${t}/updateAuth`,{method:"POST",body:JSON.stringify({headers:i})})}onFavIcons(e){const t=document.querySelector("head"),i=document.querySelectorAll("link[rel*='icon']");for(const e of i)t.removeChild(e);for(const i of e.detail.icons){const e=document.createElement("link");e.rel=i.rel,e.href=i.href,t.appendChild(e)}}onNavMenu(){this.navMenuShown=!this.navMenuShown}initRoute(){this.pageParams=new URLSearchParams(window.location.search);let e=this.pageParams.get("state");if(e)try{if(e=JSON.parse(e),e.ids instanceof Array&&e.userId&&"open"===e.action)return this.pageParams.set("source","googledrive://"+e.ids[0]),this.pageParams.delete("state"),void(window.location.search=this.pageParams.toString())}catch(e){console.log(e)}this.sourceUrl=this.pageParams.get("source")||"",this.pageParams.get("autherr")&&this.pageParams.get("redirUrl")&&this.sourceUrl.startsWith("googledrive://")&&(this.gdriveReAuth=this.sourceUrl.slice("googledrive://".length)),this.pageParams.has("terms")&&(this.showTerms=!0)}onStartLoad(e){if(!e.detail.blobUrl)return this.pageParams.set("source",e.detail.sourceUrl),void(window.location.search=this.pageParams.toString());this.sourceUrl=e.detail.sourceUrl,this.loadInfo=e.detail}onCollLoaded(e){this.loadInfo=null,e.detail.alreadyLoaded?this.sourceLoaded=!0:(this.initRoute(),e.detail.sourceUrl!==this.sourceUrl&&(this.pageParams.set("source",e.detail.sourceUrl),window.location.search=this.pageParams.toString()))}}class Me extends ie{constructor(){super(),this.progress=0,this.total=0,this.percent=0,this.coll="",this.state="waiting",this.loadInfo=null}static get properties(){return{sourceUrl:{type:String},loadInfo:{type:Object},state:{type:String},progress:{type:Number},percent:{type:Number},error:{type:String},total:{type:Number},status:{type:String},coll:{type:String}}}firstUpdated(e){this.initMessages()}initMessages(){Ge.addEventListener("message",e=>{switch(e.data.msg_type){case"collProgress":e.data.name===this.coll&&(this.percent=e.data.percent,e.data.error&&(this.error=e.data.error,this.state="errored"));break;case"collAdded":e.data.name===this.coll&&(this.total||(this.total=100),this.progress=this.total,this.percent=100)}})}async doLoad(){let e=this.sourceUrl,t=null;try{const{scheme:i,host:a,path:r}=function(e){let t=e.indexOf("://"),i=0,a="",r="",o="";return t>=0?(a=e.slice(0,t),t+=3):(t++,e.startsWith("//")&&(t+=2)),i=e.indexOf("/",t),i>0?(r=e.slice(t,i),o=e.slice(i)):(r=e.slice(t),o=""),{scheme:a,host:r,path:o}}(e);switch(i){case"googledrive":this.state="googledrive",this.fileId=a,t=await this.googledriveInit();break;case"s3":e=`https://${a}.s3.amazonaws.com${r}`,t={sourceUrl:e,sourceId:this.sourceUrl,name:this.sourceUrl};break;case"file":if(!this.loadInfo)return this.state="errored",void(this.error="File URLs are local and can not be shared. You can choose a file to upload from the main page.");t={sourceUrl:this.loadInfo.blobUrl,sourceId:this.loadInfo.name,name:this.loadInfo.name}}}catch(e){}t||(t={sourceUrl:e}),this.state="started";const i={msg_type:"addColl",name:this.coll,skipExisting:!0,file:t};Ge.postMessage(i)}googledriveInit(){return this._gdWait=new Promise(e=>this._gdResolve=e),this._gdWait}async onLoadReady(e){this._gdResolve&&this._gdResolve(e.detail)}updated(e){this.sourceUrl&&e.has("sourceUrl")&&this.doLoad()}static get styles(){return Ne(ee` + `:void 0}firstUpdated(){this.initRoute()}updated(e){e.has("sourceUrl")&&(this.sourceLoaded=!1)}async onReAuthed(e){const t=this.pageParams.get("redirUrl"),{coll:i}=await de(this.sourceUrl),a=e.detail.headers;await fetch(`/wabac/api/${i}/updateAuth`,{method:"POST",body:JSON.stringify({headers:a})});t&&(window.location.href=t)}onFavIcons(e){const t=document.querySelector("head"),i=document.querySelectorAll("link[rel*='icon']");for(const e of i)t.removeChild(e);for(const i of e.detail.icons){const e=document.createElement("link");e.rel=i.rel,e.href=i.href,t.appendChild(e)}}onNavMenu(){this.navMenuShown=!this.navMenuShown}initRoute(){this.pageParams=new URLSearchParams(window.location.search);let e=this.pageParams.get("state");if(e)try{if(e=JSON.parse(e),e.ids instanceof Array&&e.userId&&"open"===e.action)return this.pageParams.set("source","googledrive://"+e.ids[0]),this.pageParams.delete("state"),void(window.location.search=this.pageParams.toString())}catch(e){console.log(e)}this.sourceUrl=this.pageParams.get("source")||"",this.pageParams.get("autherr")&&this.pageParams.get("redirUrl")&&this.sourceUrl.startsWith("googledrive://")&&(this.gdriveReAuth=this.sourceUrl.slice("googledrive://".length)),this.pageParams.has("terms")&&(this.showTerms=!0)}onStartLoad(e){if(!e.detail.blobUrl)return this.pageParams.set("source",e.detail.sourceUrl),void(window.location.search=this.pageParams.toString());this.sourceUrl=e.detail.sourceUrl,this.loadInfo=e.detail}onCollLoaded(e){this.loadInfo=null,e.detail.alreadyLoaded?this.sourceLoaded=!0:(this.initRoute(),e.detail.sourceUrl!==this.sourceUrl&&(this.pageParams.set("source",e.detail.sourceUrl),window.location.search=this.pageParams.toString()))}}class Me extends ie{constructor(){super(),this.progress=0,this.total=0,this.percent=0,this.coll="",this.state="waiting",this.loadInfo=null}static get properties(){return{sourceUrl:{type:String},loadInfo:{type:Object},state:{type:String},progress:{type:Number},percent:{type:Number},error:{type:String},total:{type:Number},status:{type:String},coll:{type:String}}}firstUpdated(e){this.initMessages()}initMessages(){Ge.addEventListener("message",e=>{switch(e.data.msg_type){case"collProgress":e.data.name===this.coll&&(this.percent=e.data.percent,e.data.error&&(this.error=e.data.error,this.state="errored"));break;case"collAdded":e.data.name===this.coll&&(this.total||(this.total=100),this.progress=this.total,this.percent=100)}})}async doLoad(){let e=this.sourceUrl,t=null;try{const{scheme:i,host:a,path:r}=function(e){let t=e.indexOf("://"),i=0,a="",r="",o="";return t>=0?(a=e.slice(0,t),t+=3):(t++,e.startsWith("//")&&(t+=2)),i=e.indexOf("/",t),i>0?(r=e.slice(t,i),o=e.slice(i)):(r=e.slice(t),o=""),{scheme:a,host:r,path:o}}(e);switch(i){case"googledrive":this.state="googledrive",this.fileId=a,t=await this.googledriveInit();break;case"s3":e=`https://${a}.s3.amazonaws.com${r}`,t={sourceUrl:e,sourceId:this.sourceUrl,name:this.sourceUrl};break;case"file":if(!this.loadInfo)return this.state="errored",void(this.error="File URLs are local and can not be shared. You can choose a file to upload from the main page.");t={sourceUrl:this.loadInfo.blobUrl,sourceId:this.loadInfo.name,name:this.loadInfo.name}}}catch(e){}t||(t={sourceUrl:e}),this.state="started";const i={msg_type:"addColl",name:this.coll,skipExisting:!0,file:t};Ge.postMessage(i)}googledriveInit(){return this._gdWait=new Promise(e=>this._gdResolve=e),this._gdWait}async onLoadReady(e){this._gdResolve&&this._gdResolve(e.detail)}updated(e){this.sourceUrl&&e.has("sourceUrl")&&this.doLoad()}static get styles(){return Ne(ee` .logo { width: 96px; height: 96px; diff --git a/src/frontend.js b/src/frontend.js index 1685a67..37d85d6 100644 --- a/src/frontend.js +++ b/src/frontend.js @@ -180,7 +180,7 @@ class AppMain extends LitElement }); if (redir) { - //window.location.href = redir; + window.location.href = redir; } }