filesafe/dist/js/dashboard.js

3 lines
80 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",albums:"selectedAlbums",albumsAll:"selectedAlbumsAll",users:"selectedUsers"},originalNames:{uploads:"originalNames",uploadsAll:"originalNamesAll"}},page={section:null,dom:null,token:localStorage[lsKeys.token],username:null,permissions:null,menusContainer:null,menus:[],currentView:null,views:{uploads:{type:localStorage[lsKeys.viewType.uploads],originalNames:"1"===localStorage[lsKeys.originalNames.uploads],album:null,pageNum:null},uploadsAll:{type:localStorage[lsKeys.viewType.uploadsAll],originalNames:"1"===localStorage[lsKeys.originalNames.uploadsAll],filters:null,pageNum:null,all:!0},albums:{filters:null,pageNum:null},albumsAll:{filters:null,pageNum:null,all:!0},users:{filters:null,pageNum:null}},prevPageNums:{uploads:null,uploadsAll:null,albums:null,albumsAll:null,users:null},selected:{uploads:[],uploadsAll:[],albums:[],albumsAll:[],users:[]},checkboxes:[],lastSelected:[],selectAlbumContainer:null,cache:{},clipboardJS:null,lazyLoad:null,albumsSidebarCollapse:null,albumsSidebarCollapsible:null,imageExts:[".gif",".jpeg",".jpg",".png",".svg",".tif",".tiff",".webp"],videoExts:[".3g2",".3gp",".asf",".avchd",".avi",".divx",".evo",".flv",".h264",".h265",".hevc",".m2p",".m2ts",".m4v",".mk3d",".mkv",".mov",".mp4",".mpeg",".mpg",".mxf",".ogg",".ogv",".ps",".qt",".rmvb",".ts",".vob",".webm",".wmv"],audioExts:[".flac",".mp3",".wav",".wma"],isSomethingLoading:!1,fadingIn:null,albumTitleMaxLength:70,albumDescMaxLength:4e3,cloudflareErrors:{520:"Unknown Error",521:"Web Server Is Down",522:"Connection Timed Out",523:"Origin Is Unreachable",524:"A Timeout Occurred",525:"SSL Handshake Failed",526:"Invalid SSL Certificate",527:"Railgun Error",530:"Origin DNS Error"},unhide:function(){document.querySelector("#loader").classList.add("is-hidden"),page.section.classList.remove("is-hidden")},onError:function(e){console.error(e);var a=document.createElement("div");return a.innerHTML="\n <p><code>"+e.toString()+"</code></p>\n <p>Please check your console for more information.</p>\n ",swal({title:"An error occurred!",icon:"error",content:a})},onAxiosError:function(e){var a=page.cloudflareErrors[e.response.status]||e.response.statusText,t=e.response.data&&e.response.data.description?e.response.data.description:"There was an error with the request.\nPlease check the console for more information.";return swal(e.response.status+" "+a,t,"error")},preparePage:function(){page.token?page.verifyToken(page.token):window.location="auth"},checkClientVersion:function(e){var a=document.querySelector("#mainScript").src.match(/\?_=(\d+)$/);if(a&&a[1]&&a[1]!==e)return swal({title:"Update detected!",text:"Client assets have been updated. Reload to display the latest version?",icon:"info",buttons:{confirm:{text:"Reload",closeModal:!1}}}).then((function(){window.location.reload()}))},verifyToken:function(e){axios.post("api/tokens/verify",{token:e}).then((function(a){axios.defaults.headers.common.token=e,localStorage[lsKeys.token]=e,a.data.version&&page.checkClientVersion(a.data.version),page.token=e,page.username=a.data.username,page.permissions=a.data.permissions,page.prepareDashboard()})).catch((function(e){return page.onAxiosError(e).then((function(){e.response.data&&10001===e.response.data.code&&(localStorage.removeItem(lsKeys.token),window.location="auth")}))}))},prepareDashboard:function(){page.section=document.querySelector("#dashboard"),page.dom=page.section.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:"#itemManageYourAlbums",onclick:page.getAlbums},{selector:"#itemManageToken",onclick:page.changeToken},{selector:"#itemChangePassword",onclick:page.changePassword},{selector:"#itemLogout",onclick:page.logout},{selector:"#itemManageUploads",onclick:page.getUploads,params:{all:!0},group:"moderator"},{selector:"#itemManageAlbums",onclick:page.getAlbums,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 t=document.querySelector(e[a].selector);t.addEventListener("click",(function(t){if(page.isSomethingLoading)return page.warnSomethingLoading();e[a].onclick.call(null,Object.assign(e[a].params||{},{trigger:t.currentTarget,forceScroll:!0}))})),t.classList.remove("is-hidden"),page.menus.push(t)}},t=0;t<e.length;t++)a(t);page.permissions.moderator&&(document.querySelector("#itemLabelAdmin").classList.remove("is-hidden"),document.querySelector("#itemListAdmin").classList.remove("is-hidden")),document.querySelector("#itemLogout").innerHTML="Logout ( "+page.username+" )",page.unhide(),page.getAlbumsSidebar(),"function"==typeof page.prepareShareX&&page.prepareShareX()},logout:function(e){page.updateTrigger(e.trigger,"active"),localStorage.removeItem(lsKeys.token),window.location="auth"},warnSomethingLoading:function(){swal("Please wait!","Something else is still loading…","warning",{buttons:!1,timer:3e3})},updateTrigger:function(e,a){if(e)if("loading"===a?(page.isSomethingLoading=!0,page.section.classList.add("is-loading")):(page.section.classList.remove("is-loading"),page.isSomethingLoading=!1),"loading"===a)e.classList.add("is-loading");else if("active"===a){if("LI"===e.parentNode.tagName&&!e.className.includes("pagination-link")){for(var t=0;t<page.menus.length;t++)page.menus[t].classList.remove("is-active");e.classList.add("is-active")}e.classList.remove("is-loading")}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 t=page.getItemID(a),n=a.dataset.action;switch(n){case"view-list":return page.setUploadsView("list",a);case"view-thumbs":return page.setUploadsView("thumbs",a);case"toggle-original-names":return page.toggleOriginalNames(a);case"add-to-album":return page.addToAlbum(t);case"delete-upload":return page.deleteUpload(t);case"add-selected-uploads-to-album":return page.addSelectedUploadsToAlbum();case"bulk-delete-uploads":return page.bulkDeleteUploads();case"display-preview":return page.displayPreview(t);case"upload-filters-help":return page.uploadFiltersHelp(a);case"filter-uploads":return page.filterUploads(a);case"submit-album":return page.submitAlbum(a);case"edit-album":return page.editAlbum(t);case"disable-album":return page.disableAlbum(t);case"delete-album":return page.deleteAlbum(t);case"view-album-uploads":return page.viewAlbumUploads(t,a);case"create-user":return page.createUser();case"edit-user":return page.editUser(t);case"disable-user":return page.disableUser(t);case"delete-user":return page.deleteUser(t);case"view-user-uploads":return page.viewUserUploads(t,a);case"get-new-token":return page.getNewToken(a);case"clear-selection":return page.clearSelection();case"select":return page.select(a,e);case"select-all":return page.selectAll(a);case"page-ellipsis":return page.focusJumpToPage(a);case"page-prev":case"page-next":case"page-goto":case"jump-to-page":return page.switchPage(n,a)}}},fadeInDom:function(e){page.fadingIn&&(clearTimeout(page.fadingIn),page.dom.classList.remove("fade-in")),e||(page.dom.classList.add("fade-in"),page.fadingIn=setTimeout((function(){page.dom.classList.remove("fade-in")}),500))},scrollToDom:function(e){page.dom.scrollIntoView({behavior:e?"auto":"smooth",block:"start",inline:"nearest"})},getByView:function(e,a){switch(e){case"uploads":case"uploadsAll":return{type:"uploads",func:page.getUploads}[a];case"albums":case"albumsAll":return{type:"albums",func:page.getAlbums}[a];case"users":return{type:"users",func:page.getUsers}[a];default:return null}},switchPage:function(e,a){if(page.isSomethingLoading)return page.warnSomethingLoading();var t=Object.assign(page.views[page.currentView],{trigger:a}),n=page.getByView(page.currentView,"func");switch(e){case"page-prev":return t.pageNum=page.views[page.currentView].pageNum-1,t.pageNum<0?swal("An error occurred!","This is already the first page.","error"):n(t);case"page-next":return t.pageNum=page.views[page.currentView].pageNum+1,n(t);case"page-goto":return t.pageNum=parseInt(a.dataset.goto),n(t);case"jump-to-page":var s=document.querySelector("#"+(a.dataset.jumpid||"jumpToPage"));if(!s.checkValidity())return;var i=parseInt(s.value);return t.pageNum=isNaN(i)?0:i-1,t.pageNum<0&&(t.pageNum=0),n(t)}},focusJumpToPage:function(e){var a=document.querySelector("#"+(e.dataset.jumpid||"jumpToPage"));a&&(a.focus(),a.select())},getUploads:function(e){if(void 0===e&&(e={}),e&&e.all&&!page.permissions.moderator)return swal("An error occurred!","You cannot do this!","error");if(page.isSomethingLoading)return page.warnSomethingLoading();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,t={};e.all&&(t.all="1"),e.filters&&(t.filters=e.filters,/(^|\s)(date|expiry):[\d"]/.test(e.filters)&&(t.minoffset=(new Date).getTimezoneOffset())),axios.get(a,{headers:t}).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 t=a.data.uploadsPerPage||25,n=Math.ceil(a.data.count/t),s=a.data.files;if(e.pageNum&&0===s.length)return page.updateTrigger(e.trigger),e.autoPage?(e.pageNum=n-1,page.getUploads(e)):swal("An error occurred!","There are no more uploads to populate page "+(e.pageNum+1)+".","error");page.currentView=e.all?"uploadsAll":"uploads",page.cache={};var i=a.data.albums,l=a.data.users,o=a.data.basedomain;e.pageNum<0&&(e.pageNum=Math.max(0,n+e.pageNum));for(var r=page.paginate(a.data.count,t,e.pageNum),d='\n <div class="columns">\n '+('\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="Filter uploads" value="'+page.escape(e.filters||"")+'">\n </div>\n <div class="control">\n <button type="button" class="button is-small is-primary is-outlined" title="Help?" data-action="upload-filters-help"'+(e.all?' data-all="true"':"")+'>\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 is-outlined" 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 ')+'\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" min="1" max="'+n+'" value="'+(e.pageNum+1)+'"'+(1===n?" disabled":"")+'>\n </div>\n <div class="control">\n <button type="submit" class="button is-small is-info is-outlined" 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 exclusive-operations has-text-left">\n <a class="button is-small is-primary is-outlined" title="Toggle original names" data-action="toggle-original-names">\n <span class="icon">\n <i class="icon-exchange"></i>\n </span>\n <span>Toggle original names</span>\n </a>\n </div>\n <div class="column has-text-centered">\n <a class="button is-small is-danger is-outlined" 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 is-outlined" 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 bulk-operations has-text-right">\n <a class="button is-small is-info is-outlined" title="Clear selection" data-action="clear-selection">\n <span class="icon">\n <i class="icon-cancel"></i>\n </span>\n </a>\n '+(e.all?"":'<a class="button is-small is-warning is-outlined" 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 is-outlined" 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 ',p=d.replace(/id="filters"/,'id="bFilters"').replace(/(data-action="filter-uploads")/,'$1 data-filtersid="bFilters"').replace(/id="jumpToPage"/,'id="bJumpToPage"').replace(/(data-action="jump-to-page")/g,'$1 data-jumpid="bJumpToPage"'),u=r.replace(/(data-action="page-ellipsis")/g,'$1 data-jumpid="bJumpToPage"'),g=!1,m=page.views[page.currentView].originalNames,b=s.some((function(e){return void 0!==e.expirydate})),h=0;h<s.length;h++){s[h].file=(o||window.location.origin)+"/"+s[h].name,s[h].thumb&&(s[h].thumb=(o?o+"/":"")+s[h].thumb);var v=s[h].extname.toLowerCase();page.imageExts.includes(v)?s[h].type="picture":page.videoExts.includes(v)?s[h].type="video":page.audioExts.includes(v)?s[h].type="audio":s[h].type="other",s[h].previewable=s[h].thumb||"audio"===s[h].type,page.cache[s[h].id]={name:s[h].name,original:s[h].original,extname:s[h].extname,thumb:s[h].thumb,file:s[h].file,type:s[h].type,previewable:s[h].previewable},s[h].prettyBytes=page.getPrettyBytes(parseInt(s[h].size)),s[h].prettyDate=page.getPrettyDate(new Date(1e3*s[h].timestamp)),b&&(s[h].prettyExpiryDate=s[h].expirydate?page.getPrettyDate(new Date(1e3*s[h].expirydate)):null),s[h].selected=page.selected[page.currentView].includes(s[h].id),s[h].selected||(g=!0),e.all?s[h].appendix=s[h].userid&&l[s[h].userid]||"":void 0===e.album&&(s[h].appendix=s[h].albumid&&"["+s[h].albumid+"] "+i[s[h].albumid]||"")}if("thumbs"===page.views[page.currentView].type){page.dom.innerHTML="\n "+r+"\n "+d+"\n "+c+'\n <div id="table" class="columns is-multiline is-mobile is-centered">\n </div>\n '+c+"\n "+p+"\n "+u+"\n ";for(var f=document.querySelector("#table"),w=0;w<s.length;w++){var y=s[w],k=document.createElement("div");k.className="image-container column",k.dataset.id=y.id,void 0!==y.thumb?k.innerHTML='<a class="image" href="'+y.file+'" target="_blank"><img alt="'+y.name+'" data-src="'+y.thumb+'"/></a>':k.innerHTML='<a class="image" href="'+y.file+'" target="_blank"><h1 class="title">'+(y.extname||"N/A")+"</h1></a>",k.innerHTML+='\n <input type="checkbox" class="checkbox" title="Select" data-index="'+w+'" data-action="select"'+(y.selected?" checked":"")+'>\n <div class="controls">\n '+(y.previewable?'<a class="button is-small is-primary" title="Display preview" data-action="display-preview">\n <span class="icon">\n <i class="'+("other"!==y.type?"icon-"+y.type:"icon-doc-inv")+'"></i>\n </span>\n </a>':"")+'\n <a class="button is-small is-info" title="View file info" href="file/'+y.name+'" target="_blank">\n <span class="icon">\n <i class="icon-info"></i>\n </span>\n </a>\n <a class="button is-small is-info clipboard-js" title="Copy link to clipboard" data-clipboard-text="'+y.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 class="name" title="'+y.file+'">'+y.name+"</p>\n "+(m?'<p class="originalname" title="'+y.original+'">'+y.original+"</p>":"")+'\n <p class="prettybytes" data-bytes="'+y.size+'">'+(y.appendix?"<span>"+y.appendix+"</span> ":"")+y.prettyBytes+"</p>\n "+(b&&y.prettyExpiryDate?'<p class="prettyexpirydate"'+(y.expirydate?' data-timestamp="'+y.expirydate+'"':"")+">EXP: "+y.prettyExpiryDate+"</p>":"")+"\n </div>\n ",f.appendChild(k),page.checkboxes=f.querySelectorAll('.checkbox[data-action="select"]')}}else{var x=e.all&&e.filters&&e.filters.includes("albumid:");page.dom.innerHTML="\n "+r+"\n "+d+"\n "+c+'\n <div class="table-container has-text-left">\n <table class="table is-narrow is-fullwidth is-hoverable">\n <thead>\n <tr>\n <th class="controls"><input id="selectAll" class="checkbox" type="checkbox" title="Select all" data-action="select-all"></th>\n <th title="Key: name">File name</th>\n '+(m?'<th title="Key: original">Original name</th>':"")+"\n "+(void 0===e.album?'<th title="Key: '+(e.all?'userid">User':'albumid">Album')+"</th>":"")+"\n "+(x?'<th title="Key: albumid">Album</th>':"")+'\n <th title="Key: size">Size</th>\n '+(e.all?'<th title="Key: ip">IP</th>':"")+'\n <th title="Key: timestamp">Upload date</th>\n '+(b?'<th title="Key: expirydate">Expiry date</th>':"")+'\n <th class="has-text-right">('+a.data.count+' total)</th>\n </tr>\n </thead>\n <tbody id="table">\n </tbody>\n </table>\n </div>\n '+c+"\n "+p+"\n "+u+"\n ";for(var S=document.querySelector("#table"),T=0;T<s.length;T++){var A=s[T],N=document.createElement("tr");N.dataset.id=A.id,N.innerHTML='\n <td class="controls"><input type="checkbox" class="checkbox" title="Select" data-index="'+T+'" data-action="select"'+(A.selected?" checked":"")+'></td>\n <th class="name"><a href="'+A.file+'" target="_blank" title="'+A.file+'">'+A.name+"</a></th>\n "+(m?'<th class="originalname" title="'+A.original+'">'+A.original+"</th>":"")+"\n "+(void 0===e.album?'<th class="appendix">'+A.appendix+"</th>":"")+"\n "+(x?'<th class="album">'+(A.albumid&&"["+A.albumid+"] "+i[A.albumid]||"")+"</th>":"")+'\n <td class="prettybytes" data-bytes="'+A.size+'">'+A.prettyBytes+"</td>\n "+(e.all?'<td class="ip">'+(A.ip||"")+"</td>":"")+'\n <td class="prettydate" data-timestamp="'+A.timestamp+'">'+A.prettyDate+"</td>\n "+(b?'<td class="prettyexpirydate"'+(A.expirydate?' data-timestamp="'+A.expirydate+'"':"")+">"+(A.prettyExpiryDate||"-")+"</td>":"")+'\n <td class="controls has-text-right">\n <a class="button is-small is-primary is-outlined" title="'+(A.previewable?"Display preview":"File can't be previewed")+'" data-action="display-preview"'+(A.previewable?"":" disabled")+'>\n <span class="icon">\n <i class="'+("other"!==A.type?"icon-"+A.type:"icon-doc-inv")+'"></i>\n </span>\n </a>\n <a class="button is-small is-info is-outlined" title="View file info" href="file/'+A.name+'" target="_blank">\n <span class="icon">\n <i class="icon-info"></i>\n </span>\n </a>\n <a class="button is-small is-info is-outlined clipboard-js" title="Copy link to clipboard" data-clipboard-text="'+A.file+'">\n <span class="icon">\n <i class="icon-clipboard"></i>\n </span>\n </a>\n '+(e.all?"":'<a class="button is-small is-warning is-outlined" 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 is-outlined" title="Delete" data-action="delete-upload">\n <span class="icon">\n <i class="icon-trash"></i>\n </span>\n </a>\n </td>\n ',S.appendChild(N),page.checkboxes=S.querySelectorAll('.checkbox[data-action="select"]')}}var L=document.querySelector("#selectAll");s.length&&L&&!g&&(L.checked=!0,L.title="Unselect all"),page.fadeInDom();var V=s.length?e.pageNum:0;if(e.forceScroll||null===page.prevPageNums[page.currentView]||page.prevPageNums[page.currentView]!==V){var U=!e.forceScroll&&"thumbs"===page.views[page.currentView].type;page.scrollToDom(U)}"thumbs"===page.views[page.currentView].type&&page.lazyLoad.update(),page.updateTrigger(e.trigger,"active"),"uploads"===page.currentView&&(page.views.uploads.album=e.album),page.views[page.currentView].filters=e.filters,page.views[page.currentView].pageNum=page.prevPageNums[page.currentView]=V})).catch((function(a){page.updateTrigger(e.trigger),page.onAxiosError(a)}))},setUploadsView:function(e,a){if(page.isSomethingLoading)return page.warnSomethingLoading();"list"===e?(delete localStorage[lsKeys.viewType[page.currentView]],page.views[page.currentView].type=void 0):(localStorage[lsKeys.viewType[page.currentView]]=e,page.views[page.currentView].type=e),page.getUploads(Object.assign(page.views[page.currentView],{trigger:a}))},toggleOriginalNames:function(e){if(page.isSomethingLoading)return page.warnSomethingLoading();page.views[page.currentView].originalNames?(delete localStorage[lsKeys.originalNames[page.currentView]],page.views[page.currentView].originalNames=!1):(localStorage[lsKeys.originalNames[page.currentView]]="1",page.views[page.currentView].originalNames=!0),page.getUploads(Object.assign(page.views[page.currentView],{trigger:e}))},displayPreview:function(e){var a=page.cache[e];if(a.previewable){var t=document.createElement("div");if(t.innerHTML='\n <div class="content has-text-centered">\n <p>\n <div class="has-text-weight-bold has-word-break-all">'+a.name+'</div>\n <div class="has-word-break-all">'+a.original+"</div>\n </p>\n "+(a.thumb?'<p class="swal-display-thumb-container">\n <img id="swalThumb" src="'+a.thumb+'">\n </p>':"")+"\n </div>\n ",a.file&&["picture","video","audio"].includes(a.type))if(t.innerHTML+='\n <div class="field has-text-centered">\n <div class="controls">\n <a id="swalOriginal" type="button" class="button is-info">\n <span class="icon">\n <i class="icon-'+a.type+'"></i>\n </span>\n <span>'+("picture"===a.type?"Load original":"Play in embedded player")+"</span>\n </a>\n </div>\n </div>\n ","picture"===a.type)t.querySelector("#swalOriginal").addEventListener("click",(function(e){var n=e.currentTarget;if(!n.classList.contains("is-danger")){n.classList.add("is-loading");var s=t.querySelector("#swalThumb");s.src=a.file,s.onload=function(){n.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"),n.className="button is-danger is-fullwidth",n.innerHTML='\n <span class="icon">\n <i class="icon-block"></i>\n </span>\n <span>Unable to load original</span>\n '}}}));else{var n=a.file.match(/.*\/(.*)$/);(n||n[1])&&(t.querySelector("#swalOriginal").setAttribute("href","v/"+n[1]),t.querySelector("#swalOriginal").setAttribute("target","_blank"))}return swal({content:t,buttons:!1}).then((function(){document.body.querySelector(".swal-overlay .swal-modal").classList.remove("is-expanded")}))}},selectAll:function(e){for(var a=0;a<page.checkboxes.length;a++){var t=page.getItemID(page.checkboxes[a]);isNaN(t)||page.checkboxes[a].checked!==e.checked&&(page.checkboxes[a].checked=e.checked,page.checkboxes[a].checked?page.selected[page.currentView].push(t):page.selected[page.currentView].splice(page.selected[page.currentView].indexOf(t),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 t=parseInt(e.dataset.index),n=parseInt(a.dataset.index);if(!(Math.abs(t-n)<2))for(var s=0;s<page.checkboxes.length;s++)if(t>n&&s>n&&s<t||t<n&&s>t&&s<n){var i=page.checkboxes[s].checked=a.checked,l=page.getItemID(page.checkboxes[s]);!page.selected[page.currentView].includes(l)&&i?page.selected[page.currentView].push(l):page.selected[page.currentView].includes(l)&&!i&&page.selected[page.currentView].splice(page.selected[page.currentView].indexOf(l),1)}},select:function(e,a){var t=page.getItemID(e);isNaN(t)||(a.shiftKey&&page.lastSelected?(page.selectInBetween(e,page.lastSelected),e.checked=page.lastSelected.checked):page.lastSelected=e,!page.selected[page.currentView].includes(t)&&e.checked?page.selected[page.currentView].push(t):page.selected[page.currentView].includes(t)&&!e.checked&&page.selected[page.currentView].splice(page.selected[page.currentView].indexOf(t),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=page.getByView(page.currentView,"type"),t=e.length;if(!t)return swal("An error occurred!","You have not selected any "+a+".","error");var n=1===t?a.substring(0,a.length-1):a;return swal({title:"Are you sure?",text:"You are going to unselect "+t+" "+n+".",buttons:!0}).then((function(e){if(e){for(var a=page.checkboxes,s=0;s<a.length;s++)a[s].checked&&(a[s].checked=!1);page.selected[page.currentView]=[],delete localStorage[lsKeys.selected[page.currentView]];var i=document.querySelector("#selectAll");return i&&(i.checked=!1),swal("Cleared selection!","Unselected "+t+" "+n+".","success")}}))},uploadFiltersHelp:function(e){var a=Boolean(e.dataset.all),t=document.createElement("div");t.style="text-align: left",t.innerHTML=((a?"There are 2 filter keys, namely <b>user</b> (username) and <b>ip</b>.\n These keys can be specified more than once.\n For usernames with whitespaces, wrap them with double quotes (<code>\"</code>).\n Special cases such as uploads by non-registered users or have no IPs respectively, use <code>user:-</code> or <code>ip:-</code>.\n\n To exclude certain users/ips while still listing every other uploads, add negation sign (<code>-</code>) before the keys.\n Negation sign can also be used to exclude the special cases mentioned above (i.e. <code>-user:-</code> or <code>-ip:-</code>).\n\n If you know the ID of a user's album, you can list its uploads with <b>albumid</b> key.\n Negation sign works for this key as well.":"There is only 1 filter key, namely <b>albumid</b>.\n This key can be specified more than once.\n Special case such as uploads with no albums, use <code>albumid:-</code>.\n\n To exclude certain albums while still listing every other uploads, add negation sign (<code>-</code>) before the keys.\n Negation sign can also be used to exclude the special case mentioned above (i.e. <code>-albumid:-</code>).")+'\n\n There are 2 range keys: <b>date</b> (upload date) and <b>expiry</b> (expiry date).\n Their format is: <code>"YYYY/MM/DD HH:MM:SS-YYYY/MM/DD HH:MM:SS"</code> ("from" date and "to" date respectively).\n You may specify only one of the dates.\n If "to" date is missing, \'now\' will be used. If "from" date is missing, \'beginning of time\' will be used.\n If any of the subsequent date or time units are not specified, their first value will be used (e.g. January for month, 1 for day, and so on).\n If only time is specified, today\'s date will be used.\n If you do not need to specify both date and time, you may omit the double quotes.\n In conclusion, the following examples are all valid: <code>date:"2020/01/01 01:23-2018/01/01 06"</code>, <code>expiry:-2020/05</code>, <code>date:12:34:56</code>.\n These keys can only be specified once each.\n\n <b>Timezone?</b> Feel free to query the dates with your own timezone.\n API requests to the filter endpoint will attach your browser\'s timezone offset, so the server will automatically calculate timezone differences.\n\n Matches can also be sorted with <b>sort</b> keys.\n Their formats are: <code>sort:columnName[:d[escending]]</code>, where <code>:d[escending]</code> is an optional tag to set the direction to descending.\n This key must be used with internal column names used in the database (<code>id</code>, <code>'+(a?"userid":"albumid")+"</code>, and so on),\n but there are 2 shortcuts available: <b>date</b> for <code>timestamp</code> column and <b>expiry</b> for <code>expirydate</code> column.\n This key can also be specified more than once, where their order will decide the sorting steps.\n\n Finally, there are type-<b>is</b> keys to refine by types.\n You can use <code>is:image</code>, <code>is:video</code>, and <code>is:audio</code> to list images, videos, audios respectively.\n This will only use image, video and audio extensions that are whitelisted internally in the safe.\n For images and videos specifically, they will be the ones whose thumbnails can be generated by the safe.\n Negation sign works for this key as well.\n Mixing inclusion and exclusion is not allowed (i.e. <code>is:image -is:video</code>, since the second key is redundant).\n\n Any leftover keywords which do not use keys (non-keyed keywords) will be matched against the matches' file names.\n Excluding certain keywords is also supported by adding negation sign before the keywords.\n\n <b>Internal steps:</b>\n "+(a?"- Query uploads passing ALL exclusion filter keys OR matching ANY filter keys, if any.\n - Refine matches":"- Filter uploads")+" using date key, if any.\n - Refine matches using expiry key, if any.\n - Refine matches using type-is keys, if any.\n - Refine matches using ANY non-keyed keywords, if any.\n - Filter matches using ALL exclusion non-keyed keywords, if any.\n - Sort matches using sorting keys, if any.\n\n <b>Examples:</b>\n "+(a?'- Uploads from users named "demo" AND/OR "John Doe" AND/OR non-registered users:\n <code>user:demo user:"John Doe" user:-</code>\n - ALL uploads, but NOT the ones from user named "demo" AND "John Doe":\n <code>-user:demo -user:"John Doe"</code>\n - Uploads from IP "127.0.0.1" AND which file names match "*.rar" OR "*.zip":\n <code>ip:127.0.0.1 *.rar *.zip</code>\n ':"")+'- Uploads without albums:\n <code>albumid:-</code>\n - ALL uploads, but NOT the ones from album with ID 69:\n <code>-albumid:69</code>\n - Uploads uploaded since "1 June 2019 00:00:00":\n <code>date:2019/06</code>\n - Uploads uploaded between "7 April 2020 12:00:00" and "7 April 2020 23:59:59":\n <code>date:"2020/04/07 12-2020/04/07 23:59:59"</code>\n - Uploads uploaded before "5 February 2020 00:00:00":\n <code>date:-2020/02/05</code>\n - Uploads which file names match "*.gz" but NOT "*.tar.gz":\n <code>*.gz -*.tar.gz</code>\n - Sort matches by "size" column in ascending and descending order respectively:\n <code>'+(a?'user:"John Doe"':"*.txt")+" sort:size</code>\n <code>*.mp4 "+(a?"user:- ":"")+"sort:size:d</code>\n "+(page.permissions.moderator?"":"<b>Notice:</b> Regular users may face some limitations in the amount of keys that can be used at a time.")+"\n <b>Friendly reminder:</b> This window can be scrolled up!\n ").trim().replace(/^\s*/g,"").replace(/\n/g,"<br>"),swal({content:t}).then((function(){document.body.querySelector(".swal-overlay .swal-modal").classList.remove("is-expanded")})),document.body.querySelector(".swal-overlay .swal-modal:not(.is-expanded)").classList.add("is-expanded")},filterUploads:function(e){var a=document.querySelector("#"+(e.dataset.filtersid||"filters")).value.trim().replace(/\t/g," ").replace(/(^|\s)((albumid|ip|user|date|expiry|is|sort|orderby):)\s+/g,"$2");page.getUploads(Object.assign(page.views[page.currentView],{filters:a,pageNum:0,trigger:e}))},viewUserUploads:function(e,a){var t=page.cache[e];if(t){a.classList.add("is-loading");var n=t.username.includes(" ")?'"'+t.username+'"':t.username;page.getUploads({all:!0,filters:"user:"+n,trigger:document.querySelector("#itemManageUploads")})}},viewAlbumUploads:function(e,a){if(page.cache[e]){a.classList.add("is-loading");var t="albumsAll"===page.currentView&&page.permissions.moderator;page.getUploads({all:t,filters:"albumid:"+e,trigger:t?document.querySelector("#itemManageUploads"):document.querySelector("#itemUploads")})}},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(page.views[page.currentView],{autoPage:!0}))}})},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(page.views[page.currentView],{autoPage:!0}))}})},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-outlined 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.fadeInDom(),page.scrollToDom(),page.updateTrigger(e.trigger,"active"),document.querySelector("#submitBulkDelete").addEventListener("click",(function(){if(page.isSomethingLoading)return page.warnSomethingLoading();var e=document.querySelector("#bulkDeleteNames"),a={},t=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=t.join("\n"),!t.length)return swal("An error occurred!","You have not entered any upload names.","error");page.postBulkDeleteUploads({all:!0,field:"name",values:t,cb:function(a){e.value=a.join("\n")}})}))},postBulkDeleteUploads:function(e){void 0===e&&(e={});var a=e.values.length,t=e.values.length+" upload"+(1===a?"":"s"),n="<p>You won't be able to recover "+t.replace(/^(\d*)(.*)/,"<b>$1</b>$2")+"!</p>";e.all&&(n+="\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=n,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(n){n&&axios.post("api/upload/bulkdelete",{field:e.field,values:e.values}).then((function(n){if(n){if(!1===n.data.success)return"No token provided"===n.data.description?page.verifyToken(page.token):swal("An error occurred!",n.data.description,"error");var s=Array.isArray(n.data.failed)?n.data.failed:[];s.length===e.values.length?swal("An error occurred!","Unable to delete any of the "+t+".","error"):s.length&&s.length<e.values.length?swal("Warning!","From "+t+", unable to delete "+s.length+" of them.","warning"):swal("Deleted!",t+" "+(1===a?"has":"have")+" been deleted.","success",{buttons:!1,timer:1500}),"function"==typeof e.cb&&e.cb(s)}})).catch(page.onAxiosError)}))},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 t=e.length,n=document.createElement("div");n.innerHTML='\n <div class="field has-text-centered">\n <p>You are about to add <b>'+t+"</b> upload"+(1===t?"":"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:n,buttons:{cancel:!0,confirm:{text:"OK",closeModal:!1}}}).then((function(t){if(t){var n=parseInt(document.querySelector("#swalAlbum").value);if(isNaN(n))return swal("An error occurred!","You did not choose an album.","error");axios.post("api/albums/addfiles",{ids:e,albumid:n}).then((function(t){if(t)if(!1!==t.data.success){var s=e.length;t.data.failed&&t.data.failed.length&&(s-=t.data.failed.length);var i="upload"+(1===e.length?"":"s");if(!s)return swal("An error occurred!","Could not add the "+i+" to the album.","error");swal("Woohoo!","Successfully "+(n<0?"removed":"added")+" "+s+" "+i+" "+(n<0?"from":"to")+" the album.","success",{buttons:!1,timer:1500}),a(t.data.failed)}else"No token provided"===t.data.description?page.verifyToken(page.token):swal("An error occurred!",t.data.description,"error")})).catch(page.onAxiosError)}})),axios.get("api/albums",{headers:{simple:"1"}}).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(page.onAxiosError)},getAlbums:function(e){if(void 0===e&&(e={}),e&&e.all&&!page.permissions.moderator)return swal("An error occurred!","You cannot do this!","error");if(page.isSomethingLoading)return page.warnSomethingLoading();page.updateTrigger(e.trigger,"loading"),"number"!=typeof e.pageNum&&(e.pageNum=0);var a={};e.all&&(a.all="1");var t="api/albums/"+e.pageNum;axios.get(t,{headers:a}).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"));var t=a.data.albumsPerPage||25,n=Math.ceil(a.data.count/t),s=a.data.albums;if(e.pageNum&&0===s.length)return page.updateTrigger(e.trigger),e.autoPage?(e.pageNum=n-1,page.getAlbums(e)):swal("An error occurred!","There are no more albums to populate page "+(e.pageNum+1)+".","error");page.currentView=e.all?"albumsAll":"albums",page.cache={};var i=a.data.users,l=a.data.homeDomain||window.location.origin;e.pageNum<0&&(e.pageNum=Math.max(0,n+e.pageNum));var o=page.paginate(a.data.count,t,e.pageNum),r='\n <div class="columns">\n '+('\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="Filter albums (WIP)" value="'+page.escape(e.filters||"")+'" disabled>\n </div>\n <div class="control">\n <button type="button" class="button is-small is-primary is-outlined" title="Help? (WIP)" data-action="album-filters-help" disabled>\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 is-outlined" title="Filter albums (WIP)" data-action="filter-albums" disabled>\n <span class="icon">\n <i class="icon-filter"></i>\n </span>\n </button>\n </div>\n </div>\n </form>\n </div>\n ')+'\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" min="1" max="'+n+'" value="'+(e.pageNum+1)+'"'+(1===n?" disabled":"")+'>\n </div>\n <div class="control">\n <button type="submit" class="button is-small is-info is-outlined" 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 ',d='\n <div class="columns">\n <div class="column is-hidden-mobile"></div>\n <div class="column bulk-operations has-text-right">\n <a class="button is-small is-info is-outlined" 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-dangerish is-outlined" title="Bulk disable (WIP)" data-action="bulk-disable-albums" disabled>\n <span class="icon">\n <i class="icon-cancel"></i>\n </span>\n '+(e.all?"":"<span>Bulk disable</span>")+"\n </a>\n "+(e.all?'<a class="button is-small is-danger is-outlined" title="Bulk delete (WIP)" data-action="bulk-delete-albums" 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 ",c=r.replace(/id="filters"/,'id="bFilters"').replace(/(data-action="filter-uploads")/,'$1 data-filtersid="bFilters"').replace(/id="jumpToPage"/,'id="bJumpToPage"').replace(/(data-action="jump-to-page")/g,'$1 data-jumpid="bJumpToPage"'),p=o.replace(/(data-action="page-ellipsis")/g,'$1 data-jumpid="bJumpToPage"'),u=!1,g='\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-outlined 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 ';page.dom.innerHTML="\n "+(e.all?"":g)+"\n "+o+"\n "+r+"\n "+d+'\n <div class="table-container has-text-left">\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>ID</th>\n <th>Name</th>\n '+(e.all?"<th>User</th>":"")+'\n <th>Uploads</th>\n <th>Size</th>\n <th>Created at</th>\n <th>ZIP size</th>\n <th>ZIP generated at</th>\n <th>Public link</th>\n <th class="has-text-right">('+a.data.count+' total)</th>\n </tr>\n </thead>\n <tbody id="table">\n </tbody>\n </table>\n </div>\n '+d+"\n "+c+"\n "+p+"\n ";for(var m=document.querySelector("#table"),b=0;b<s.length;b++){var h=s[b],v="/a/"+h.identifier,f=l+v,w=page.selected[page.currentView].includes(h.id);w||(u=!0),h.hasZip=null!==h.zipSize,h.prettyDate=page.getPrettyDate(new Date(1e3*h.timestamp)),h.prettyZipDate=h.hasZip?page.getPrettyDate(new Date(1e3*h.zipGeneratedAt)):null,h.isZipExpired=h.hasZip&&!(h.zipGeneratedAt>h.editedAt);var y=0!==h.enabled;page.cache[h.id]={name:h.name,download:h.download,public:h.public,description:h.description,descriptionHtml:h.descriptionHtml,enabled:y,homeDomain:l,urlPath:"/a/",identifier:h.identifier};var k=document.createElement("tr");k.dataset.id=h.id,k.innerHTML='\n <td class="controls"><input type="checkbox" class="checkbox" title="Select" data-index="'+b+'" data-action="select"'+(w?" checked":"")+"></td>\n <th>"+h.id+"</th>\n <th"+(y?"":' class="has-text-grey"')+">"+h.name+"</td>\n "+(e.all?"<th>"+(h.userid&&i[h.userid]||"")+"</th>":"")+"\n <th>"+h.uploads+'</th>\n <td data-bytes="'+h.size+'">'+page.getPrettyBytes(h.size)+'</td>\n <td data-timestamp="'+h.timestamp+'">'+h.prettyDate+"</td>\n <td"+(h.hasZip?' data-bytes="'+h.zipSize+'"':"")+">"+(h.hasZip?page.getPrettyBytes(h.zipSize):"-")+"</td>\n <td"+(h.hasZip?' data-timestamp="'+h.zipGeneratedAt+'"':"")+(h.isZipExpired?' class="has-text-warning" title="This album has been modified since the last time its ZIP was generated."':"")+">"+(h.hasZip?h.prettyZipDate:"-")+"</td$>\n <td><a "+(y&&h.public?"":'class="is-linethrough" ')+'href="'+f+'" target="_blank">'+v+'</a></td>\n <td class="has-text-right" data-id="'+h.id+'">\n <a class="button is-small is-primary is-outlined" 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 is-outlined" title="'+(h.uploads?"View uploads":"Album doesn't have uploads")+'" data-action="view-album-uploads" '+(h.uploads?"":"disabled")+'>\n <span class="icon">\n <i class="icon-docs"></i>\n </span>\n </a>\n <a class="button is-small is-info is-outlined clipboard-js" title="Copy link to clipboard" '+(h.public?'data-clipboard-text="'+f+'"':"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 is-outlined" title="Download album" '+(y&&h.download?'href="api/album/zip/'+h.identifier+"?v="+h.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-dangerish is-outlined" title="Disable album" data-action="disable-album"'+(y?"":" disabled")+'>\n <span class="icon is-small">\n <i class="icon-cancel"></i>\n </span>\n </a>\n '+(e.all?'<a class="button is-small is-danger is-outlined" 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 ",m.appendChild(k),page.checkboxes=m.querySelectorAll('.checkbox[data-action="select"]')}var x=document.querySelector("#selectAll");s.length&&x&&!u&&(x.checked=!0,x.title="Unselect all"),page.fadeInDom();var S=s.length?e.pageNum:0;(e.forceScroll||null===page.prevPageNums[page.currentView]||page.prevPageNums[page.currentView]!==S)&&page.scrollToDom(),page.updateTrigger(e.trigger,"active"),"albumsAll"===page.currentView&&(page.views[page.currentView].filters=e.filters),page.views[page.currentView].pageNum=page.prevPageNums[page.currentView]=S}})).catch((function(a){page.updateTrigger(e.trigger),page.onAxiosError(a)}))},editAlbum:function(e){var a=page.cache[e];if(a){var t=a.urlPath+a.identifier,n=a.homeDomain+t,s=document.createElement("div");s.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"><b>Markdown supported.</b> Max length is '+page.albumDescMaxLength+" characters.</p>\n </div>\n "+(a.descriptionHtml?'<div class="field">\n <div class="content swal-display-description-preview">\n '+a.descriptionHtml+'\n </div>\n <p class="help">Save changes then re-open this Edit prompt to refresh this preview.</p>\n </div>':"")+"\n "+("albumsAll"===page.currentView&&page.permissions.moderator?'<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="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 <div class="field">\n <p>Current public link: <a href="'+n+'" target="_blank" class="is-underline">'+t+"</a></p>\n </div>\n ",swal({title:"Edit album",icon:"info",content:s,buttons:{cancel:!0,confirm:{closeModal:!1}}}).then((function(t){if(t){var n={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};"albumsAll"===page.currentView&&page.permissions.moderator&&(n.enabled=document.querySelector("#swalEnabled").checked),axios.post("api/albums/edit",n).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!","The album's new identifier is: "+e.data.identifier+".","success"):e.data.name!==a.name?swal("Success!","The album was renamed to: "+e.data.name+".","success"):swal("Success!","The album was edited.","success",{buttons:!1,timer:1500}),page.getAlbumsSidebar(),page.getAlbums(Object.assign(page.views[page.currentView],{autoPage:!0}))}})).catch(page.onAxiosError)}}))}},disableAlbum:function(e){swal({title:"Are you sure?",text:"This won't delete the uploads associated with the album!",icon:"warning",dangerMode:!0,buttons:{cancel:!0,confirm:{text:"Yes, disable it!",closeModal:!1},purge:{text:"Umm, delete the uploads, please?",value:"purge",className:"swal-button--danger",closeModal:!1}}}).then((function(a){a&&axios.post("api/albums/disable",{id:e,purge:"purge"===a}).then((function(e){if(!1===e.data.success){var a=Array.isArray(e.data.failed)?e.data.failed:[];return"No token provided"===e.data.description?page.verifyToken(page.token):a.length?swal("An error occurred!","Unable to delete "+a.length+" of the album's upload"+(1===a.length?"":"s")+".","error"):swal("An error occurred!",e.data.description,"error")}swal("Disabled!","The album has been disabled.","success",{buttons:!1,timer:1500}),page.getAlbumsSidebar(),page.getAlbums(Object.assign(page.views[page.currentView],{autoPage:!0}))})).catch(page.onAxiosError)}))},deleteAlbum:function(e){swal({title:"Are you sure?",text:"You won't be able to recover this album!\nThis also won't delete the uploads associated with the album!",icon:"warning",dangerMode:!0,buttons:{cancel:!0,confirm:{text:"Yes, delete it!",closeModal:!1},purge:{text:"Umm, delete the uploads, 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){var a=Array.isArray(e.data.failed)?e.data.failed:[];return"No token provided"===e.data.description?page.verifyToken(page.token):a.length?swal("An error occurred!","Unable to delete "+a.length+" of the album's upload"+(1===a.length?"":"s")+".","error"):swal("An error occurred!",e.data.description,"error")}swal("Disabled!","The album has been deleted.","success",{buttons:!1,timer:1500}),page.getAlbumsSidebar(),page.getAlbums(Object.assign(page.views[page.currentView],{autoPage:!0}))})).catch(page.onAxiosError)}))},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",{buttons:!1,timer:1500}),page.getAlbumsSidebar(),page.getAlbums({pageNum:-1})}})).catch((function(a){page.updateTrigger(e),page.onAxiosError(a)}))},getAlbumsSidebar:function(){axios.get("api/albums",{headers:{simple:"1"}}).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=e.data.albums,t=e.data.count,n=document.querySelector("#albumsSidebar"),s=n.querySelectorAll("li > a"),i=s.length!==t;if(s.length){for(var l=0;l<s.length;l++)page.menus.splice(page.menus.indexOf(s[l]),1);n.innerHTML=""}if(page.albumsSidebarCollapse.innerText=page.albumsSidebarCollapsible.collapsed()?page.albumsSidebarCollapse.dataset.textExpand:page.albumsSidebarCollapse.dataset.textCollapse,!a||!a.length)return page.albumsSidebarCollapsible.collapse(),void page.albumsSidebarCollapse.setAttribute("disabled","disabled");for(var o=0;o<a.length;o++){var r=a[o],d=document.createElement("li"),c=document.createElement("a");c.id=r.id,c.className="is-relative",c.innerHTML=r.name,c.addEventListener("click",(function(e){page.getUploads({album:parseInt(e.currentTarget.id),trigger:e.currentTarget})})),page.menus.push(c),d.appendChild(c),n.appendChild(d)}page.albumsSidebarCollapse.removeAttribute("disabled"),!page.albumsSidebarCollapsible.collapsed()&&i&&page.albumsSidebarCollapsible.collapse()}})).catch(page.onAxiosError)},changeToken:function(e){void 0===e&&(e={}),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="'+page.token+'">\n </div>\n </div>\n </div>\n <div class="field">\n <div class="control">\n <a id="getNewToken" class="button is-info is-outlined 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.fadeInDom(),page.scrollToDom(),page.updateTrigger(e.trigger,"active"),document.querySelector("#getNewToken").addEventListener("click",(function(e){if(page.isSomethingLoading)return page.warnSomethingLoading();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",buttons:!1,timer:1500}).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){page.updateTrigger(a),page.onAxiosError(e)}))}))},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" minlength="6" maxlength="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" minlength="6" maxlength="64">\n </div>\n </div>\n <div class="field">\n <div class="control">\n <button type="submit" id="sendChangePassword" class="button is-info is-outlined 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.fadeInDom(),page.scrollToDom(),page.updateTrigger(e.trigger,"active"),document.querySelector("#sendChangePassword").addEventListener("click",(function(e){if(page.isSomethingLoading)return page.warnSomethingLoading();page.dom.querySelector("form").checkValidity()&&(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(!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 password was successfully changed.",icon:"success",buttons:!1,timer:1500}).then((function(){page.changePassword()}))})).catch((function(e){page.updateTrigger(a),page.onAxiosError(e)}))},getUsers:function(e){if(void 0===e&&(e={}),!page.permissions.admin)return swal("An error occurred!","You cannot do this!","error");if(page.isSomethingLoading)return page.warnSomethingLoading();page.updateTrigger(e.trigger,"loading"),"number"!=typeof e.pageNum&&(e.pageNum=0);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"));var t=a.data.usersPerPage||25,n=Math.ceil(a.data.count/t),s=a.data.users;if(e.pageNum&&0===s.length)return page.updateTrigger(e.trigger),e.autoPage?(e.pageNum=n-1,page.getUsers(e)):swal("An error occurred!","There are no more users to populate page "+(e.pageNum+1)+".","error");page.currentView="users",page.cache={},e.pageNum<0&&(e.pageNum=Math.max(0,n+e.pageNum));var i=page.paginate(a.data.count,t,e.pageNum),l='\n <div class="columns">\n '+('\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="Filter users (WIP)" value="'+page.escape(e.filters||"")+'" disabled>\n </div>\n <div class="control">\n <button type="button" class="button is-small is-primary is-outlined" title="Help? (WIP)" data-action="user-filters-help" disabled>\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 is-outlined" title="Filter users (WIP)" data-action="filter-users" disabled>\n <span class="icon">\n <i class="icon-filter"></i>\n </span>\n </button>\n </div>\n </div>\n </form>\n </div>\n ')+'\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" min="1" max="'+n+'" value="'+(e.pageNum+1)+'"'+(1===n?" disabled":"")+'>\n </div>\n <div class="control">\n <button type="submit" class="button is-small is-info is-outlined" 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 ',o='\n <div class="columns">\n <div class="column exclusive-operations has-text-left">\n <a class="button is-small is-primary is-outlined" title="Create new user" data-action="create-user">\n <span class="icon">\n <i class="icon-plus"></i>\n </span>\n <span>Create new user</span>\n </a>\n </div>\n <div class="column bulk-operations has-text-right">\n <a class="button is-small is-info is-outlined" 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-dangerish is-outlined" title="Bulk disable (WIP)" data-action="bulk-disable-users" disabled>\n <span class="icon">\n <i class="icon-hammer"></i>\n </span>\n </a>\n <a class="button is-small is-danger is-outlined" 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 ',r=l.replace(/id="filters"/,'id="bFilters"').replace(/(data-action="filter-uploads")/,'$1 data-filtersid="bFilters"').replace(/id="jumpToPage"/,'id="bJumpToPage"').replace(/(data-action="jump-to-page")/g,'$1 data-jumpid="bJumpToPage"'),d=i.replace(/(data-action="page-ellipsis")/g,'$1 data-jumpid="bJumpToPage"'),c=!1;page.dom.innerHTML="\n "+i+"\n "+l+"\n "+o+'\n <div class="table-container has-text-left">\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 title="Key: username">Username</th>\n <th>Uploads</th>\n <th>Usage</th>\n <th title="Key: permission">Group</th>\n <th title="Key: registration">Registration date</th>\n <th title="Key: timestamp">Last token update</th>\n <th class="has-text-right">('+a.data.count+' total)</th>\n </tr>\n </thead>\n <tbody id="table">\n </tbody>\n </table>\n </div>\n '+o+"\n "+r+"\n "+d+"\n ";for(var p=document.querySelector("#table"),u=0;u<s.length;u++){var g=s[u],m=page.selected[page.currentView].includes(g.id);m||(c=!0);for(var b=null,h=Object.keys(g.groups),v=0;v<h.length&&g.groups[h[v]];v++)b=h[v];var f=!1!==g.enabled&&0!==g.enabled;page.cache[g.id]={username:g.username,groups:g.groups,enabled:f,displayGroup:b};var w=g.registration?page.getPrettyDate(new Date(1e3*g.registration)):"-",y=g.timestamp?page.getPrettyDate(new Date(1e3*g.timestamp)):"-",k=document.createElement("tr");k.dataset.id=g.id,k.innerHTML='\n <td class="controls"><input type="checkbox" class="checkbox" title="Select" data-index="'+u+'" data-action="select"'+(m?" checked":"")+"></td>\n <th"+(f?"":' class="has-text-grey"')+">"+g.username+"</td>\n <th>"+g.uploads+"</th>\n <td>"+page.getPrettyBytes(g.usage)+"</td>\n <td>"+b+"</td>\n <td>"+w+"</td>\n <td>"+y+'</td>\n <td class="controls has-text-right">\n <a class="button is-small is-primary is-outlined" 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 is-outlined" title="'+(g.uploads?"View uploads":"User doesn't have uploads")+'" data-action="view-user-uploads" '+(g.uploads?"":"disabled")+'>\n <span class="icon">\n <i class="icon-docs"></i>\n </span>\n </a>\n <a class="button is-small is-dangerish is-outlined" title="'+(f?"Disable user":"User is disabled")+'" data-action="disable-user" '+(f?"":"disabled")+'>\n <span class="icon">\n <i class="icon-hammer"></i>\n </span>\n </a>\n <a class="button is-small is-danger is-outlined" title="Delete user" data-action="delete-user">\n <span class="icon">\n <i class="icon-trash"></i>\n </span>\n </a>\n </td>\n ',p.appendChild(k),page.checkboxes=p.querySelectorAll('.checkbox[data-action="select"]')}var x=document.querySelector("#selectAll");s.length&&x&&!c&&(x.checked=!0,x.title="Unselect all"),page.fadeInDom();var S=s.length?e.pageNum:0;(e.forceScroll||null===page.prevPageNums[page.currentView]||page.prevPageNums[page.currentView]!==S)&&page.scrollToDom(),page.updateTrigger(e.trigger,"active"),page.views[page.currentView].pageNum=page.prevPageNums[page.currentView]=S})).catch((function(a){page.updateTrigger(e.trigger),page.onAxiosError(a)}))},createUser:function(){var e=Object.keys(page.permissions).map((function(e,a,t){return'<option value="'+e+'"'+(!(t[a+1]&&page.permissions[t[a+1]])?" disabled":"")+">"+e+"</option>"})).join("\n"),a=document.createElement("div");a.innerHTML='\n <div class="field">\n <label class="label">Username</label>\n <div class="controls">\n <input id="swalUsername" class="input" type="text">\n </div>\n </div>\n <div class="field">\n <label class="label">Password (optional)</label>\n <div class="controls">\n <input id="swalPassword" class="input" type="text">\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 '+e+"\n </select>\n </div>\n </div>\n </div>\n ",swal({title:"Create new user",icon:"info",content:a,buttons:{cancel:!0,confirm:{closeModal:!1}}}).then((function(e){e&&axios.post("api/users/create",{username:document.querySelector("#swalUsername").value,password:document.querySelector("#swalPassword").value,group:document.querySelector("#swalGroup").value}).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.createElement("div");a.innerHTML="\n <p>Username: <b>"+e.data.username+"</b></p>\n <p>Password: <code>"+e.data.password+"</code></p>\n <p>User group: <b>"+e.data.group+"</b></p>\n ",swal({title:"Created a new user!",icon:"success",content:a}),page.getUsers(Object.assign(page.views.users,{pageNum:-1}))}})).catch(page.onAxiosError)}))},editUser:function(e){var a=page.cache[e];if(a){var t=!1,n=Object.keys(page.permissions).map((function(e,n,s){var i=e===a.displayGroup;return i&&(t=void 0!==s[n+1]&&page.permissions[s[n+1]]),'<option value="'+e+'"'+(i?" selected":"")+(!(s[n+1]&&page.permissions[s[n+1]])?" disabled":"")+">"+e+"</option>"})).join("\n"),s=t?"":" disabled",i=document.createElement("div");i.innerHTML='\n <div class="field">\n <p>User ID: '+e+'</p>\n </div>\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||"")+'"'+s+'>\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"'+s+">\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":"")+s+'>\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"'+s+">\n Reset password\n </label>\n </div>\n </div>\n "+(t?"":'<div class="notification is-danger">\n You <b>cannot</b> modify user in the same or higher group as you.\n </div>')+"\n ",swal({title:"Edit user",icon:"info",content:i,buttons:{cancel:!0,confirm:{closeModal:!1}}}).then((function(t){t&&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");var t=!0,n=document.createElement("div"),s=a.username;e.data.update.username!==a.username&&(n.innerHTML+="<p>"+a.username+" was renamed into: <b>"+e.data.update.username+"</b>.</p>",t=!1,s=e.data.update.username),e.data.update.password&&(n.innerHTML+="\n <p>"+s+"'s new password is:</p>\n <p><code>"+e.data.update.password+"</code></p>\n ",t=!1),e.data.update.enabled!==a.enabled&&(n.innerHTML+="<p>"+s+" has been "+(e.data.update.enabled?"enabled":"disabled")+"!</p>"),n.innerHTML||(n.innerHTML="<p>"+s+" was edited!</p>"),swal({title:"Success!",icon:"success",content:n,buttons:!t,timer:t?1500:null}),page.getUsers(page.views.users)}})).catch(page.onAxiosError)}))}},disableUser:function(e){var a=page.cache[e];if(a&&a.enabled){var t=document.createElement("div");t.innerHTML="\n <p>You will be disabling a user named <b>"+page.cache[e].username+"</b>.</p>\n <p>Their files will remain.</p>\n ",swal({title:"Are you sure?",icon:"warning",content:t,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(a){if(a){if(!1===a.data.success)return"No token provided"===a.data.description?page.verifyToken(page.token):swal("An error occurred!",a.data.description,"error");swal("Success!",page.cache[e].username+" has been disabled.","success",{buttons:!1,timer:1500}),page.getUsers(page.views.users)}})).catch(page.onAxiosError)}))}},deleteUser:function(e){if(page.cache[e]){var a=document.createElement("div");a.innerHTML="\n <p>You will be deleting a user named <b>"+page.cache[e].username+"</b>.<p>\n <p>Their uploads will still remain, unless you choose otherwise.</p>\n ",swal({title:"Are you sure?",icon:"warning",content:a,dangerMode:!0,buttons:{cancel:!0,confirm:{text:"Yes, ONLY the user!",closeModal:!1},purge:{text:"Yes, AND their uploads too!",value:"purge",className:"swal-button--danger",closeModal:!1}}}).then((function(a){a&&axios.post("api/users/delete",{id:e,purge:"purge"===a}).then((function(a){if(a){if(!1===a.data.success){var t=Array.isArray(a.data.failed)?a.data.failed:[];return"No token provided"===a.data.description?page.verifyToken(page.token):t.length?swal("An error occurred!","Unable to delete "+t.length+" of the user's upload"+(1===t.length?"":"s")+".","error"):swal("An error occurred!",a.data.description,"error")}swal("Success!",page.cache[e].username+" has been deleted.","success",{buttons:!1,timer:1500}),page.getUsers(Object.assign(page.views.users,{autoPage:!0}))}})).catch(page.onAxiosError)}))}},paginate:function(e,a,t){t+=1;var n=Math.ceil(e/a),s="",i=function(e,a){for(var n=e;n<=a;++n)s+='<li><a class="button pagination-link '+(n===t?" is-current":"")+'" aria-label="Goto page '+n+'" data-action="page-goto" data-goto="'+(n-1)+'">'+n+"</a></li>"},l=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 '},o=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 '+n+'" data-action="page-goto" data-goto="'+(n-1)+'">'+n+"</a></li>\n "};return 7>=n?i(1,n):t<6?(i(1,6),o()):t>n-6+1?(l(),i(n-6+1,n)):(l(),i(t-3+1,t+3-1),o()),'\n <nav class="pagination is-centered is-small">\n <a class="button pagination-previous" data-action="page-prev"'+(1===t?" disabled":"")+'>Previous</a>\n <a class="button pagination-next" data-action="page-next"'+(t>=n?" disabled":"")+'>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 cannot do this!","error");if(page.isSomethingLoading)return page.warnSomethingLoading();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 t="",n=Object.keys(a.data.stats),s=0;s<n.length;s++){var i="";if(a.data.stats[n[s]])try{for(var l=Object.keys(a.data.stats[n[s]]),o=0;o<l.length;o++){var r=a.data.stats[n[s]][l[o]],d="object"==typeof r?r.type:"auto",c="object"==typeof r?r.value:r,p=void 0;switch(d){case"byte":p=page.getPrettyBytes(c);break;case"byteUsage":var u=void 0!==c.available?c.used+c.available:c.total;p=page.getPrettyBytes(c.used)+" / "+page.getPrettyBytes(c.total)+" ("+(c.used/u*100).toFixed(2)+"%)";break;case"uptime":p=page.getPrettyUptime(c);break;case"auto":if("number"==typeof c)p=c.toLocaleString();else p=c;break;default:p=c}i+="\n <tr>\n <th>"+l[o]+"</th>\n <td>"+p+"</td>\n </tr>\n "}}catch(e){i="\n <tr>\n <td>Error parsing response. Try again?</td>\n <td></td>\n </tr>\n ",page.onError(e)}else i+="\n <tr>\n <td>Generating, please try again later…</td>\n <td></td>\n </tr>\n ";t+='\n <div class="table-container has-text-left">\n <table id="statistics" class="table is-narrow is-fullwidth is-hoverable">\n <thead>\n <tr>\n <th class="capitalize">'+n[s]+"</th>\n <td></td>\n </tr>\n </thead>\n <tbody>\n "+i+"\n </tbody>\n </table>\n </div>\n "}Array.isArray(a.data.hrtime)&&(t+='\n <article class="message is-size-7">\n <div class="message-body has-text-left">\n Time taken: '+a.data.hrtime[0]+"s "+Math.ceil(a.data.hrtime[1]/1e6)+"ms.\n </div>\n </article>\n "),page.dom.innerHTML=t,page.fadeInDom(),page.scrollToDom(),page.updateTrigger(e.trigger,"active")})).catch((function(a){page.updateTrigger(e.trigger),page.onAxiosError(a)}))}};window.addEventListener("DOMContentLoaded",(function(){"function"!=typeof Object.assign&&Object.defineProperty(Object,"assign",{value:function(e,a){"use strict";var t=arguments;if(null==e)throw new TypeError("Cannot convert undefined or null to object");for(var n=Object(e),s=1;s<arguments.length;s++){var i=t[s];if(null!=i)for(var l in i)Object.prototype.hasOwnProperty.call(i,l)&&(n[l]=i[l])}return n},writable:!0,configurable:!0}),"ontouchstart"in document.documentElement||document.documentElement.classList.add("no-touch");for(var e=["uploads","uploadsAll","albums","albumsAll","users"],a=0;a<e.length;a++){var t=localStorage[lsKeys.selected[e[a]]];t&&(page.selected[e[a]]=JSON.parse(t))}page.preparePage(),page.clipboardJS=new ClipboardJS(".clipboard-js"),page.clipboardJS.on("success",(function(){return swal("","The link has been copied to clipboard.","success",{buttons:!1,timer:1500})})),page.clipboardJS.on("error",page.onError),page.lazyLoad=new LazyLoad,page.albumsSidebarCollapse=document.querySelector("#albumsSidebarCollapse"),page.albumsSidebarCollapsible=new bulmaCollapsible(document.querySelector("#albumsSidebar")),page.albumsSidebarCollapsible.on("before:expand",(function(e){page.albumsSidebarCollapse.innerText=page.albumsSidebarCollapse.dataset.textCollapse})),page.albumsSidebarCollapsible.on("before:collapse",(function(e){page.albumsSidebarCollapse.innerText=page.albumsSidebarCollapse.dataset.textExpand}))}));
//# sourceMappingURL=dashboard.js.map