diff --git a/dist/js/dashboard.js b/dist/js/dashboard.js index a252db9..7729eff 100644 --- a/dist/js/dashboard.js +++ b/dist/js/dashboard.js @@ -1,2 +1,2 @@ -var lsKeys={token:"token",viewType:{uploads:"viewTypeUploads",uploadsAll:"viewTypeUploadsAll"},selected:{uploads:"selectedUploads",uploadsAll:"selectedUploadsAll",users:"selectedUsers"}},page={dom:null,token:localStorage[lsKeys.token],username:null,permissions:null,menusContainer:null,menus:[],currentView:null,views:{uploads:{type:localStorage[lsKeys.viewType.uploads],album:null,pageNum:null},uploadsAll:{type:localStorage[lsKeys.viewType.uploadsAll],filters:null,pageNum:null,all:!0},users:{pageNum:null}},selected:{uploads:[],uploadsAll:[],users:[]},checkboxes:{uploads:[],uploadsAll:[],users:[]},lastSelected:{upload:null,uploadsAll:null,user:null},selectAlbumContainer:null,cache:{uploads:{},albums:{},users:{}},clipboardJS:null,lazyLoad:null,imageExts:[".webp",".jpg",".jpeg",".gif",".png",".tiff",".tif",".svg"],videoExts:[".webm",".mp4",".wmv",".avi",".mov",".mkv"],isTriggerLoading:null,fadingIn:null,preparePage:function(){page.token?page.verifyToken(page.token,!0):window.location="auth"},verifyToken:function(e,a){axios.post("api/tokens/verify",{token:e}).then((function(n){if(!1===n.data.success)return swal({title:"An error occurred!",text:n.data.description,icon:"error"}).then((function(){a&&(localStorage.removeItem(lsKeys.token),window.location="auth")}));axios.defaults.headers.common.token=e,localStorage[lsKeys.token]=e,page.token=e,page.username=n.data.username,page.permissions=n.data.permissions,page.prepareDashboard()})).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")}))},prepareDashboard:function(){page.dom=document.querySelector("#page"),page.dom.addEventListener("click",page.domClick,!0),page.dom.addEventListener("submit",(function(e){if(e.target&&e.target.classList.contains("prevent-default"))return e.preventDefault()}),!0),page.menusContainer=document.querySelector("#menu");for(var e=[{selector:"#itemUploads",onclick:page.getUploads},{selector:"#itemDeleteUploadsByNames",onclick:page.deleteUploadsByNames},{selector:"#itemManageAlbums",onclick:page.getAlbums},{selector:"#itemManageToken",onclick:page.changeToken},{selector:"#itemChangePassword",onclick:page.changePassword},{selector:"#itemLogout",onclick:page.logout,inactive:!0},{selector:"#itemManageUploads",onclick:page.getUploads,params:{all:!0},group:"moderator"},{selector:"#itemStatistics",onclick:page.getStatistics,group:"admin"},{selector:"#itemManageUsers",onclick:page.getUsers,group:"admin"}],a=function(a){if(!e[a].group||page.permissions[e[a].group]){var n=document.querySelector(e[a].selector);n.addEventListener("click",(function(n){page.menusContainer.classList.contains("is-loading")||e[a].onclick.call(null,Object.assign({trigger:n.currentTarget},e[a].params||{}))})),n.classList.remove("is-hidden"),page.menus.push(n)}},n=0;n';e.all&&(l='\n
\n
\n
\n
\n \n
\n
\n \n
\n
\n \n
\n
\n
\n
\n ');for(var o='\n
\n '+l+'\n
\n
\n
\n
\n \n
\n
\n \n
\n
\n
\n
\n
\n ',c='\n
\n
\n \n \n
\n ',d=!1,u=n.some((function(e){return void 0!==e.expirydate})),p=0;p\n \n
\n '+i+"\n ";for(var g=document.querySelector("#table"),m=0;m'+h.name+'':b.innerHTML='

'+(h.extname||"N/A")+"

",b.innerHTML+='\n \n
\n '+(h.thumb?'\n \n \n \n \n ':"")+'\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
\n
\n

'+h.name+"

\n

"+(h.appendix?""+h.appendix+" – ":"")+h.prettyBytes+"

\n
\n ",g.appendChild(b),page.checkboxes[page.currentView]=g.querySelectorAll('.checkbox[data-action="select"]'),page.lazyLoad.update()}}else{page.dom.innerHTML="\n "+i+"\n "+o+"\n "+c+'\n
\n \n \n \n \n \n '+(void 0===e.album?"":"")+"\n \n "+(e.all?"":"")+"\n \n "+(u?"":"")+'\n \n \n \n \n \n
File"+(e.all?"User":"Album")+"SizeIPDateExpiry date
\n
\n
\n '+i+"\n ";for(var f=document.querySelector("#table"),v=0;v\n '+w.name+"\n "+(w.appendix?""+w.appendix+"":"")+"\n "+w.prettyBytes+"\n "+(e.all?""+(w.ip||"")+"":"")+"\n "+w.prettyDate+"\n "+(u?""+w.prettyExpiryDate+"":"")+'\n \n \n \n \n \n \n \n \n \n \n \n '+(e.all?"":'\n \n \n \n \n ')+'\n \n \n \n \n \n \n ',f.appendChild(y),page.checkboxes[page.currentView]=f.querySelectorAll('.checkbox[data-action="select"]')}}var k=document.querySelector("#selectAll");k&&!d&&(k.checked=!0,k.title="Unselect all"),page.fadeAndScroll(),page.updateTrigger(e.trigger,"active"),"uploads"===page.currentView&&(page.views.uploads.album=e.album),"uploadsAll"===page.currentView&&(page.views.uploadsAll.filters=e.filters),page.views[page.currentView].pageNum=n.length?e.pageNum:0})).catch((function(a){return console.error(a),page.updateTrigger(e.trigger),swal("An error occurred!","There was an error with the request, please check the console for more information.","error")}))},setUploadsView:function(e,a){localStorage[lsKeys.viewType[page.currentView]]=e,page.views[page.currentView].type=e,page.getUploads(Object.assign({trigger:a},page.views[page.currentView]))},displayThumbnail:function(e){var a=page.cache.uploads[e];if(a.thumb){var n=document.createElement("div");if(n.innerHTML='\n
\n \n
\n \n
\n
\n ',a.original){var t=/.[\w]+(\?|$)/.exec(a.original),s=t&&t[0]?t[0].toLowerCase():null,r=page.imageExts.includes(s),i=!r&&page.videoExts.includes(s);(r||i)&&(n.innerHTML+='\n \n ',n.querySelector("#swalOriginal").addEventListener("click",(function(e){var t=e.currentTarget;if(!t.classList.contains("is-danger")){t.classList.add("is-loading");var s=n.querySelector("#swalThumb");if(r)s.src=a.original,s.onload=function(){t.classList.add("is-hidden"),document.body.querySelector(".swal-overlay .swal-modal:not(.is-expanded)").classList.add("is-expanded")},s.onerror=function(e){e.currentTarget.classList.add("is-hidden"),t.className="button is-danger is-fullwidth",t.innerHTML='\n \n \n \n Unable to load original\n '};else if(i){s.classList.add("is-hidden");var l=document.createElement("video");l.id="swalVideo",l.controls=!0,l.autoplay=!0,l.src=a.original,s.insertAdjacentElement("afterend",l),t.classList.add("is-hidden"),document.body.querySelector(".swal-overlay .swal-modal:not(.is-expanded)").classList.add("is-expanded")}}})))}return swal({content:n,buttons:!1}).then((function(){var e=n.querySelector("#swalVideo");e&&e.remove(),document.body.querySelector(".swal-overlay .swal-modal").classList.remove("is-expanded")}))}},selectAll:function(e){for(var a=0;at&&s>t&&sn&&s"),swal({content:a})},filterUploads:function(e){var a=document.querySelector("#filters").value;page.getUploads({all:!0,filters:a},e)},viewUserUploads:function(e,a){var n=page.cache.users[e];n&&(a.classList.add("is-loading"),page.getUploads({all:!0,filters:"user:"+n.username.replace(/ /g,"\\ "),trigger:document.querySelector("#itemManageUploads")}))},deleteUpload:function(e){page.postBulkDeleteUploads({all:"uploadsAll"===page.currentView,field:"id",values:[e],cb:function(a){!a.length&&page.selected[page.currentView].includes(e)&&page.selected[page.currentView].splice(page.selected[page.currentView].indexOf(e),1),page.selected[page.currentView].length?localStorage[lsKeys.selected[page.currentView]]=JSON.stringify(page.selected[page.currentView]):delete localStorage[lsKeys.selected[page.currentView]],page.getUploads(Object.assign({autoPage:!0},page.views[page.currentView]))}})},bulkDeleteUploads:function(){if(!page.selected[page.currentView].length)return swal("An error occurred!","You have not selected any uploads.","error");page.postBulkDeleteUploads({all:"uploadsAll"===page.currentView,field:"id",values:page.selected[page.currentView],cb:function(e){e.length?page.selected[page.currentView]=page.selected[page.currentView].filter((function(a){return e.includes(a)})):page.selected[page.currentView]=[],page.selected[page.currentView].length?localStorage[lsKeys.selected[page.currentView]]=JSON.stringify(page.selected[page.currentView]):delete localStorage[lsKeys.selected[page.currentView]],page.getUploads(Object.assign({autoPage:!0},page.views[page.currentView]))}})},deleteUploadsByNames:function(e){void 0===e&&(e={});var a="";page.permissions.moderator&&(a="
Hint: You can use this feature to delete uploads by other users."),page.dom.innerHTML='\n
\n
\n \n
\n \n
\n

Separate each entry with a new line.'+a+'

\n
\n
\n
\n \n
\n
\n
\n ',page.fadeAndScroll(),page.updateTrigger(e.trigger,"active"),document.querySelector("#submitBulkDelete").addEventListener("click",(function(){var e=document.querySelector("#bulkDeleteNames"),a={},n=e.value.split(/\r?\n/).map((function(e){var a=e.trim();return/^[^\s]+$/.test(a)?a:""})).filter((function(e){return!(!e||Object.prototype.hasOwnProperty.call(a,e))&&(a[e]=!0)}));if(e.value=n.join("\n"),!n.length)return swal("An error occurred!","You have not entered any upload names.","error");page.postBulkDeleteUploads({all:!0,field:"name",values:n,cb:function(a){e.value=a.join("\n")}})}))},postBulkDeleteUploads:function(e){void 0===e&&(e={});var a=e.values.length,n=e.values.length+" upload"+(1===a?"":"s"),t="

You won't be able to recover "+n.replace(/^(\d*)(.*)/,"$1$2")+"!

";e.all&&(t+="\n

Warning: You may be nuking "+(1===a?"an upload":"some uploads")+" by "+(1===a?"another user":"other users")+"!

");var s=document.createElement("div");s.innerHTML=t,swal({title:"Are you sure?",content:s,icon:"warning",dangerMode:!0,buttons:{cancel:!0,confirm:{text:"Yes, nuke "+(1===e.values.length?"it":"them")+"!",closeModal:!1}}}).then((function(t){t&&axios.post("api/upload/bulkdelete",{field:e.fields,values:e.values}).then((function(t){if(t){if(!1===t.data.success)return"No token provided"===t.data.description?page.verifyToken(page.token):swal("An error occurred!",t.data.description,"error");var s=Array.isArray(t.data.failed)?t.data.failed:[];s.length===e.values.length?swal("An error occurred!","Unable to delete any of the "+n+".","error"):s.length&&s.length\n

You are about to add '+n+" upload"+(1===n?"":"s")+' to an album.

\n

If an upload is already in an album, it will be moved.

\n \n
\n
\n
\n \n
\n
\n
\n ',swal({icon:"warning",content:t,buttons:{cancel:!0,confirm:{text:"OK",closeModal:!1}}}).then((function(n){if(n){var t=parseInt(document.querySelector("#swalAlbum").value);if(isNaN(t))return swal("An error occurred!","You did not choose an album.","error");axios.post("api/albums/addfiles",{ids:e,albumid:t}).then((function(n){if(n)if(!1!==n.data.success){var s=e.length;n.data.failed&&n.data.failed.length&&(s-=n.data.failed.length);var r="upload"+(1===e.length?"":"s");if(!s)return swal("An error occurred!","Could not add the "+r+" to the album.","error");swal("Woohoo!","Successfully "+(t<0?"removed":"added")+" "+s+" "+r+" "+(t<0?"from":"to")+" the album.","success"),a(n.data.failed)}else"No token provided"===n.data.description?page.verifyToken(page.token):swal("An error occurred!",n.data.description,"error")})).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")}))}})).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")})),axios.get("api/albums").then((function(e){if(!1!==e.data.success){var a=document.querySelector("#swalAlbum");a&&(a.innerHTML+=e.data.albums.map((function(e){return'"})).join("\n"),a.getElementsByTagName("option")[1].innerHTML="Choose an album",a.removeAttribute("disabled"))}else"No token provided"===e.data.description?page.verifyToken(page.token):swal("An error occurred!",e.data.description,"error")})).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")}))},getAlbums:function(e){void 0===e&&(e={}),page.updateTrigger(e.trigger,"loading"),axios.get("api/albums").then((function(a){if(a){if(!1===a.data.success)return"No token provided"===a.data.description?page.verifyToken(page.token):(page.updateTrigger(e.trigger),swal("An error occurred!",a.data.description,"error"));page.cache.albums={},page.dom.innerHTML='\n

Create new album

\n
\n
\n
\n \n
\n
\n
\n
\n \n
\n
\n
\n
\n \n
\n
\n
\n
\n

List of albums

\n
\n \n \n \n \n \n \n \n \n \n \n \n \n \n
IDNameFilesCreated atPublic link
\n
\n ';for(var n=a.data.homeDomain,t=document.querySelector("#table"),s=0;s"+r.id+"\n "+r.name+"\n "+r.files+"\n "+r.prettyDate+"\n '+i+'\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n ',t.appendChild(l)}page.fadeAndScroll(),page.updateTrigger(e.trigger,"active")}})).catch((function(a){return console.error(a),page.updateTrigger(e.trigger),swal("An error occurred!","There was an error with the request, please check the console for more information.","error")}))},editAlbum:function(e){var a=page.cache.albums[e];if(a){var n=document.createElement("div");n.innerHTML='\n
\n
\n \n
\n
\n
\n
\n \n
\n
\n
\n
\n \n
\n
\n
\n
\n \n
\n
\n
\n
\n \n
\n
\n ',swal({title:"Edit album",icon:"info",content:n,buttons:{cancel:!0,confirm:{closeModal:!1}}}).then((function(n){n&&axios.post("api/albums/edit",{id:e,name:document.querySelector("#swalName").value.trim(),description:document.querySelector("#swalDescription").value.trim(),download:document.querySelector("#swalDownload").checked,public:document.querySelector("#swalPublic").checked,requestLink:document.querySelector("#swalRequestLink").checked}).then((function(e){if(e){if(!1===e.data.success)return"No token provided"===e.data.description?page.verifyToken(page.token):swal("An error occurred!",e.data.description,"error");e.data.identifier?swal("Success!","Your album's new identifier is: "+e.data.identifier+".","success"):e.data.name!==a.name?swal("Success!","Your album was renamed to: "+e.data.name+".","success"):swal("Success!","Your album was edited!","success"),page.getAlbumsSidebar(),page.getAlbums()}})).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")}))}))}},deleteAlbum:function(e){swal({title:"Are you sure?",text:"This won't delete your uploads, only the album!",icon:"warning",dangerMode:!0,buttons:{cancel:!0,confirm:{text:"Yes, delete it!",closeModal:!1},purge:{text:"Umm, delete the uploads too please?",value:"purge",className:"swal-button--danger",closeModal:!1}}}).then((function(a){a&&axios.post("api/albums/delete",{id:e,purge:"purge"===a}).then((function(e){if(!1===e.data.success)return"No token provided"===e.data.description?page.verifyToken(page.token):Array.isArray(e.data.failed)&&e.data.failed.length?swal("An error occurred!","Unable to delete ","error"):swal("An error occurred!",e.data.description,"error");swal("Deleted!","Your album has been deleted.","success"),page.getAlbumsSidebar(),page.getAlbums()})).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")}))}))},submitAlbum:function(e){page.updateTrigger(e,"loading"),axios.post("api/albums",{name:document.querySelector("#albumName").value,description:document.querySelector("#albumDescription").value}).then((function(a){if(a){if(page.updateTrigger(e),!1===a.data.success)return"No token provided"===a.data.description?page.verifyToken(page.token):swal("An error occurred!",a.data.description,"error");swal("Woohoo!","Album was created successfully.","success"),page.getAlbumsSidebar(),page.getAlbums()}})).catch((function(a){return console.error(a),page.updateTrigger(e),swal("An error occurred!","There was an error with the request, please check the console for more information.","error")}))},getAlbumsSidebar:function(){axios.get("api/albums/sidebar").then((function(e){if(e){if(!1===e.data.success)return"No token provided"===e.data.description?page.verifyToken(page.token):swal("An error occurred!",e.data.description,"error");var a=document.querySelector("#albumsContainer"),n=a.querySelectorAll("li > a");if(n.length){for(var t=0;t\n \n \n \n \n ',page.fadeAndScroll(),page.updateTrigger(e.trigger,"active"),document.querySelector("#getNewToken").addEventListener("click",(function(e){var a=e.currentTarget;page.updateTrigger(a,"loading"),axios.post("api/tokens/change").then((function(e){if(!1===e.data.success)return"No token provided"===e.data.description?page.verifyToken(page.token):(page.updateTrigger(a),swal("An error occurred!",e.data.description,"error"));page.updateTrigger(a),swal({title:"Woohoo!",text:"Your token was successfully changed.",icon:"success"}).then((function(){axios.defaults.headers.common.token=e.data.token,localStorage[lsKeys.token]=e.data.token,page.token=e.data.token,page.changeToken()}))})).catch((function(e){return console.error(e),page.updateTrigger(a),swal("An error occurred!","There was an error with the request, please check the console for more information.","error")}))}))})).catch((function(a){return console.error(a),page.updateTrigger(e.trigger),swal("An error occurred!","There was an error with the request, please check the console for more information.","error")}))},changePassword:function(e){void 0===e&&(e={}),page.dom.innerHTML='\n
\n
\n \n
\n \n
\n
\n
\n \n
\n \n
\n
\n
\n
\n \n
\n
\n
\n ',page.fadeAndScroll(),page.updateTrigger(e.trigger,"active"),document.querySelector("#sendChangePassword").addEventListener("click",(function(e){document.querySelector("#password").value===document.querySelector("#passwordConfirm").value?page.sendNewPassword(document.querySelector("#password").value,e.currentTarget):swal({title:"Password mismatch!",text:"Your passwords do not match, please try again.",icon:"error"})}))},sendNewPassword:function(e,a){page.updateTrigger(a,"loading"),axios.post("api/password/change",{password:e}).then((function(e){if(page.updateTrigger(a),!1===e.data.success)return"No token provided"===e.data.description?page.verifyToken(page.token):swal("An error occurred!",e.data.description,"error");swal({title:"Woohoo!",text:"Your password was successfully changed.",icon:"success"}).then((function(){page.changePassword()}))})).catch((function(e){return console.error(e),page.updateTrigger(a),swal("An error occurred!","There was an error with the request, please check the console for more information.","error")}))},getUsers:function(e){if(void 0===e&&(e={}),page.updateTrigger(e.trigger,"loading"),void 0===e.pageNum&&(e.pageNum=0),!page.permissions.admin)return swal("An error occurred!","You can not do this!","error");var a="api/users/"+e.pageNum;axios.get(a).then((function(a){if(!1===a.data.success)return"No token provided"===a.data.description?page.verifyToken(page.token):(page.updateTrigger(e.trigger),swal("An error occurred!",a.data.description,"error"));if(e.pageNum&&0===a.data.users.length)return page.updateTrigger(e.trigger),swal("An error occurred!","There are no more users to populate page "+(e.pageNum+1)+".","error");page.currentView="users",page.cache.users={};var n=page.paginate(a.data.count,25,e.pageNum),t='\n
\n
\n
\n
\n
\n
\n \n
\n
\n \n
\n
\n
\n
\n
\n ',s=!1;page.dom.innerHTML="\n "+n+"\n "+t+'\n \n \n \n
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
IDUsernameUploadsUsageGroup
\n
\n
\n '+n+"\n ";for(var r=document.querySelector("#table"),i=0;i