var lsKeys={token:"token",chunkSize:"chunkSize",parallelUploads:"parallelUploads",uploadsHistoryOrder:"uploadsHistoryOrder",fileLength:"fileLength",uploadAge:"uploadAge"},page={token:localStorage[lsKeys.token],private:null,enableUserAccounts:null,maxSize:null,chunkSize:null,temporaryUploadAges:null,fileIdentifierLength:null,album:null,parallelUploads:null,uploadsHistoryOrder:null,fileLength:null,uploadAge:null,maxSizeBytes:null,urlMaxSize:null,urlMaxSizeBytes:null,tabs:[],activeTab:null,albumSelect:null,previewTemplate:null,dropzone:null,clipboardJS:null,lazyLoad:null,imageExtensions:[".webp",".jpg",".jpeg",".bmp",".gif",".png",".svg"],checkIfPublic:function(e){return axios.get("api/check").then((function(a){return page.private=a.data.private,page.enableUserAccounts=a.data.enableUserAccounts,page.maxSize=parseInt(a.data.maxSize),page.maxSizeBytes=1e6*page.maxSize,page.chunkSize=parseInt(a.data.chunkSize),page.temporaryUploadAges=a.data.temporaryUploadAges,page.fileIdentifierLength=a.data.fileIdentifierLength,page.preparePage(e)})).catch(e)},preparePage:function(e){if(!page.private)return page.prepareUpload(e);if(page.token)return page.verifyToken(page.token,e,!0);var a=document.querySelector("#loginToUpload");a.href="auth",a.classList.remove("is-loading"),page.enableUserAccounts?a.innerText="Anonymous upload is disabled. Log in to upload.":a.innerText="Running in private mode. Log in to upload."},verifyToken:function(e,a,t){return axios.post("api/tokens/verify",{token:e}).then((function(r){return!1===r.data.success?swal({title:"An error occurred!",text:r.data.description,icon:"error"}).then((function(){t&&(localStorage.removeItem("token"),location.reload())})):(localStorage.token=e,page.token=e,page.prepareUpload(a))})).catch(a)},prepareUpload:function(e){page.token&&(document.querySelector("#albumDiv").classList.remove("is-hidden"),page.albumSelect=document.querySelector("#albumSelect"),page.albumSelect.addEventListener("change",(function(){page.album=parseInt(page.albumSelect.value),"function"==typeof page.prepareShareX&&page.prepareShareX()})),page.fetchAlbums(e)),page.prepareUploadConfig(),document.querySelector("#maxSize > span").innerHTML=page.getPrettyBytes(page.maxSizeBytes),document.querySelector("#loginToUpload").classList.add("is-hidden"),!page.token&&page.enableUserAccounts&&(document.querySelector("#loginLinkText").innerHTML="Create an account and keep track of your uploads"),page.prepareDropzone(),"function"==typeof page.prepareShareX&&page.prepareShareX();var a=document.querySelector("#urlMaxSize");a&&(page.urlMaxSize=parseInt(a.innerHTML),page.urlMaxSizeBytes=1e6*page.urlMaxSize,a.innerHTML=page.getPrettyBytes(page.urlMaxSizeBytes),document.querySelector("#uploadUrls").addEventListener("click",(function(e){page.uploadUrls(e.currentTarget)})));for(var t=document.querySelector("#tabs"),r=t.querySelectorAll("li"),n=function(e){var a=r[e].dataset.id,t=document.querySelector("#"+a);t&&(r[e].addEventListener("click",(function(){page.setActiveTab(e)})),page.tabs.push({tab:r[e],content:t}))},l=0;l a"),r=e.previewElement.querySelector(".clipboard-mobile > .clipboard-js");t.href=t.innerHTML=r.dataset.clipboardText=a.url,r.parentElement.classList.remove("is-hidden");var n=/.[\w]+(\?|$)/.exec(a.url);if(n&&n[0]&&page.imageExtensions.includes(n[0].toLowerCase())){var l=e.previewElement.querySelector("img");l.setAttribute("alt",a.name||""),l.dataset.src=a.url,l.classList.remove("is-hidden"),l.onerror=function(a){a.currentTarget.classList.add("is-hidden"),page.updateTemplateIcon(e.previewElement,"icon-picture")},page.lazyLoad.update(e.previewElement.querySelectorAll("img"))}else page.updateTemplateIcon(e.previewElement,"icon-doc-inv");if(a.expirydate){var o=e.previewElement.querySelector(".expiry-date");o.innerHTML="Expiry date: "+page.getPrettyDate(new Date(1e3*a.expirydate)),o.classList.remove("is-hidden")}}},createAlbum:function(){var e=document.createElement("div");e.innerHTML='\n
\n
\n \n
\n
\n
\n
\n \n
\n
\n
\n
\n \n
\n
\n
\n
\n \n
\n
\n ',swal({title:"Create new album",icon:"info",content:e,buttons:{cancel:!0,confirm:{closeModal:!1}}}).then((function(e){if(e){var a=document.querySelector("#swalName").value.trim();axios.post("api/albums",{name:a,description:document.querySelector("#swalDescription").value.trim(),download:document.querySelector("#swalDownload").checked,public:document.querySelector("#swalPublic").checked},{headers:{token:page.token}}).then((function(e){if(!1===e.data.success)return swal("An error occurred!",e.data.description,"error");var t=document.createElement("option");page.albumSelect.appendChild(t),t.value=e.data.id,t.innerHTML=a,t.selected=!0,swal("Woohoo!","Album was created successfully.","success")})).catch((function(e){return console.error(e),swal("An error occurred!","There was an error with the request, please check the console for more information.","error")}))}}))},prepareUploadConfig:function(){var e={chunkSize:page.chunkSize,parallelUploads:2};page.chunkSize=parseInt(localStorage[lsKeys.chunkSize])||e.chunkSize,page.parallelUploads=parseInt(localStorage[lsKeys.parallelUploads])||e.parallelUploads,document.querySelector("#chunkSize").value=page.chunkSize,document.querySelector("#parallelUploads").value=page.parallelUploads;var a={chunkSize:{min:1,max:95},parallelUploads:{min:1,max:8}};document.querySelector("#chunkSizeDiv .help").innerHTML="Default is "+e.chunkSize+" MB. Max is "+a.chunkSize.max+" MB.",document.querySelector("#parallelUploadsDiv .help").innerHTML="Default is "+e.parallelUploads+". Max is "+a.parallelUploads.max+".";var t=document.querySelector("#fileLengthDiv");if(page.fileIdentifierLength&&t){var r=document.querySelector("#fileLength"),n=parseInt(localStorage[lsKeys.fileLength]);e.fileLength=page.fileIdentifierLength.default;var l="Default is "+page.fileIdentifierLength.default+".",o="number"==typeof page.fileIdentifierLength.min&&"number"==typeof page.fileIdentifierLength.max;o&&(l+=" Min is "+page.fileIdentifierLength.min+". Max is "+page.fileIdentifierLength.max,a.fileLength={min:page.fileIdentifierLength.min,max:page.fileIdentifierLength.max}),page.fileIdentifierLength.force&&(l+=" This option is currently disabled.",r.disabled=!0),page.fileIdentifierLength.force||isNaN(n)||!o||npage.fileIdentifierLength.max?(r.value=e.fileLength,page.fileLength=null):(r.value=n,page.fileLength=n),t.classList.remove("is-hidden"),t.querySelector(".help").innerHTML=l}Object.keys(a).forEach((function(e){document.querySelector("#"+e).setAttribute("min",a[e].min),document.querySelector("#"+e).setAttribute("max",a[e].max)}));var i=document.querySelector("#uploadAgeDiv");if(Array.isArray(page.temporaryUploadAges)&&page.temporaryUploadAges.length&&i){for(var s=document.querySelector("#uploadAge"),c=parseFloat(localStorage[lsKeys.uploadAge]),p=0;p .uploads"),f=0;f0&&s!==e[l[o]]?localStorage[lsKeys[l[o]]]=s:localStorage.removeItem(lsKeys[l[o]])}swal({title:"Woohoo!",text:"Configuration saved into this browser.",icon:"success"}).then((function(){location.reload()}))}}))},getPrettyUploadAge:function(e){if(0===e)return"Permanent";if(e<1){var a=60*e;return a+" minute"+(1===a?"":"s")}if(e>=24){var t=e/24;return t+" day"+(1===t?"":"s")}return e+" hour"+(1===e?"":"s")}};window.addEventListener("paste",(function(e){for(var a=(e.clipboardData||e.originalEvent.clipboardData).items,t=Object.keys(a),r=0;r",swal({title:"An error occurred!",icon:"error",content:n})}}page.checkIfPublic(e),page.clipboardJS=new ClipboardJS(".clipboard-js"),page.clipboardJS.on("success",(function(){return swal("Copied!","The link has been copied to clipboard.","success")})),page.clipboardJS.on("error",e),page.lazyLoad=new LazyLoad({elements_selector:".field.uploads img"}),document.querySelector("#createAlbum").addEventListener("click",(function(){page.createAlbum()}))}; //# sourceMappingURL=home.js.map