(function(p){typeof define=="function"&&define.amd?define(p):p()})(function(){"use strict";function p(r,u,o,e){if(u===!1||u==null||!u&&(r==="class"||r==="style"))return"";if(u===!0)return" "+(e?r:r+'="'+r+'"');var i=typeof u;return i!=="object"&&i!=="function"||typeof u.toJSON!="function"||(u=u.toJSON()),typeof u=="string"||(u=JSON.stringify(u),o||u.indexOf('"')===-1)?(o&&(u=n(u))," "+r+'="'+u+'"'):" "+r+"='"+u.replace(/'/g,"&#39;")+"'"}function n(r){var u=""+r,o=z.exec(u);if(!o)return r;var e,i,t,a="";for(e=o.index,i=0;e<u.length;e++){switch(u.charCodeAt(e)){case 34:t="&quot;";break;case 38:t="&amp;";break;case 60:t="&lt;";break;case 62:t="&gt;";break;default:continue}i!==e&&(a+=u.substring(i,e)),i=e+1,a+=t}return i!==e?a+u.substring(i,e):a}var z=/["&<>]/;function h(r,u,o,e){if(!(r instanceof Error))throw r;if(!(typeof window>"u"&&u||e))throw r.message+=" on line "+o,r;var i,t,a,l;try{e=e||require("fs").readFileSync(u,{encoding:"utf8"}),i=3,t=e.split(`
`),a=Math.max(o-i,0),l=Math.min(t.length,o+i)}catch(d){return r.message+=" - could not read from "+u+" ("+d.message+")",void h(r,null,o)}i=t.slice(a,l).map(function(d,c){var F=c+a+1;return(F==o?"  > ":"    ")+F+"| "+d}).join(`
`),r.path=u;try{r.message=(u||"Pug")+":"+o+`
`+i+`

`+r.message}catch{}throw r}function f(r){var u="",o,e,i;try{var t=r||{};(function(a){i=1,e="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizeUpload.pug",u=u+'<div class="g-body-title">',i=1,e="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizeUpload.pug",u=u+"Authorize upload into folder ",i=1,e="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizeUpload.pug",u=u+"<a"+p("href",`#folder/${a.id}`,!0,!1)+">",i=1,e="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizeUpload.pug",u=u+n((o=a.name())==null?"":o)+"</a>",i=1,e="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizeUpload.pug",u=u+"</div>",i=3,e="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizeUpload.pug",u=u+"<p>",i=4,e="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizeUpload.pug",u=u+"This will generate a secure URL that can be used to upload a single file into this folder.",i=5,e="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizeUpload.pug",u=u+`
`,i=5,e="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizeUpload.pug",u=u+"</p>",i=6,e="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizeUpload.pug",u=u+"<form>",i=7,e="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizeUpload.pug",u=u+'<div class="form-group">',i=8,e="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizeUpload.pug",u=u+"<label>",i=8,e="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizeUpload.pug",u=u+"Number of days until URL expires (optional, defaults to lifetime of user sessions)</label>",i=9,e="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizeUpload.pug",u=u+'<input class="g-num-days form-control"/></div></form>',i=11,e="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizeUpload.pug",u=u+'<btn class="g-create-authorized-upload btn btn-primary">',i=12,e="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizeUpload.pug",u=u+'<i class="icon-link"></i>',i=13,e="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizeUpload.pug",u=u+" Generate URL</btn>",i=15,e="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizeUpload.pug",u=u+'<div class="g-url-container hide">',i=16,e="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizeUpload.pug",u=u+"<p>",i=17,e="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizeUpload.pug",u=u+"Your secure URL is below. Copy this value and send it to the user who will perform the",i=18,e="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizeUpload.pug",u=u+`
`,i=18,e="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizeUpload.pug",u=u+"upload. They do not need to register a user in order to perform the upload. This token",i=19,e="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizeUpload.pug",u=u+`
`,i=19,e="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizeUpload.pug",u=u+"will allow the user to upload a single file to the destination folder.</p>",i=20,e="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizeUpload.pug",u=u+"<p>",i=20,e="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizeUpload.pug",u=u+"You will be notified via email when the upload is complete.</p>",i=21,e="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizeUpload.pug",u=u+"<input"+(' class="g-authorized-upload-url-target form-control"'+p("readonly",!0,!0,!1))+"/></div>"}).call(this,"folder"in t?t.folder:typeof folder<"u"?folder:void 0)}catch(a){h(a,e,i)}return u}const L="",w=girder.views.View,{restRequest:b}=girder.rest;var U=w.extend({events:{"click .g-create-authorized-upload":function(){b({url:"authorized_upload",method:"POST",data:{folderId:this.folder.id,duration:this.$(".g-num-days").val()||30}}).done(r=>{this.$(".g-url-container").removeClass("hide"),this.$(".g-authorized-upload-url-target").val(r.url).trigger("select")})}},initialize:function(r){this.folder=r.folder,this.render()},render:function(){return this.$el.html(f({folder:this.folder})),this}});function g(r,u,o,e){if(!(r instanceof Error))throw r;if(!(typeof window>"u"&&u||e))throw r.message+=" on line "+o,r;var i,t,a,l;try{e=e||require("fs").readFileSync(u,{encoding:"utf8"}),i=3,t=e.split(`
`),a=Math.max(o-i,0),l=Math.min(t.length,o+i)}catch(d){return r.message+=" - could not read from "+u+" ("+d.message+")",void g(r,null,o)}i=t.slice(a,l).map(function(d,c){var F=c+a+1;return(F==o?"  > ":"    ")+F+"| "+d}).join(`
`),r.path=u;try{r.message=(u||"Pug")+":"+o+`
`+i+`

`+r.message}catch{}throw r}function v(r){var u="",o,e;try{e=1,o="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizedUpload.pug",u=u+'<div class="g-authorized-upload-page-wrapper">',e=2,o="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizedUpload.pug",u=u+'<div class="g-upload-wrapper">',e=3,o="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizedUpload.pug",u=u+"<p>",e=4,o="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizedUpload.pug",u=u+"You have been authorized to upload a file to this server. Please drag and drop your file",e=5,o="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizedUpload.pug",u=u+`
`,e=5,o="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizedUpload.pug",u=u+"here, or click the button to select it using a file browser, and then click ",e=5,o="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizedUpload.pug",u=u+"<b>",e=5,o="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizedUpload.pug",u=u+"Start Upload</b>",e=5,o="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizedUpload.pug",u=u+".",e=6,o="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizedUpload.pug",u=u+`
`,e=6,o="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizedUpload.pug",u=u+"</p>",e=7,o="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizedUpload.pug",u=u+"<p>",e=8,o="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizedUpload.pug",u=u+"You may also include your email address and a description of the data.",e=9,o="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizedUpload.pug",u=u+`
`,e=9,o="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizedUpload.pug",u=u+"</p>",e=10,o="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizedUpload.pug",u=u+'<label for="g-authorized-upload-email">',e=10,o="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizedUpload.pug",u=u+"Your email address (optional)</label>",e=11,o="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizedUpload.pug",u=u+'<input class="form-control" id="g-authorized-upload-email" placeholder="Enter email"/>',e=13,o="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizedUpload.pug",u=u+'<label for="g-authorized-upload-description">',e=13,o="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizedUpload.pug",u=u+"Description of data (optional)</label>",e=14,o="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizedUpload.pug",u=u+'<input class="form-control" id="g-authorized-upload-description" placeholder="Enter description"/>',e=16,o="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizedUpload.pug",u=u+'<div class="g-upload-widget-container"></div></div>',e=17,o="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizedUpload.pug",u=u+'<div class="g-complete-wrapper hide">',e=18,o="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizedUpload.pug",u=u+"<p>",e=18,o="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/authorizedUpload.pug",u=u+"Thank you! Your file has been received.</p></div></div>"}catch(i){g(i,o,e)}return u}const V="",j=girder.models.FolderModel,E=girder.views.View,C=girder.views.widgets.UploadWidget,{setCurrentToken:y}=girder.auth;var $=E.extend({initialize:function(r){this.folder=new j({_id:r.folderId,name:""}),y(r.token),this.uploadWidget=new C({parent:this.folder,title:!1,multiFile:!1,modal:!1,parentView:this,otherParams:()=>({authorizedUploadDescription:this.$("#g-authorized-upload-description").val(),authorizedUploadEmail:this.$("#g-authorized-upload-email").val()})}).on("g:uploadFinished",function(){this.$(".g-upload-wrapper").addClass("hide"),this.$(".g-complete-wrapper").removeClass("hide")},this),this.render()},render:function(){return this.$el.html(v()),this.uploadWidget.setElement(this.$(".g-upload-widget-container")).render(),this}});const s=girder.router,_=girder.events,k=girder.models.FolderModel,M=girder.constants.Layout;s.route("authorize_upload/:folderId","authorizeUpload",r=>{var u=new k({_id:r}).once("g:fetched",()=>{_.trigger("g:navigateTo",U,{folder:u})});u.fetch()}),s.route("authorized_upload/:folderId/:token","authorizedUpload",function(r,u){_.trigger("g:navigateTo",$,{token:u,folderId:r},{layout:M.EMPTY})});function x(r,u,o,e){if(u===!1||u==null||!u&&(r==="class"||r==="style"))return"";if(u===!0)return" "+(e?r:r+'="'+r+'"');var i=typeof u;return i!=="object"&&i!=="function"||typeof u.toJSON!="function"||(u=u.toJSON()),typeof u=="string"||(u=JSON.stringify(u),o||u.indexOf('"')===-1)?(o&&(u=A(u))," "+r+'="'+u+'"'):" "+r+"='"+u.replace(/'/g,"&#39;")+"'"}function A(r){var u=""+r,o=S.exec(u);if(!o)return r;var e,i,t,a="";for(e=o.index,i=0;e<u.length;e++){switch(u.charCodeAt(e)){case 34:t="&quot;";break;case 38:t="&amp;";break;case 60:t="&lt;";break;case 62:t="&gt;";break;default:continue}i!==e&&(a+=u.substring(i,e)),i=e+1,a+=t}return i!==e?a+u.substring(i,e):a}var S=/["&<>]/;function m(r,u,o,e){if(!(r instanceof Error))throw r;if(!(typeof window>"u"&&u||e))throw r.message+=" on line "+o,r;var i,t,a,l;try{e=e||require("fs").readFileSync(u,{encoding:"utf8"}),i=3,t=e.split(`
`),a=Math.max(o-i,0),l=Math.min(t.length,o+i)}catch(d){return r.message+=" - could not read from "+u+" ("+d.message+")",void m(r,null,o)}i=t.slice(a,l).map(function(d,c){var F=c+a+1;return(F==o?"  > ":"    ")+F+"| "+d}).join(`
`),r.path=u;try{r.message=(u||"Pug")+":"+o+`
`+i+`

`+r.message}catch{}throw r}function T(r){var u="",o,e;try{var i=r||{};(function(t){e=1,o="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/folderActions.pug",u=u+'<li role="presentation">',e=2,o="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/folderActions.pug",u=u+"<a"+(' class="g-authorize-upload-here"'+x("href",`#authorize_upload/${t.id}`,!0,!1))+">",e=3,o="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/folderActions.pug",u=u+'<i class="icon-upload"></i>',e=4,o="/home/circleci/project/girder/plugins/authorized_upload/girder_authorized_upload/web_client/templates/folderActions.pug",u=u+"Authorize upload here</a></li>"}).call(this,"folder"in i?i.folder:typeof folder<"u"?folder:void 0)}catch(t){m(t,o,e)}return u}const O=girder.views.widgets.HierarchyWidget,{wrap:N}=girder.utilities.PluginUtils,{AccessType:P}=girder.constants;N(O,"render",function(r){return r.call(this),this.parentModel.resourceName==="folder"&&this.parentModel.getAccessLevel()>=P.WRITE&&this.$(".g-folder-actions-menu a.g-edit-folder").parent().after(T({folder:this.parentModel})),this})});
