mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2024-12-16 01:16:22 +00:00
a6156da798
Their thumbs can be made with ffmpeg Run "yarn thumbs 2" to create thumbs for existing uploads with those extensions Rebuilt client assets and bumped v1 version string
3 lines
61 KiB
JavaScript
3 lines
61 KiB
JavaScript
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:{filters:null,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",".m4v",".m2ts"],isTriggerLoading:null,fadingIn:null,albumTitleMaxLength:70,albumDescMaxLength:4e3,unhide:function(){document.querySelector("#loader").classList.add("is-hidden"),document.querySelector("#dashboard").classList.remove("is-hidden")},onError:function(e){console.error(e);var a=document.createElement("div");return a.innerHTML="<code>"+e.toString()+"</code>",swal({title:"An error occurred!",icon:"error",content:a})},onAxiosError:function(e){console.error(e);var a={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"}[e.response.status]||e.response.statusText,n=e.response.data&&e.response.data.description?e.response.data.description:"There was an error with the request, please check the console for more information.";return swal(e.response.status+" "+a,n,"error")},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(page.onAxiosError)},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},{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+" )",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"},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"add-to-album":return page.addToAlbum(n);case"delete-upload":return page.deleteUpload(n);case"add-selected-uploads-to-album":return page.addSelectedUploadsToAlbum();case"bulk-delete-uploads":return page.bulkDeleteUploads();case"display-preview":return page.displayPreview(n);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(n);case"delete-album":return page.deleteAlbum(n);case"create-user":return page.createUser();case"edit-user":return page.editUser(n);case"disable-user":return page.disableUser(n);case"delete-user":return page.deleteUser(n);case"view-user-uploads":return page.viewUserUploads(n,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();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")),e||(page.dom.classList.add("fade-in"),page.fadingIn=setTimeout((function(){page.dom.classList.remove("fade-in")}),500)),page.dom.scrollIntoView({behavior:e?"auto":"smooth",block:"start",inline:"nearest"})},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 i=parseInt(s.value);return n.pageNum=isNaN(i)?0:i-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||""};(n.filters.includes("date:")||n.filters.includes("expiry:"))&&(n.minOffset=(new Date).getTimezoneOffset()),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=Math.ceil(a.data.count/25),t=a.data.files;if(e.pageNum&&0===t.length)return e.autoPage?(e.pageNum=n-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 s=a.data.albums,i=a.data.users,l=a.data.basedomain,r=page.paginate(a.data.count,25,e.pageNum),o='<div class="column is-hidden-mobile"></div>';e.all&&(o='\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="'+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">\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 ');for(var c='\n <div class="columns">\n '+o+'\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 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 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?"":'\n <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 ',u=!1,p=t.some((function(e){return void 0!==e.expirydate})),g=0;g<t.length;g++){t[g].file=l+"/"+t[g].name,t[g].thumb&&(t[g].thumb=l+"/"+t[g].thumb),t[g].type="other";var m=/.[\w]+(\?|$)/.exec(t[g].file),b=m&&m[0]?m[0].toLowerCase():null;page.imageExts.includes(b)?t[g].type="picture":page.videoExts.includes(b)&&(t[g].type="video"),page.cache.uploads[t[g].id]={name:t[g].name,thumb:t[g].thumb,original:t[g].file,type:t[g].type},t[g].prettyBytes=page.getPrettyBytes(parseInt(t[g].size)),t[g].prettyDate=page.getPrettyDate(new Date(1e3*t[g].timestamp)),p&&(t[g].prettyExpiryDate=t[g].expirydate?page.getPrettyDate(new Date(1e3*t[g].expirydate)):null),t[g].selected=page.selected[page.currentView].includes(t[g].id),t[g].selected||(u=!0),e.all?t[g].appendix=t[g].userid&&i[t[g].userid]||"":void 0===e.album&&(t[g].appendix=t[g].albumid&&s[t[g].albumid]||"")}if("thumbs"===page.views[page.currentView].type){page.dom.innerHTML="\n "+r+"\n "+c+"\n "+d+'\n <div id="table" class="columns is-multiline is-mobile is-centered">\n </div>\n '+r+"\n ";for(var h=document.querySelector("#table"),v=0;v<t.length;v++){var f=t[v],w=document.createElement("div");w.className="image-container column",w.dataset.id=f.id,void 0!==f.thumb?w.innerHTML='<a class="image" href="'+f.file+'" target="_blank"><img alt="'+f.name+'" data-src="'+f.thumb+'"/></a>':w.innerHTML='<a class="image" href="'+f.file+'" target="_blank"><h1 class="title">'+(f.extname||"N/A")+"</h1></a>",w.innerHTML+='\n <input type="checkbox" class="checkbox" title="Select" data-index="'+v+'" data-action="select"'+(f.selected?" checked":"")+'>\n <div class="controls">\n '+(f.thumb?'\n <a class="button is-small is-primary" title="Display preview" data-action="display-preview">\n <span class="icon">\n <i class="'+("other"!==f.type?"icon-"+f.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="'+f.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">'+f.name+"</span></p>\n <p>"+(f.appendix?"<span>"+f.appendix+"</span> – ":"")+f.prettyBytes+"</p>\n "+(p&&f.prettyExpiryDate?'\n <p class="expirydate">EXP: '+f.prettyExpiryDate+"</p>":"")+"\n </div>\n ",h.appendChild(w),page.checkboxes[page.currentView]=h.querySelectorAll('.checkbox[data-action="select"]')}}else{page.dom.innerHTML="\n "+r+"\n "+c+"\n "+d+'\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 name</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 "+(p?"<th>Expiry date</th>":"")+'\n <th></th>\n </tr>\n </thead>\n <tbody id="table">\n </tbody>\n </table>\n </div>\n '+r+"\n ";for(var y=document.querySelector("#table"),k=0;k<t.length;k++){var x=t[k],T=document.createElement("tr");T.dataset.id=x.id,T.innerHTML='\n <td class="controls"><input type="checkbox" class="checkbox" title="Select" data-index="'+k+'" data-action="select"'+(x.selected?" checked":"")+'></td>\n <th><a href="'+x.file+'" target="_blank" title="'+x.file+'">'+x.name+"</a></th>\n "+(void 0===e.album?"<th>"+x.appendix+"</th>":"")+"\n <td>"+x.prettyBytes+"</td>\n "+(e.all?"<td>"+(x.ip||"")+"</td>":"")+"\n <td>"+x.prettyDate+"</td>\n "+(p?"<td>"+(x.prettyExpiryDate||"-")+"</td>":"")+'\n <td class="controls has-text-right">\n <a class="button is-small is-primary is-outlined" title="'+(x.thumb?"Display preview":"File can't be previewed")+'" data-action="display-preview"'+(x.thumb?"":" disabled")+'>\n <span class="icon">\n <i class="'+("other"!==x.type?"icon-"+x.type:"icon-doc-inv")+'"></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="'+x.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 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 ',y.appendChild(T),page.checkboxes[page.currentView]=y.querySelectorAll('.checkbox[data-action="select"]')}}var A=document.querySelector("#selectAll");A&&!u&&t.length&&(A.checked=!0,A.title="Unselect all"),"thumbs"===page.views[page.currentView].type?(page.fadeAndScroll(!0),page.lazyLoad.update()):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=t.length?e.pageNum:0})).catch((function(a){page.updateTrigger(e.trigger),page.onAxiosError(a)}))},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,i=page.imageExts.includes(s),l=!i&&page.videoExts.includes(s);(i||l)&&(n.innerHTML+='\n <div class="field has-text-centered">\n <div class="controls">\n <a id="swalOriginal" type="button" class="button is-info is-outlined 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(i)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(l){s.classList.add("is-hidden");var r=document.createElement("video");r.id="swalVideo",r.controls=!0,r.autoplay=!0,r.src=a.original,s.insertAdjacentElement("afterend",r),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 i=page.checkboxes[page.currentView][s].checked=a.checked,l=page.getItemID(page.checkboxes[page.currentView][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 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 i=document.querySelector("#selectAll");return i&&(i.checked=!1),swal("Cleared selection!","Unselected "+n+" "+t+".","success")}}))},uploadFiltersHelp:function(e){var a=document.createElement("div");a.style="text-align: left",a.innerHTML='\n 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 (<b>"</b>).\n\n There are 2 special filter keys, namely <b>user:-</b> and <b>ip:-</b>, to match uploads by non-registered users and have no IPs respectively.\n\n To exclude certain users/ips while still listing every other uploads, add negation sign (<b>-</b>) before the keys.\n <b>Unfortunately</b>, this will not show uploads by non-registered users or have no IPs as well, instead you need to also use the special filter keys if you want to include them.\n\n There are 2 range keys: <b>date</b> (upload date) and <b>expiry</b> (expiry date).\n Their format is: <b>YYYY/MM/DD HH:MM:SS-YYYY/MM/DD HH:MM:SS</b> ("to" date is optional).\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 Meaning the following can be accepted: <b>2020/01/01 01:23</b>, <b>2018/01/01 06</b>, <b>2019/11</b>, <b>12:34:56</b>.\n These keys can only be specified once each.\n\n Matches can also be sorted with <b>orderby:columnName[:d[escending]]</b> keys.\n This key require internal column names used in the database (id, userid, and so on), but there are 2 shortcuts, namely <b>date</b> for timestamp column and <b>expiry</b> for expirydate column.\n This key can also be specified more than once, where their order will decide the sorting steps.\n\n Any leftover keywords which do not use keys will be matched against the matches\' file names.\n Excluding certain keywords is also supported by adding negation sign (<b>-</b>) before the keywords.\n\n <b>Internals:</b>\n First, it will filter uploads matching ANY of the supplied filter keys AND/OR special filter keys, if any.\n Second, it will refine the matches using the supplied <b>date</b> AND/OR <b>expiry</b> range keys, if any.\n Third, it will refine the matches using the leftover non-keyed keywords, if any.\n Finally, it will sort the matches using the supplied <b>orderby</b> keys, if any.\n\n <b>Examples:</b>\n Uploads from user named "demo":\n <code>user:demo</code>\n 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, including from non-registered users, but NOT the ones from user named "demo":\n <code>-user:demo user:-</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 uploaded since "1 June 2019 00:00:00":\n <code>date:2019/06</code>\n Uploads uploaded between "7 April 2020 00:00:00" and "7 April 2020 23:59:59":\n <code>date:2020/04/07-2020/04/07 23:59:59</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>user:"John Doe" orderby:size</code>\n <code>*.mp4 user:- orderby:size:d</code>\n\n <b>Friendly reminder:</b> This window can be scrolled up!\n '.trim().replace(/^ {6}/gm,"").replace(/\n/g,"<br>"),swal({content:a}).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("#filters").value.trim();page.getUploads({all:!0,filters:a},e)},viewUserUploads:function(e,a){var n=page.cache.users[e];if(n){a.classList.add("is-loading");var t=n.username.includes(" ")?'"'+n.username+'"':n.username;page.getUploads({all:!0,filters:"user:"+t,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-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.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",{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 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 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 "+(t<0?"removed":"added")+" "+s+" "+i+" "+(t<0?"from":"to")+" the album.","success",{buttons:!1,timer:1500}),a(n.data.failed)}else"No token provided"===n.data.description?page.verifyToken(page.token):swal("An error occurred!",n.data.description,"error")})).catch(page.onAxiosError)}})),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(page.onAxiosError)},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-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 <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 i=a.data.albums[s],l=n+"/a/"+i.identifier;i.prettyDate=page.getPrettyDate(new Date(1e3*i.timestamp)),page.cache.albums[i.id]={name:i.name,download:i.download,public:i.public,description:i.description};var r=document.createElement("tr");r.innerHTML="\n <th>"+i.id+"</th>\n <th>"+i.name+"</th>\n <th>"+i.files+"</th>\n <td>"+i.prettyDate+"</td>\n <td><a "+(i.public?'href="'+l+'"':'class="is-linethrough"')+' target="_blank">'+l+'</a></td>\n <td class="has-text-right" data-id="'+i.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 clipboard-js" title="Copy link to clipboard" '+(i.public?'data-clipboard-text="'+l+'"':"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" '+(i.download?'href="api/album/zip/'+i.identifier+"?v="+i.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 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 ',t.appendChild(r)}page.fadeAndScroll(),page.updateTrigger(e.trigger,"active")}})).catch((function(a){page.updateTrigger(e.trigger),page.onAxiosError(a)}))},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",{buttons:!1,timer:1500}),page.getAlbumsSidebar(),page.getAlbums()}})).catch(page.onAxiosError)}))}},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){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("Deleted!","Your album has been deleted.","success",{buttons:!1,timer:1500}),page.getAlbumsSidebar(),page.getAlbums()})).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()}})).catch((function(a){page.updateTrigger(e),page.onAxiosError(a)}))},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 i=e.data.albums[s],l=document.createElement("li"),r=document.createElement("a");r.id=i.id,r.innerHTML=i.name,r.className="is-relative",r.addEventListener("click",(function(e){page.getUploads({album:parseInt(e.currentTarget.id),trigger:e.currentTarget})})),page.menus.push(r),l.appendChild(r),a.appendChild(l)}}})).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.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",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.fadeAndScroll(),page.updateTrigger(e.trigger,"active"),document.querySelector("#sendChangePassword").addEventListener("click",(function(e){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.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"));var n=Math.ceil(a.data.count/25);if(e.pageNum&&0===a.data.users.length)return e.autoPage?(e.pageNum=n-1,page.getUsers(e)):(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 t=page.paginate(a.data.count,25,e.pageNum),s='\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="Filters (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 ',i=!1;page.dom.innerHTML="\n "+t+"\n "+s+'\n \n <div class="columns">\n <div class="column 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 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-warning 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 \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>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 '+t+"\n ";for(var l=document.querySelector("#table"),r=0;r<a.data.users.length;r++){var o=a.data.users[r],c=page.selected.users.includes(o.id);c||(i=!0);for(var d=null,u=Object.keys(o.groups),p=0;p<u.length&&o.groups[u[p]];p++)d=u[p];var g=!1!==o.enabled&&0!==o.enabled;page.cache.users[o.id]={username:o.username,groups:o.groups,enabled:g,displayGroup:d};var m=document.createElement("tr");m.dataset.id=o.id,m.innerHTML='\n <td class="controls"><input type="checkbox" class="checkbox" title="Select" data-index="'+r+'" data-action="select"'+(c?" checked":"")+"></td>\n <th"+(g?"":' class="is-linethrough"')+">"+o.username+"</td>\n <th>"+o.uploads+"</th>\n <td>"+page.getPrettyBytes(o.usage)+"</td>\n <td>"+d+'</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="'+(o.uploads?"View uploads":"User doesn't have uploads")+'" data-action="view-user-uploads" '+(o.uploads?"":"disabled")+'>\n <span class="icon">\n <i class="icon-docs"></i>\n </span>\n </a>\n <a class="button is-small is-warning is-outlined" title="'+(g?"Disable user":"User is disabled")+'" data-action="disable-user" '+(g?"":"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 ',l.appendChild(m),page.checkboxes.users=l.querySelectorAll('.checkbox[data-action="select"]')}var b=document.querySelector("#selectAll");b&&!i&&(b.checked=!0,b.title="Unselect all"),page.fadeAndScroll(),page.updateTrigger(e.trigger,"active"),page.views.users.pageNum=a.data.users.length?e.pageNum:0})).catch((function(a){page.updateTrigger(e.trigger),page.onAxiosError(a)}))},createUser:function(){var e=Object.keys(page.permissions).map((function(e,a,n){return'<option value="'+e+'"'+(!(n[a+1]&&page.permissions[n[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(page.views.users)}})).catch(page.onAxiosError)}))},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");var n=!0,t=document.createElement("div"),s=a.username;e.data.update.username!==a.username&&(t.innerHTML+="<p>"+a.username+" was renamed into: <b>"+e.data.update.username+"</b>.</p>",n=!1,s=e.data.update.username),e.data.update.password&&(t.innerHTML+="\n <p>"+s+"'s new password is:</p>\n <p><code>"+e.data.update.password+"</code></p>\n ",n=!1),e.data.update.enabled!==a.enabled&&(t.innerHTML+="<p>"+s+" has been "+(e.data.update.enabled?"enabled":"disabled")+"!</p>"),t.innerHTML||(t.innerHTML="<p>"+s+" was edited!</p>"),swal({title:"Success!",icon:"success",content:t,buttons:!n,timer:n?1500:null}),page.getUsers(page.views.users)}})).catch(page.onAxiosError)}))}},disableUser:function(e){var a=page.cache.users[e];if(a&&a.enabled){var n=document.createElement("div");n.innerHTML="\n <p>You will be disabling a user named <b>"+page.cache.users[e].username+"</b>.</p>\n <p>Their files will remain.</p>\n ",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(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.users[e].username+" has been disabled.","success",{buttons:!1,timer:1500}),page.getUsers(page.views.users)}})).catch(page.onAxiosError)}))}},deleteUser:function(e){if(page.cache.users[e]){var a=document.createElement("div");a.innerHTML="\n <p>You will be deleting a user named <b>"+page.cache.users[e].username+"</b>.<p>\n <p>Their files will remain, unless you choose otherwise.</p>\n ",swal({title:"Are you sure?",icon:"warning",content:a,dangerMode:!0,buttons:{cancel:!0,confirm:{text:"Yes, delete it!",closeModal:!1},purge:{text:"Yes, and the 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 n=Array.isArray(a.data.failed)?a.data.failed:[];return"No token provided"===a.data.description?page.verifyToken(page.token):n.length?swal("An error occurred!","Unable to delete "+n.length+" of the user's upload"+(1===n.length?"":"s")+".","error"):swal("An error occurred!",a.data.description,"error")}swal("Success!",page.cache.users[e].username+" has been deleted.","success",{buttons:!1,timer:1500}),page.getUsers(Object.assign({autoPage:!0},page.views.users))}})).catch(page.onAxiosError)}))}},paginate:function(e,a,n){n+=1;var t=Math.ceil(e/a),s="",i=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>"},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">…</span></li>\n '},r=function(){s+='\n <li data-action="page-ellipsis"><span class="pagination-ellipsis">…</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?i(1,t):n<6?(i(1,6),r()):n>t-6+1?(l(),i(t-6+1,t)):(l(),i(n-3+1,n+3-1),r()),'\n <nav class="pagination is-centered is-small">\n <a class="button pagination-previous" data-action="page-prev"'+(1===n?" disabled":"")+'>Previous</a>\n <a class="button pagination-next" data-action="page-next"'+(n===t?" 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 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 i="";if(a.data.stats[t[s]])try{for(var l=a.data.stats[t[s]]._types||{},r=Object.keys(a.data.stats[t[s]]),o=0;o<r.length;o++)if(!/^_/.test(r[o])){var c=a.data.stats[t[s]][r[o]],d=c;(l.number||[]).includes(r[o])&&(d=c.toLocaleString()),(l.byte||[]).includes(r[o])&&(d=page.getPrettyBytes(c)),(l.byteUsage||[]).includes(r[o])&&(d=page.getPrettyBytes(c.used)+" / "+page.getPrettyBytes(c.total)+" ("+Math.round(c.used/c.total*100)+"%)"),i+="\n <tr>\n <th>"+r[o].replace(/([A-Z])/g," $1").toUpperCase()+"</th>\n <td>"+d+"</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 ";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 "+i+"\n </tbody>\n </table>\n </div>\n "}page.dom.innerHTML=n,page.fadeAndScroll(),page.updateTrigger(e.trigger,"active")})).catch((function(a){page.updateTrigger(e.trigger),page.onAxiosError(a)}))}};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 i=n[s];if(null!=i)for(var l in i)Object.prototype.hasOwnProperty.call(i,l)&&(t[l]=i[l])}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("","The link has been copied to clipboard.","success",{buttons:!1,timer:1500})})),page.clipboardJS.on("error",page.onError),page.lazyLoad=new LazyLoad};
|
||
//# sourceMappingURL=dashboard.js.map
|