filesafe/dist/js/dashboard.js
Bobby Wibowo ea37e0b7d3
Updated
Reduced album title max length from 280 to 70.
Existing albums with longer titles will have their titles truncated in
their public pages, but the original titles will still remain in db.

"Load images for preview" will now properly display its saved value.

Increased max parallel uploads to 10.

"yarn develop" will now also restart safe if some Nunjuck templates are
edited (_globals.njk, _layout.njk, and album.njk).

Better meta tags generation.

Bumped v1 version string.
2019-09-19 08:27:19 +07:00

3 lines
56 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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,albumTitleMaxLength:70,albumDescMaxLength:4e3,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.length;n++)a(n);page.permissions.moderator&&(document.querySelector("#itemLabelAdmin").classList.remove("is-hidden"),document.querySelector("#itemListAdmin").classList.remove("is-hidden")),document.querySelector("#itemLogout").innerHTML="Logout ( "+page.username+" )",document.querySelector("#dashboard").classList.remove("is-hidden"),page.getAlbumsSidebar(),"function"==typeof page.prepareShareX&&page.prepareShareX()},logout:function(){localStorage.removeItem(lsKeys.token),window.location="auth"},updateTrigger:function(e,a){if(e)if("loading"===a?page.menusContainer.classList.add("is-loading"):page.menusContainer.classList.remove("is-loading"),"loading"===a)e.classList.add("is-loading");else if("active"===a){if("LI"!==e.parentNode.tagName)return;for(var n=0;n<page.menus.length;n++)page.menus[n].classList.remove("is-active");e.classList.remove("is-loading"),e.classList.add("is-active")}else e.classList.remove("is-loading"),e.classList.remove("is-active")},getItemID:function(e){var a=e.parentNode;return e.parentNode.classList.contains("controls")&&(a=a.parentNode),parseInt(a.dataset.id)},domClick:function(e){var a=e.target;if(a&&(["I"].includes(a.tagName)&&["SPAN"].includes(a.parentNode.tagName)&&(a=a.parentNode),["SPAN"].includes(a.tagName)&&["A","BUTTON"].includes(a.parentNode.tagName)&&(a=a.parentNode),a.dataset&&a.dataset.action&&!a.hasAttribute("disabled"))){e.stopPropagation();var n=page.getItemID(a),t=a.dataset.action;switch(t){case"view-list":return page.setUploadsView("list",a);case"view-thumbs":return page.setUploadsView("thumbs",a);case"clear-selection":return page.clearSelection();case"add-selected-uploads-to-album":return page.addSelectedUploadsToAlbum();case"select":return page.select(a,e);case"select-all":return page.selectAll(a);case"add-to-album":return page.addToAlbum(n);case"delete-upload":return page.deleteUpload(n);case"bulk-delete-uploads":return page.bulkDeleteUploads();case"display-preview":return page.displayPreview(n);case"submit-album":return page.submitAlbum(a);case"edit-album":return page.editAlbum(n);case"delete-album":return page.deleteAlbum(n);case"get-new-token":return page.getNewToken(a);case"edit-user":return page.editUser(n);case"disable-user":return page.disableUser(n);case"filters-help":return page.filtersHelp(a);case"filter-uploads":return page.filterUploads(a);case"view-user-uploads":return page.viewUserUploads(n,a);case"page-ellipsis":return page.focusJumpToPage();case"page-prev":case"page-next":case"page-goto":case"jump-to-page":return page.switchPage(t,a)}}},fadeAndScroll:function(e){page.fadingIn&&(clearTimeout(page.fadingIn),page.dom.classList.remove("fade-in")),page.dom.classList.add("fade-in"),page.fadingIn=setTimeout((function(){page.dom.classList.remove("fade-in")}),500),page.dom.scrollIntoView(!0)},switchPage:function(e,a){var n=Object.assign({trigger:a},page.views[page.currentView]),t="users"===page.currentView?page.getUsers:page.getUploads;switch(e){case"page-prev":return n.pageNum=page.views[page.currentView].pageNum-1,n.pageNum<0?swal("An error occurred!","This is already the first page.","error"):t(n);case"page-next":return n.pageNum=page.views[page.currentView].pageNum+1,t(n);case"page-goto":return n.pageNum=parseInt(a.dataset.goto),t(n);case"jump-to-page":var s=document.querySelector("#jumpToPage");if(!s.checkValidity())return;var r=parseInt(s.value);return n.pageNum=isNaN(r)?0:r-1,n.pageNum<0&&(n.pageNum=0),t(n)}},focusJumpToPage:function(){var e=document.querySelector("#jumpToPage");e&&(e.focus(),e.select())},getUploads:function(e){if(void 0===e&&(e={}),void 0===e&&(e={}),(e.all||e.filters)&&!page.permissions.moderator)return swal("An error occurred!","You can not do this!","error");page.updateTrigger(e.trigger,"loading"),("number"!=typeof e.pageNum||e.pageNum<0)&&(e.pageNum=0);var a=void 0!==e.album?"api/album/"+e.album+"/"+e.pageNum:"api/uploads/"+e.pageNum,n={all:e.all?"1":"",filters:e.filters||""};axios.get(a,{headers:n}).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"));var n=a.data.files;if(e.pageNum&&0===n.length)return e.autoPage?(e.pageNum=Math.ceil(a.data.count/25)-1,page.getUploads(e)):(page.updateTrigger(e.trigger),swal("An error occurred!","There are no more uploads to populate page "+(e.pageNum+1)+".","error"));page.currentView=e.all?"uploadsAll":"uploads",page.cache.uploads={};var t=a.data.albums,s=a.data.users,r=a.data.basedomain,i=page.paginate(a.data.count,25,e.pageNum),l='<div class="column is-hidden-mobile"></div>';e.all&&(l='\n <div class="column">\n <form class="prevent-default">\n <div class="field has-addons">\n <div class="control is-expanded">\n <input id="filters" class="input is-small" type="text" placeholder="Filters" value="'+(e.filters||"")+'">\n </div>\n <div class="control">\n <button type="button" class="button is-small is-info" title="Help?" data-action="filters-help">\n <span class="icon">\n <i class="icon-help-circled"></i>\n </span>\n </button>\n </div>\n <div class="control">\n <button type="submit" class="button is-small is-info" title="Filter uploads" data-action="filter-uploads">\n <span class="icon">\n <i class="icon-filter"></i>\n </span>\n </button>\n </div>\n </div>\n </form>\n </div>\n ');for(var o='\n <div class="columns">\n '+l+'\n <div class="column is-one-quarter">\n <form class="prevent-default">\n <div class="field has-addons">\n <div class="control is-expanded">\n <input id="jumpToPage" class="input is-small" type="number" value="'+(e.pageNum+1)+'">\n </div>\n <div class="control">\n <button type="submit" class="button is-small is-info" title="Jump to page" data-action="jump-to-page">\n <span class="icon">\n <i class="icon-paper-plane"></i>\n </span>\n </button>\n </div>\n </div>\n </form>\n </div>\n </div>\n ',c='\n <div class="columns">\n <div class="column is-hidden-mobile"></div>\n <div class="column has-text-centered">\n <a class="button is-small is-danger" title="List view" data-action="view-list">\n <span class="icon">\n <i class="icon-th-list"></i>\n </span>\n </a>\n <a class="button is-small is-danger" title="Thumbs view" data-action="view-thumbs">\n <span class="icon">\n <i class="icon-th-large"></i>\n </span>\n </a>\n </div>\n <div class="column has-text-right">\n <a class="button is-small is-info" title="Clear selection" data-action="clear-selection">\n <span class="icon">\n <i class="icon-cancel"></i>\n </span>\n </a>\n '+(e.all?"":'\n <a class="button is-small is-warning" title="Bulk add to album" data-action="add-selected-uploads-to-album">\n <span class="icon">\n <i class="icon-plus"></i>\n </span>\n </a>')+'\n <a class="button is-small is-danger" title="Bulk delete" data-action="bulk-delete-uploads">\n <span class="icon">\n <i class="icon-trash"></i>\n </span>\n <span>Bulk delete</span>\n </a>\n </div>\n </div>\n ',d=!1,u=n.some((function(e){return void 0!==e.expirydate})),p=0;p<n.length;p++){n[p].file=r+"/"+n[p].name,n[p].thumb&&(n[p].thumb=r+"/"+n[p].thumb),n[p].type="other";var g=/.[\w]+(\?|$)/.exec(n[p].file),m=g&&g[0]?g[0].toLowerCase():null;page.imageExts.includes(m)?n[p].type="picture":page.videoExts.includes(m)&&(n[p].type="video"),page.cache.uploads[n[p].id]={name:n[p].name,thumb:n[p].thumb,original:n[p].file,type:n[p].type},n[p].prettyBytes=page.getPrettyBytes(parseInt(n[p].size)),n[p].prettyDate=page.getPrettyDate(new Date(1e3*n[p].timestamp)),u&&(n[p].prettyExpiryDate=n[p].expirydate?page.getPrettyDate(new Date(1e3*n[p].expirydate)):null),n[p].selected=page.selected[page.currentView].includes(n[p].id),n[p].selected||(d=!0),e.all?n[p].appendix=n[p].userid&&s[n[p].userid]||"":void 0===e.album&&(n[p].appendix=n[p].albumid&&t[n[p].albumid]||"")}if("thumbs"===page.views[page.currentView].type){page.dom.innerHTML="\n "+i+"\n "+o+"\n "+c+'\n <div id="table" class="columns is-multiline is-mobile is-centered">\n </div>\n <hr>\n '+i+"\n ";for(var h=document.querySelector("#table"),b=0;b<n.length;b++){var v=n[b],f=document.createElement("div");f.className="image-container column",f.dataset.id=v.id,void 0!==v.thumb?f.innerHTML='<a class="image" href="'+v.file+'" target="_blank" rel="noopener"><img alt="'+v.name+'" data-src="'+v.thumb+'"/></a>':f.innerHTML='<a class="image" href="'+v.file+'" target="_blank" rel="noopener"><h1 class="title">'+(v.extname||"N/A")+"</h1></a>",f.innerHTML+='\n <input type="checkbox" class="checkbox" title="Select" data-index="'+b+'" data-action="select"'+(v.selected?" checked":"")+'>\n <div class="controls">\n '+(v.thumb?'\n <a class="button is-small is-primary" title="Display preview" data-action="display-preview">\n <span class="icon">\n <i class="'+("other"!==v.type?"icon-"+v.type:"icon-doc-inv")+'"></i>\n </span>\n </a>':"")+'\n <a class="button is-small is-info clipboard-js" title="Copy link to clipboard" data-clipboard-text="'+v.file+'">\n <span class="icon">\n <i class="icon-clipboard"></i>\n </span>\n </a>\n <a class="button is-small is-warning" title="Add to album" data-action="add-to-album">\n <span class="icon">\n <i class="icon-plus"></i>\n </span>\n </a>\n <a class="button is-small is-danger" title="Delete" data-action="delete-upload">\n <span class="icon">\n <i class="icon-trash"></i>\n </span>\n </a>\n </div>\n <div class="details">\n <p><span class="name">'+v.name+"</span></p>\n <p>"+(v.appendix?"<span>"+v.appendix+"</span> ":"")+v.prettyBytes+"</p>\n "+(u&&v.prettyExpiryDate?'\n <p class="expirydate">EXP: '+v.prettyExpiryDate+"</p>":"")+"\n </div>\n ",h.appendChild(f),page.checkboxes[page.currentView]=h.querySelectorAll('.checkbox[data-action="select"]'),page.lazyLoad.update()}}else{page.dom.innerHTML="\n "+i+"\n "+o+"\n "+c+'\n <div class="table-container">\n <table class="table is-narrow is-fullwidth is-hoverable">\n <thead>\n <tr>\n <th><input id="selectAll" class="checkbox" type="checkbox" title="Select all" data-action="select-all"></th>\n <th>File</th>\n '+(void 0===e.album?"<th>"+(e.all?"User":"Album")+"</th>":"")+"\n <th>Size</th>\n "+(e.all?"<th>IP</th>":"")+"\n <th>Date</th>\n "+(u?"<th>Expiry date</th>":"")+'\n <th></th>\n </tr>\n </thead>\n <tbody id="table">\n </tbody>\n </table>\n </div>\n <hr>\n '+i+"\n ";for(var w=document.querySelector("#table"),y=0;y<n.length;y++){var k=n[y],x=document.createElement("tr");x.dataset.id=k.id,x.innerHTML='\n <td class="controls"><input type="checkbox" class="checkbox" title="Select" data-index="'+y+'" data-action="select"'+(k.selected?" checked":"")+'></td>\n <th><a href="'+k.file+'" target="_blank" rel="noopener" title="'+k.file+'">'+k.name+"</a></th>\n "+(void 0===e.album?"<th>"+k.appendix+"</th>":"")+"\n <td>"+k.prettyBytes+"</td>\n "+(e.all?"<td>"+(k.ip||"")+"</td>":"")+"\n <td>"+k.prettyDate+"</td>\n "+(u?"<td>"+(k.prettyExpiryDate||"-")+"</td>":"")+'\n <td class="controls has-text-right">\n <a class="button is-small is-primary" title="'+(k.thumb?"Display preview":"File can't be previewed")+'" data-action="display-preview"'+(k.thumb?"":" disabled")+'>\n <span class="icon">\n <i class="'+("other"!==k.type?"icon-"+k.type:"icon-doc-inv")+'"></i>\n </span>\n </a>\n <a class="button is-small is-info clipboard-js" title="Copy link to clipboard" data-clipboard-text="'+k.file+'">\n <span class="icon">\n <i class="icon-clipboard"></i>\n </span>\n </a>\n '+(e.all?"":'\n <a class="button is-small is-warning" title="Add to album" data-action="add-to-album">\n <span class="icon">\n <i class="icon-plus"></i>\n </span>\n </a>')+'\n <a class="button is-small is-danger" title="Delete" data-action="delete-upload">\n <span class="icon">\n <i class="icon-trash"></i>\n </span>\n </a>\n </td>\n ',w.appendChild(x),page.checkboxes[page.currentView]=w.querySelectorAll('.checkbox[data-action="select"]')}}var T=document.querySelector("#selectAll");T&&!d&&(T.checked=!0,T.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]))},displayPreview:function(e){var a=page.cache.uploads[e];if(a.thumb){var n=document.createElement("div");if(n.innerHTML='\n <div class="field has-text-centered">\n <label class="label">'+a.name+'</label>\n <div class="controls swal-display-thumb-container">\n <img id="swalThumb" src="'+a.thumb+'">\n </div>\n </div>\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 <div class="field has-text-centered">\n <div class="controls">\n <a id="swalOriginal" type="button" class="button is-info is-fullwidth" data-original="'+a.original+'">\n <span class="icon">\n <i class="icon-arrows-cw"></i>\n </span>\n <span>Load original</span>\n </a>\n </div>\n </div>\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 <span class="icon">\n <i class="icon-block"></i>\n </span>\n <span>Unable to load original</span>\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;a<page.checkboxes[page.currentView].length;a++){var n=page.getItemID(page.checkboxes[page.currentView][a]);isNaN(n)||page.checkboxes[page.currentView][a].checked!==e.checked&&(page.checkboxes[page.currentView][a].checked=e.checked,page.checkboxes[page.currentView][a].checked?page.selected[page.currentView].push(n):page.selected[page.currentView].splice(page.selected[page.currentView].indexOf(n),1))}page.selected[page.currentView].length?localStorage[lsKeys.selected[page.currentView]]=JSON.stringify(page.selected[page.currentView]):delete localStorage[lsKeys.selected[page.currentView]],e.title=e.checked?"Unselect all":"Select all"},selectInBetween:function(e,a){var n=parseInt(e.dataset.index),t=parseInt(a.dataset.index);if(!(Math.abs(n-t)<2))for(var s=0;s<page.checkboxes[page.currentView].length;s++)if(n>t&&s>t&&s<n||n<t&&s>n&&s<t){var r=page.checkboxes[page.currentView][s].checked=a.checked,i=page.getItemID(page.checkboxes[page.currentView][s]);!page.selected[page.currentView].includes(i)&&r?page.selected[page.currentView].push(i):page.selected[page.currentView].includes(i)&&!r&&page.selected[page.currentView].splice(page.selected[page.currentView].indexOf(i),1)}},select:function(e,a){var n=page.getItemID(e);if(!isNaN(n)){var t=page.lastSelected[page.currentView];a.shiftKey&&t?(page.selectInBetween(e,t),e.checked=t.checked):page.lastSelected[page.currentView]=e,!page.selected[page.currentView].includes(n)&&e.checked?page.selected[page.currentView].push(n):page.selected[page.currentView].includes(n)&&!e.checked&&page.selected[page.currentView].splice(page.selected[page.currentView].indexOf(n),1),page.selected[page.currentView].length?localStorage[lsKeys.selected[page.currentView]]=JSON.stringify(page.selected[page.currentView]):delete localStorage[lsKeys.selected[page.currentView]]}},clearSelection:function(){var e=page.selected[page.currentView],a="users"===page.currentView?"users":"uploads",n=e.length;if(!n)return swal("An error occurred!","You have not selected any "+a+".","error");var t=1===n?a.substring(0,a.length-1):a;return swal({title:"Are you sure?",text:"You are going to unselect "+n+" "+t+".",buttons:!0}).then((function(e){if(e){for(var a=page.checkboxes[page.currentView],s=0;s<a.length;s++)a[s].checked&&(a[s].checked=!1);page.selected[page.currentView]=[],delete localStorage[lsKeys.selected[page.currentView]];var r=document.querySelector("#selectAll");return r&&(r.checked=!1),swal("Cleared selection!","Unselected "+n+" "+t+".","success")}}))},filtersHelp:function(e){var a=document.createElement("div");a.style="text-align: left",a.innerHTML='\n This supports 3 filter keys, namely <b>user</b> (username), <b>ip</b> and <b>name</b> (upload name).\n Each key can be specified more than once.\n Backlashes should be used if the usernames have spaces.\n There are also 2 additional flags, namely <b>-user</b> and <b>-ip</b>, which will match uploads by non-registered users and have no IPs respectively.\n\n How does it work?\n First, it will filter uploads matching ANY of the supplied <b>user</b> or <b>ip</b> keys.\n Then, it will refine the matches using the supplied <b>name</b> keys.\n\n Examples:\n\n Uploads from user with username "demo":\n <code>user:demo</code>\n\n Uploads from users with username either "John Doe" OR "demo":\n <code>user:John\\ Doe user:demo</code>\n\n Uploads from IP "127.0.0.1" AND which upload names match "*.rar" OR "*.zip":\n <code>ip:127.0.0.1 name:*.rar name:*.zip</code>\n\n Uploads from user with username "test" OR from non-registered users:\n <code>user:test -user</code>\n '.trim().replace(/^ {6}/gm,"").replace(/\n/g,"<br>"),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="<br><b>Hint:</b> You can use this feature to delete uploads by other users."),page.dom.innerHTML='\n <form class="prevent-default">\n <div class="field">\n <label class="label">Upload names:</label>\n <div class="control">\n <textarea id="bulkDeleteNames" class="textarea"></textarea>\n </div>\n <p class="help">Separate each entry with a new line.'+a+'</p>\n </div>\n <div class="field">\n <div class="control">\n <button type="submit" id="submitBulkDelete" class="button is-danger is-fullwidth">\n <span class="icon">\n <i class="icon-trash"></i>\n </span>\n <span>Bulk delete</span>\n </button>\n </div>\n </div>\n </form>\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="<p>You won't be able to recover "+n.replace(/^(\d*)(.*)/,"<b>$1</b>$2")+"!</p>";e.all&&(t+="\n<p><b>Warning:</b> You may be nuking "+(1===a?"an upload":"some uploads")+" by "+(1===a?"another user":"other users")+"!</p>");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<e.values.length?swal("Warning!","From "+n+", unable to delete "+s.length+" of them.","warning"):swal("Deleted!",n+" "+(1===a?"has":"have")+" been deleted.","success"),"function"==typeof e.cb&&e.cb(s)}})).catch((function(e){console.error(e),swal("An error occurred!","There was an error with the request, please check the console for more information.","error")}))}))},addSelectedUploadsToAlbum:function(){if("uploads"===page.currentView){if(!page.selected[page.currentView].length)return swal("An error occurred!","You have not selected any uploads.","error");page.addUploadsToAlbum(page.selected[page.currentView],(function(e){e&&(e.length?page.selected[page.currentView]=page.selected[page.currentView].filter((function(a){return e.includes(a)})):page.selected[page.currentView]=[],localStorage[lsKeys.selected[page.currentView]]=JSON.stringify(page.selected[page.currentView]),page.getUploads(page.views[page.currentView]))}))}},addToAlbum:function(e){page.addUploadsToAlbum([e],(function(e){e&&page.getUploads(page.views[page.currentView])}))},addUploadsToAlbum:function(e,a){var n=e.length,t=document.createElement("div");t.innerHTML='\n <div class="field has-text-centered">\n <p>You are about to add <b>'+n+"</b> upload"+(1===n?"":"s")+' to an album.</p>\n <p><b>If an upload is already in an album, it will be moved.</b></p>\n </div>\n <div class="field">\n <div class="control">\n <div class="select is-fullwidth">\n <select id="swalAlbum" disabled>\n <option value="-1">Remove from album</option>\n <option value="" selected disabled>Fetching albums list…</option>\n </select>\n </div>\n </div>\n </div>\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'<option value="'+e.id+'">'+e.name+"</option>"})).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 <h2 class="subtitle">Create new album</h2>\n <form class="prevent-default">\n <div class="field">\n <div class="control">\n <input id="albumName" class="input" type="text" placeholder="Name" maxlength="'+page.albumTitleMaxLength+'">\n </div>\n <p class="help">Max length is '+page.albumTitleMaxLength+' characters.</p>\n </div>\n <div class="field">\n <div class="control">\n <textarea id="albumDescription" class="textarea" placeholder="Description" rows="1" maxlength="'+page.albumDescMaxLength+'"></textarea>\n </div>\n <p class="help">Max length is '+page.albumDescMaxLength+' characters.</p>\n </div>\n <div class="field">\n <div class="control">\n <button type="submit" id="submitAlbum" class="button is-info is-fullwidth" data-action="submit-album">\n <span class="icon">\n <i class="icon-paper-plane"></i>\n </span>\n <span>Create</span>\n </button>\n </div>\n </div>\n </form>\n <hr>\n <h2 class="subtitle">List of albums</h2>\n <div class="table-container">\n <table class="table is-fullwidth is-hoverable">\n <thead>\n <tr>\n <th>ID</th>\n <th>Name</th>\n <th>Files</th>\n <th>Created at</th>\n <th>Public link</th>\n <th></th>\n </tr>\n </thead>\n <tbody id="table">\n </tbody>\n </table>\n </div>\n ';for(var n=a.data.homeDomain,t=document.querySelector("#table"),s=0;s<a.data.albums.length;s++){var r=a.data.albums[s],i=n+"/a/"+r.identifier;r.prettyDate=page.getPrettyDate(new Date(1e3*r.timestamp)),page.cache.albums[r.id]={name:r.name,download:r.download,public:r.public,description:r.description};var l=document.createElement("tr");l.innerHTML="\n <th>"+r.id+"</th>\n <th>"+r.name+"</th>\n <th>"+r.files+"</th>\n <td>"+r.prettyDate+"</td>\n <td><a "+(r.public?'href="'+i+'"':'class="is-linethrough"')+' target="_blank" rel="noopener">'+i+'</a></td>\n <td class="has-text-right" data-id="'+r.id+'">\n <a class="button is-small is-primary" title="Edit album" data-action="edit-album">\n <span class="icon is-small">\n <i class="icon-pencil"></i>\n </span>\n </a>\n <a class="button is-small is-info clipboard-js" title="Copy link to clipboard" '+(r.public?'data-clipboard-text="'+i+'"':"disabled")+'>\n <span class="icon is-small">\n <i class="icon-clipboard"></i>\n </span>\n </a>\n <a class="button is-small is-warning" title="Download album" '+(r.download?'href="api/album/zip/'+r.identifier+"?v="+r.editedAt+'"':"disabled")+'>\n <span class="icon is-small">\n <i class="icon-download"></i>\n </span>\n </a>\n <a class="button is-small is-danger" title="Delete album" data-action="delete-album">\n <span class="icon is-small">\n <i class="icon-trash"></i>\n </span>\n </a>\n </td>\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 <div class="field">\n <div class="controls">\n <input id="swalName" class="input" type="text" placeholder="Name" maxlength="'+page.albumTitleMaxLength+'" value="'+(a.name||"").substring(0,page.albumTitleMaxLength)+'">\n </div>\n <p class="help">Max length is '+page.albumTitleMaxLength+' characters.</p>\n </div>\n <div class="field">\n <div class="control">\n <textarea id="swalDescription" class="textarea" placeholder="Description" rows="2" maxlength="'+page.albumDescMaxLength+'">'+(a.description||"").substring(0,page.albumDescMaxLength)+'</textarea>\n </div>\n <p class="help">Max length is '+page.albumDescMaxLength+' characters.</p>\n </div>\n <div class="field">\n <div class="control">\n <label class="checkbox">\n <input id="swalDownload" type="checkbox" '+(a.download?"checked":"")+'>\n Enable download\n </label>\n </div>\n </div>\n <div class="field">\n <div class="control">\n <label class="checkbox">\n <input id="swalPublic" type="checkbox" '+(a.public?"checked":"")+'>\n Enable public link\n </label>\n </div>\n </div>\n <div class="field">\n <div class="control">\n <label class="checkbox">\n <input id="swalRequestLink" type="checkbox">\n Request new public link\n </label>\n </div>\n </div>\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.trim(),description:document.querySelector("#albumDescription").value.trim()}).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.length;t++)page.menus.splice(page.menus.indexOf(n[t]),1);a.innerHTML=""}if(void 0!==e.data.albums)for(var s=0;s<e.data.albums.length;s++){var r=e.data.albums[s],i=document.createElement("li"),l=document.createElement("a");l.id=r.id,l.innerHTML=r.name,l.className="is-relative",l.addEventListener("click",(function(e){page.getUploads({album:parseInt(e.currentTarget.id),trigger:e.currentTarget})})),page.menus.push(l),i.appendChild(l),a.appendChild(i)}}})).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")}))},changeToken:function(e){void 0===e&&(e={}),page.updateTrigger(e.trigger,"loading"),axios.get("api/tokens").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"));page.dom.innerHTML='\n <div class="field">\n <label class="label">Your current token:</label>\n <div class="field">\n <div class="control">\n <input id="token" readonly class="input" type="text" placeholder="Your token" value="'+a.data.token+'">\n </div>\n </div>\n </div>\n <div class="field">\n <div class="control">\n <a id="getNewToken" class="button is-info is-fullwidth">\n <span class="icon">\n <i class="icon-arrows-cw"></i>\n </span>\n <span>Request new token</span>\n </a>\n </div>\n </div>\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 <form class="prevent-default">\n <div class="field">\n <label class="label">New password:</label>\n <div class="control">\n <input id="password" class="input" type="password" min="6" max="64">\n </div>\n </div>\n <div class="field">\n <label class="label">Re-type new password:</label>\n <div class="control">\n <input id="passwordConfirm" class="input" type="password" min="6" max="64">\n </div>\n </div>\n <div class="field">\n <div class="control">\n <button type="submit" id="sendChangePassword" class="button is-info is-fullwidth">\n <span class="icon">\n <i class="icon-paper-plane"></i>\n </span>\n <span>Set new password</span>\n </button>\n </div>\n </div>\n </form>\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 <div class="columns">\n <div class="column is-hidden-mobile"></div>\n <div class="column is-one-quarter">\n <form class="prevent-default">\n <div class="field has-addons">\n <div class="control is-expanded">\n <input id="jumpToPage" class="input is-small" type="number" value="'+(e.pageNum+1)+'">\n </div>\n <div class="control">\n <button type="submit" class="button is-small is-info" title="Jump to page" data-action="jump-to-page">\n <span class="icon">\n <i class="icon-paper-plane"></i>\n </span>\n </button>\n </div>\n </div>\n </form>\n </div>\n </div>\n ',s=!1;page.dom.innerHTML="\n "+n+"\n "+t+'\n \n <div class="columns is-hidden">\n <div class="column is-hidden-mobile"></div>\n <div class="column has-text-right">\n <a class="button is-small is-info" title="Clear selection" data-action="clear-selection">\n <span class="icon">\n <i class="icon-cancel"></i>\n </span>\n </a>\n <a class="button is-small is-warning" title="Bulk disable (WIP)" data-action="bulk-disable-users" disabled>\n <span class="icon">\n <i class="icon-hammer"></i>\n </span>\n <span>Bulk disable</span>\n </a>\n <a class="button is-small is-danger" title="Bulk delete (WIP)" data-action="bulk-delete-users" disabled>\n <span class="icon">\n <i class="icon-trash"></i>\n </span>\n <span>Bulk delete</span>\n </a>\n </div>\n </div>\n \n <div class="table-container">\n <table class="table is-narrow is-fullwidth is-hoverable">\n <thead>\n <tr>\n <th class="is-hidden"><input id="selectAll" class="checkbox" type="checkbox" title="Select all" data-action="select-all"></th>\n <th>ID</th>\n <th>Username</th>\n <th>Uploads</th>\n <th>Usage</th>\n <th>Group</th>\n <th></th>\n </tr>\n </thead>\n <tbody id="table">\n </tbody>\n </table>\n </div>\n <hr>\n '+n+"\n ";for(var r=document.querySelector("#table"),i=0;i<a.data.users.length;i++){var l=a.data.users[i],o=page.selected.users.includes(l.id);o||(s=!0);for(var c=null,d=Object.keys(l.groups),u=0;u<d.length&&l.groups[d[u]];u++)c=d[u];var p=!1!==l.enabled&&0!==l.enabled;page.cache.users[l.id]={username:l.username,groups:l.groups,enabled:p,displayGroup:c};var g=document.createElement("tr");g.dataset.id=l.id,g.innerHTML='\n <td class="controls is-hidden"><input type="checkbox" class="checkbox" title="Select" data-action="select"'+(o?" checked":"")+"></td>\n <th>"+l.id+"</th>\n <th"+(p?"":' class="is-linethrough"')+">"+l.username+"</td>\n <th>"+l.uploads+"</th>\n <td>"+page.getPrettyBytes(l.usage)+"</td>\n <td>"+c+'</td>\n <td class="controls has-text-right">\n <a class="button is-small is-primary" title="Edit user" data-action="edit-user">\n <span class="icon">\n <i class="icon-pencil"></i>\n </span>\n </a>\n <a class="button is-small is-info" title="'+(l.uploads?"View uploads":"User doesn't have uploads")+'" data-action="view-user-uploads" '+(l.uploads?"":"disabled")+'>\n <span class="icon">\n <i class="icon-docs"></i>\n </span>\n </a>\n <a class="button is-small is-warning" title="'+(p?"Disable user":"User is disabled")+'" data-action="disable-user" '+(p?"":"disabled")+'>\n <span class="icon">\n <i class="icon-hammer"></i>\n </span>\n </a>\n <a class="button is-small is-danger is-hidden" title="Delete user (WIP)" data-action="delete-user" disabled>\n <span class="icon">\n <i class="icon-trash"></i>\n </span>\n </a>\n </td>\n ',r.appendChild(g),page.checkboxes.users=r.querySelectorAll('.checkbox[data-action="select"]')}var m=document.querySelector("#selectAll");m&&!s&&(m.checked=!0,m.title="Unselect all"),page.fadeAndScroll(),page.updateTrigger(e.trigger,"active"),page.views.users.pageNum=a.data.users.length?e.pageNum:0})).catch((function(a){return page.updateTrigger(e.trigger),console.error(a),swal("An error occurred!","There was an error with the request, please check the console for more information.","error")}))},editUser:function(e){var a=page.cache.users[e];if(a){var n=Object.keys(page.permissions).map((function(e,n,t){return'<option value="'+e+'"'+(e===a.displayGroup?" selected":"")+(!(t[n+1]&&page.permissions[t[n+1]])?" disabled":"")+">"+e+"</option>"})).join("\n"),t=document.createElement("div");t.innerHTML='\n <div class="field">\n <label class="label">Username</label>\n <div class="controls">\n <input id="swalUsername" class="input" type="text" value="'+(a.username||"")+'">\n </div>\n </div>\n <div class="field">\n <label class="label">User group</label>\n <div class="control">\n <div class="select is-fullwidth">\n <select id="swalGroup">\n '+n+'\n </select>\n </div>\n </div>\n </div>\n <div class="field">\n <div class="control">\n <label class="checkbox">\n <input id="swalEnabled" type="checkbox" '+(a.enabled?"checked":"")+'>\n Enabled\n </label>\n </div>\n </div>\n <div class="field">\n <div class="control">\n <label class="checkbox">\n <input id="swalResetPassword" type="checkbox">\n Reset password\n </label>\n </div>\n </div>\n ',swal({title:"Edit user",icon:"info",content:t,buttons:{cancel:!0,confirm:{closeModal:!1}}}).then((function(n){n&&axios.post("api/users/edit",{id:e,username:document.querySelector("#swalUsername").value,group:document.querySelector("#swalGroup").value,enabled:document.querySelector("#swalEnabled").checked,resetPassword:document.querySelector("#swalResetPassword").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");if(e.data.password){var n=document.createElement("div");n.innerHTML="\n <p><b>"+a.username+"</b>'s new password is:</p>\n <p><code>"+e.data.password+"</code></p>\n ",swal({title:"Success!",icon:"success",content:n})}else e.data.update&&e.data.update.username!==a.username?swal("Success!",a.username+" was renamed into: "+e.data.update.name+".","success"):swal("Success!","The user was edited!","success");page.getUsers(page.views.users)}})).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")}))}))}},disableUser:function(e){var a=page.cache.users[e];if(a&&a.enabled){var n=document.createElement("div");n.innerHTML="You will be disabling a user with the username <b>"+page.cache.users[e].username+"</b>.",swal({title:"Are you sure?",icon:"warning",content:n,dangerMode:!0,buttons:{cancel:!0,confirm:{text:"Yes, disable them!",closeModal:!1}}}).then((function(a){a&&axios.post("api/users/disable",{id:e}).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");swal("Success!","The user has been disabled.","success"),page.getUsers(page.views.users)}})).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")}))}))}},paginate:function(e,a,n){n+=1;var t=Math.ceil(e/a),s="",r=function(e,a){for(var t=e;t<=a;++t)s+='<li><a class="button pagination-link '+(t===n?" is-current":"")+'" aria-label="Goto page '+t+'" data-action="page-goto" data-goto="'+(t-1)+'">'+t+"</a></li>"},i=function(){s+='\n <li><a class="button pagination-link" aria-label="Goto page 1" data-action="page-goto" data-goto="0">1</a></li>\n <li data-action="page-ellipsis"><span class="pagination-ellipsis">&hellip;</span></li>\n '},l=function(){s+='\n <li data-action="page-ellipsis"><span class="pagination-ellipsis">&hellip;</span></li>\n <li><a class="button pagination-link" aria-label="Goto page '+t+'" data-action="page-goto" data-goto="'+(t-1)+'">'+t+"</a></li>\n "};return 7>=t?r(1,t):n<6?(r(1,6),l()):n>t-6+1?(i(),r(t-6+1,t)):(i(),r(n-3+1,n+3-1),l()),'\n <nav class="pagination is-centered is-small">\n <a class="button pagination-previous" data-action="page-prev">Previous</a>\n <a class="button pagination-next" data-action="page-next">Next page</a>\n <ul class="pagination-list">'+s+"</ul>\n </nav>\n "},getStatistics:function(e){if(void 0===e&&(e={}),!page.permissions.admin)return swal("An error occurred!","You can not do this!","error");page.updateTrigger(e.trigger,"loading");axios.get("api/stats").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"));for(var n="",t=Object.keys(a.data.stats),s=0;s<t.length;s++){var r="";if(a.data.stats[t[s]])try{for(var i=a.data.stats[t[s]]._types||{},l=Object.keys(a.data.stats[t[s]]),o=0;o<l.length;o++)if(!/^_/.test(l[o])){var c=a.data.stats[t[s]][l[o]],d=c;(i.number||[]).includes(l[o])&&(d=c.toLocaleString()),(i.byte||[]).includes(l[o])&&(d=page.getPrettyBytes(c)),(i.byteUsage||[]).includes(l[o])&&(d=page.getPrettyBytes(c.used)+" / "+page.getPrettyBytes(c.total)+" ("+Math.round(c.used/c.total*100)+"%)"),r+="\n <tr>\n <th>"+l[o].replace(/([A-Z])/g," $1").toUpperCase()+"</th>\n <td>"+d+"</td>\n </tr>\n "}}catch(e){console.error(e),r="\n <tr>\n <td>Error parsing response. Try again?</td>\n <td></td>\n </tr>\n "}else r+="\n <tr>\n <td>Generating, please try again later…</td>\n <td></td>\n </tr>\n ";n+='\n <div class="table-container">\n <table id="statistics" class="table is-fullwidth is-hoverable">\n <thead>\n <tr>\n <th>'+t[s].toUpperCase()+"</th>\n <td></td>\n </tr>\n </thead>\n <tbody>\n "+r+"\n </tbody>\n </table>\n </div>\n "}page.dom.innerHTML=n,page.fadeAndScroll(),page.updateTrigger(e.trigger,"active")})).catch((function(a){console.error(a),page.updateTrigger(e.trigger);var n=a.response.data&&a.response.data.description?a.response.data&&a.response.data.description:"There was an error with the request, please check the console for more information.";return swal("An error occurred!",n,"error")}))}};window.onload=function(){"function"!=typeof Object.assign&&Object.defineProperty(Object,"assign",{value:function(e,a){"use strict";var n=arguments;if(null==e)throw new TypeError("Cannot convert undefined or null to object");for(var t=Object(e),s=1;s<arguments.length;s++){var r=n[s];if(null!=r)for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t},writable:!0,configurable:!0}),"ontouchstart"in document.documentElement||document.documentElement.classList.add("no-touch");for(var e=["uploads","uploadsAll","users"],a=0;a<e.length;a++){var n=localStorage[lsKeys.selected[e[a]]];n&&(page.selected[e[a]]=JSON.parse(n))}page.preparePage(),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",(function(e){return console.error(e),swal("An error occurred!","There was an error when trying to copy the link to clipboard, please check the console for more information.","error")})),page.lazyLoad=new LazyLoad};
//# sourceMappingURL=dashboard.js.map