From 6ab677b0211415610e9e427880c48d20890b7eea Mon Sep 17 00:00:00 2001 From: Ibrahim Ansari Date: Sat, 25 Sep 2021 03:12:04 +0530 Subject: [PATCH] Remove lastEls, clean up Files inline JSX funcs. --- imports/dashboard/files/files.tsx | 160 +++++++++++---------------- pages/dashboard/[server]/console.tsx | 20 ++-- 2 files changed, 74 insertions(+), 106 deletions(-) diff --git a/imports/dashboard/files/files.tsx b/imports/dashboard/files/files.tsx index 6fe602d..485aa10 100644 --- a/imports/dashboard/files/files.tsx +++ b/imports/dashboard/files/files.tsx @@ -210,6 +210,52 @@ const Files = (props: { setMessage('Uploaded all files successfully!') fetchFiles() } + // Single file logic. + const handleDeleteMenuButton = async () => { + setMenuOpen('') + setFetching(true) + const a = await request( + ip, + `/server/${server}/file?path=${euc(path + menuOpen)}`, + { method: 'DELETE' } + ).then(async e => await e.json()) + if (a.error) setMessage(a.error) + setFetching(false) + setMenuOpen('') + fetchFiles() + } + const handleDownloadMenuButton = async () => { + setMenuOpen('') + const ticket = await fetch(ip + '/ott', { + headers: { authorization: localStorage.getItem('token') || '' } + }) + const ott = encodeURIComponent((await ticket.json()).ticket) + window.location.href = `${ip}/server/${server}/file?ticket=${ott}&path=${path}${menuOpen}` + } + const handleDecompressMenuButton = async () => { + setMenuOpen('') + setFetching(true) + const a = await request( + ip, + `/server/${server}/decompress?path=${euc(path + menuOpen)}`, + { method: 'POST' } + ).then(async e => await e.json()) + if (a.error) setMessage(a.error) + setFetching(false) + setMenuOpen('') + fetchFiles() + } + const handleDownloadButton = async () => { + setDownload('') + // document.cookie = `X-Authentication=${localStorage.getItem('token')}` + const ticket = await fetch(ip + '/ott', { + headers: { authorization: localStorage.getItem('token') || '' } + }) + const ott = encodeURIComponent((await ticket.json()).ticket) + window.location.href = download.replace('?path', `?ticket=${ott}&path`) + } + + const selectedFile = menuOpen && files && files.find(e => e.name === menuOpen) return ( <> {!files ? : ( @@ -258,27 +304,21 @@ const Files = (props: { )} - - - - - + + +
- - setFolderPromptOpen(true)}> - - - + setFolderPromptOpen(true)}> + +
- - setFile({ name: '', content: '' })}> - - - + setFile({ name: '', content: '' })}> + +
setDownload('')} message={`Do you want to download '${download.replace(/%2F/g, '/').split('/').filter(e => e).pop()}'?`} action={[ - ,