filesafe/dist/js/file.js.map

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","statusText","response","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","onError","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,EAGApB,QAAY,SAAGqB,GACbC,QAAQD,MAAMA,GACdrB,KAAKuB,kB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AiB,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 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"]}