{"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","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","isimage","type","startsWith","isvideo","isaudio","img","src","parentNode","onerror","event","currentTarget","add","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,KAGff,kBAAsB,SAAGgB,GACvBhB,KAAKI,eAAeE,cAAc,iBAAiBW,UAAYD,EAC/DhB,KAAKI,eAAec,UAAUC,OAAO,cAIvCnB,QAAY,SAAGoB,GACbC,QAAQD,MAAMA,GACdpB,KAAKsB,kBAAkB,kEAEVF,EAAMG,WAAU,gFAM/BvB,aAAiB,SAAGoB,GAElBvB,IAYM2B,EAZmB,CACvB,IAAK,gBACL,IAAK,qBACL,IAAK,uBACL,IAAK,wBACL,IAAK,qBACL,IAAK,uBACL,IAAK,0BACL,IAAK,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st 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\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

An error occurred!

\n

${error.toString()}

\n

Please check your console for more information.

\n `)\n}\n\n// Handler for Axios errors\npage.onAxiosError = error => {\n // Better Cloudflare errors\n const 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 const statusText = 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

${error.response.status} ${statusText}

\n

${description}

\n `)\n}\n\npage.deleteFile = () => {\n if (!page.file) return\n\n const content = document.createElement('div')\n content.innerHTML = '

You won\\'t be able to recover this file!

'\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 \n ${keys[i]}\n ${value}\n ${prettyValue}\n \n `\n }\n\n document.querySelector('#title').innerText = page.file.name\n page.fileinfoContainer.querySelector('.table-container').innerHTML = `\n
\n \n \n \n \n \n \n \n \n \n ${rows}\n \n
FieldsValues
\n
\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 isimage = page.file.type.startsWith('image/')\n const isvideo = page.file.type.startsWith('video/')\n const isaudio = page.file.type.startsWith('audio/')\n if (isimage) {\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.classList.add('is-hidden')\n } else 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('

Failed to parse upload identifier from URL.

')\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"]}