mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2024-12-13 07:56:23 +00:00
1 line
12 KiB
Plaintext
1 line
12 KiB
Plaintext
{"version":3,"sources":["file.js"],"names":["const","lsKeys","token","page","localStorage","urlPrefix","urlIdentifier","messageElement","document","querySelector","fileinfoContainer","clipboardBtn","playerBtn","downloadBtn","deleteBtn","uploadRoot","titleFormat","file","clipboardJS","cloudflareErrors","content","innerHTML","classList","remove","error","console","updateMessageBody","toString","response","onError","statusText","status","description","data","createElement","swal","title","icon","dangerMode","buttons","cancel","confirm","text","closeModal","then","proceed","axios","post","id","success","Array","isArray","failed","length","catch","onAxiosError","get","includes","replace","name","let","rows","keys","Object","i","value","prettyValue","getPrettyBytes","getPrettyDate","Date","innerText","fileUrl","setAttribute","dataset","clipboardText","img","src","parentNode","onerror","event","currentTarget","add","isvideo","type","startsWith","isaudio","urlParams","has","click","window","addEventListener","URLSearchParams","searchString","self","this","RegExp","exec","defaults","headers","common","mainScript","location","protocol","host","match","pathname","substring","indexOf","search","ClipboardJS","on","timer","deleteFile","loadFileinfo"],"mappings":"AAEAA,IAAMC,OAAS,CACbC,MAAO,SAGHC,KAAO,CAEXD,MAAOE,aAAaH,OAAOC,OAE3BG,UAAW,KACXC,cAAe,KAEfC,eAAgBC,SAASC,cAAc,YACvCC,kBAAmBF,SAASC,cAAc,aAE1CE,aAAcH,SAASC,cAAc,iBACrCG,UAAWJ,SAASC,cAAc,cAClCI,YAAaL,SAASC,cAAc,gBACpCK,UAAWN,SAASC,cAAc,cAClCM,WAAY,KACZC,YAAa,KAEbC,KAAM,KACNC,YAAa,KAGbC,iBAAkB,CAChB,IAAK,gBACL,IAAK,qBACL,IAAK,uBACL,IAAK,wBACL,IAAK,qBACL,IAAK,uBACL,IAAK,0BACL,IAAK,gBACL,IAAK,oBAIThB,kBAAsB,SAAGiB,GACvBjB,KAAKI,eAAeE,cAAc,iBAAiBY,UAAYD,EAC/DjB,KAAKI,eAAee,UAAUC,OAAO,YACvC,E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C,UAAW,CACnEI,SAAS,EACTwE,MAAO,MA1BX,IA8BA5G,KAAKe,YAAY4F,GAAG,QAAS3G,KAAK0B,SAElC1B,KAAKW,UAAU4E,iBAAiB,QAASvF,KAAK6G,YAE9C7G,KAAK8G,cA/BoE,CAI3E","file":"file.js","sourcesContent":["/* global swal, axios, ClipboardJS */\n\nconst lsKeys = {\n token: 'token'\n}\n\nconst page = {\n // user token\n token: localStorage[lsKeys.token],\n\n urlPrefix: null,\n urlIdentifier: null,\n\n messageElement: document.querySelector('#message'),\n fileinfoContainer: document.querySelector('#fileinfo'),\n\n clipboardBtn: document.querySelector('#clipboardBtn'),\n playerBtn: document.querySelector('#playerBtn'),\n downloadBtn: document.querySelector('#downloadBtn'),\n deleteBtn: document.querySelector('#deleteBtn'),\n uploadRoot: null,\n titleFormat: null,\n\n file: null,\n clipboardJS: null,\n\n // Better Cloudflare errors\n cloudflareErrors: {\n 520: 'Unknown Error',\n 521: 'Web Server Is Down',\n 522: 'Connection Timed Out',\n 523: 'Origin Is Unreachable',\n 524: 'A Timeout Occurred',\n 525: 'SSL Handshake Failed',\n 526: 'Invalid SSL Certificate',\n 527: 'Railgun Error',\n 530: 'Origin DNS Error'\n }\n}\n\npage.updateMessageBody = content => {\n page.messageElement.querySelector('.message-body').innerHTML = content\n page.messageElement.classList.remove('is-hidden')\n}\n\n// Handler for regular JS errors\npage.onError = error => {\n console.error(error)\n page.updateMessageBody(`\n <p><strong>An error occurred!</strong></p>\n <p><code>${error.toString()}</code></p>\n <p>Please check your console for more information.</p>\n `)\n}\n\n// Handler for Axios errors\npage.onAxiosError = error => {\n if (!error.response) {\n return page.onError(error)\n }\n\n const statusText = page.cloudflareErrors[error.response.status] || error.response.statusText\n\n const description = error.response.data && error.response.data.description\n ? error.response.data.description\n : ''\n page.updateMessageBody(`\n <p><strong>${error.response.status} ${statusText}</strong></p>\n <p>${description}</p>\n `)\n}\n\npage.deleteFile = () => {\n if (!page.file) return\n\n const content = document.createElement('div')\n content.innerHTML = '<p>You won\\'t be able to recover this file!</p>'\n\n swal({\n title: 'Are you sure?',\n content,\n icon: 'warning',\n dangerMode: true,\n buttons: {\n cancel: true,\n confirm: {\n text: 'Yes, nuke it!',\n closeModal: false\n }\n }\n }).then(proceed => {\n if (!proceed) return\n\n axios.post('../api/upload/delete', {\n id: page.file.id\n }).then(response => {\n if (!response) return\n\n if (response.data.success === false) {\n return swal('An error occurred!', response.data.description, 'error')\n }\n\n const failed = Array.isArray(response.data.failed) ? response.data.failed : []\n if (failed.length) {\n swal('An error occurred!', 'Unable to delete this file.', 'error')\n } else {\n swal('Deleted!', 'This file has been deleted.', 'success', {\n buttons: false\n })\n }\n }).catch(page.onAxiosError)\n })\n}\n\npage.loadFileinfo = () => {\n if (!page.urlIdentifier) return\n\n axios.get(`../api/upload/get/${page.urlIdentifier}`).then(response => {\n if (![200, 304].includes(response.status)) {\n return page.onAxiosError(response)\n }\n\n page.file = response.data.file\n\n if (page.titleFormat) {\n document.title = page.titleFormat.replace(/%identifier%/g, page.file.name)\n }\n\n let rows = ''\n const keys = Object.keys(page.file)\n for (let i = 0; i < keys.length; i++) {\n const value = page.file[keys[i]]\n\n let prettyValue = ''\n if (value) {\n if (['size'].includes(keys[i])) {\n prettyValue = page.getPrettyBytes(value)\n } else if (['timestamp', 'expirydate'].includes(keys[i])) {\n prettyValue = page.getPrettyDate(new Date(value * 1000))\n }\n }\n\n rows += `\n <tr>\n <th class=\"capitalize\">${keys[i]}</th>\n <td>${value}</td>\n <td>${prettyValue}</td>\n </tr>\n `\n }\n\n document.querySelector('#title').innerText = page.file.name\n page.fileinfoContainer.querySelector('.table-container').innerHTML = `\n <div class=\"table-container has-text-left\">\n <table id=\"statistics\" class=\"table is-fullwidth is-hoverable\">\n <thead>\n <tr>\n <th>Fields</th>\n <td>Values</td>\n <td></td>\n </tr>\n </thead>\n <tbody>\n ${rows}\n </tbody>\n </table>\n </div>\n `\n\n const fileUrl = `${page.uploadRoot}/${page.file.name}`\n page.downloadBtn.setAttribute('href', fileUrl)\n page.clipboardBtn.dataset.clipboardText = fileUrl\n\n const img = page.fileinfoContainer.querySelector('img')\n img.setAttribute('alt', page.file.name || '')\n img.src = `${page.uploadRoot}/${page.file.name}`\n img.parentNode.classList.remove('is-hidden')\n img.onerror = event => event.currentTarget.parentNode.classList.add('is-hidden')\n\n const isvideo = page.file.type.startsWith('video/')\n const isaudio = page.file.type.startsWith('audio/')\n if (isvideo || isaudio) {\n page.playerBtn.setAttribute('href', `../v/${page.file.name}`)\n page.playerBtn.parentNode.parentNode.classList.remove('is-hidden')\n }\n\n page.fileinfoContainer.classList.remove('is-hidden')\n page.messageElement.classList.add('is-hidden')\n\n if (page.urlParams.has('delete')) {\n page.deleteBtn.click()\n }\n }).catch(error => {\n if (typeof error.response !== 'undefined') page.onAxiosError(error)\n else page.onError(error)\n })\n}\n\nwindow.addEventListener('DOMContentLoaded', () => {\n // Partial polyfill URLSearchParams.has()\n // eslint-disable-next-line compat/compat\n window.URLSearchParams = window.URLSearchParams || function (searchString) {\n const self = this\n self.has = function (name) {\n const results = new RegExp('[?&]' + name).exec(self.searchString)\n if (results == null) {\n return false\n } else {\n return true\n }\n }\n }\n\n axios.defaults.headers.common.token = page.token\n\n const mainScript = document.querySelector('#mainScript')\n if (!mainScript || typeof mainScript.dataset.uploadRoot === 'undefined') return\n\n page.uploadRoot = mainScript.dataset.uploadRoot\n page.titleFormat = mainScript.dataset.titleFormat\n\n let urlPrefix = window.location.protocol + '//' + window.location.host\n const match = window.location.pathname.match(/.*\\/(.*)$/)\n if (!match || !match[1]) {\n return page.updateMessageBody('<p>Failed to parse upload identifier from URL.</p>')\n }\n\n page.urlIdentifier = match[1]\n urlPrefix += window.location.pathname.substring(0, window.location.pathname.indexOf(match[1]))\n page.urlPrefix = urlPrefix\n\n // eslint-disable-next-line compat/compat\n page.urlParams = new URLSearchParams(window.location.search)\n\n page.clipboardJS = new ClipboardJS('.clipboard-js')\n\n page.clipboardJS.on('success', () => {\n return swal('', 'The link has been copied to clipboard.', 'success', {\n buttons: false,\n timer: 1500\n })\n })\n\n page.clipboardJS.on('error', page.onError)\n\n page.deleteBtn.addEventListener('click', page.deleteFile)\n\n page.loadFileinfo()\n})\n"]} |