From ad423948ccb3ea91ecab4a80f651464e0f891429 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Sun, 23 Feb 2025 21:12:43 -0500 Subject: [PATCH] Add frontend functionality for checksum feature --- ui/script.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++-- ui/style.css | 14 ++++++------- ui/ui.tmpl | 9 +++++++++ 3 files changed, 69 insertions(+), 10 deletions(-) diff --git a/ui/script.js b/ui/script.js index ba24e0f..e419786 100755 --- a/ui/script.js +++ b/ui/script.js @@ -153,13 +153,21 @@ function rpc (call, args, cb) { xhr.open('POST', location.origin + window.extraPath + '/rpc') xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8') xhr.send(JSON.stringify({ call, args })) - xhr.onload = cb + // set the callback function (cb) to true to copy the response to the clipboard + if (cb === true) { + xhr.onload = () => { + navigator.clipboard.writeText(xhr.responseText) + }; + } else { + xhr.onload = cb + } xhr.onerror = () => flicker(sadBadge) } const mkdirCall = (path, cb) => rpc('mkdirp', [prependPath(path)], cb) const rmCall = (path1, cb) => rpc('rm', [prependPath(path1)], cb) const mvCall = (path1, path2, cb) => rpc('mv', [path1, path2], cb) +const sumCall = (path, type) => {rpc('sum', [prependPath(path), type], true)} // File upload let totalDone = 0 @@ -383,7 +391,7 @@ function resetView () { scrollToArrow() } -window.quitAll = () => helpOff() || picsOff() || videosOff() || padOff() || pdfOff() +window.quitAll = () => helpOff() || sumsOff() || picsOff() || videosOff() || padOff() || pdfOff() // Mkdir icon window.mkdirBtn = function () { @@ -659,6 +667,33 @@ function helpOff () { return true } +// checksums +function getSum (type) { + sumCall(getASelected().innerText, type) + sumsOff() +} + +const isSumsMode = () => sums.style.display === 'block' + +const sumsToggle = () => isSumsMode() ? sumsOff() : sumsOn() + +function sumsOn () { + if (getASelected().innerText.endsWith('/')) { + alert('cannot checksum a directory') + return + } + sums.style.display = 'block' + table.style.display = 'none' +} + +window.sumsOff = sumsOff +function sumsOff () { + if (!isSumsMode()) return + sums.style.display = 'none' + table.style.display = 'table' + return true +} + // Paste handler const cuts = [] function onPaste () { @@ -759,6 +794,9 @@ document.body.addEventListener('keydown', e => { case 'KeyH': return prevent(e) || isRo() || helpToggle() + case 'KeyZ': + return prevent(e) || isRo() || sumsToggle() + case 'KeyX': return prevent(e) || isRo() || onCut() @@ -784,6 +822,20 @@ document.body.addEventListener('keydown', e => { case 'ArrowRight': return prevent(e) || dl(getASelected()) } + } else if (isSumsMode()) { + switch (e.code) { + case 'Digit1': + return prevent(e) || isRo() || getSum('sha1') + + case 'Digit2': + return prevent(e) || isRo() || getSum('sha256') + + case 'Digit3': + return prevent(e) || isRo() || getSum('sha512') + + case 'Digit5': + return prevent(e) || isRo() || getSum('md5') + } } } else { // Workaround Firefox requirement for transient activation diff --git a/ui/style.css b/ui/style.css index 3858b06..c577cd3 100644 --- a/ui/style.css +++ b/ui/style.css @@ -344,12 +344,8 @@ h1 > span:hover { right: 30px; } -#helpHead { - margin-top: 60px; - text-align: center; -} - -#helpTable { +#helpTable, +#sumsTable { border-collapse: collapse; width: 70%; max-width: 790px; @@ -360,7 +356,8 @@ h1 > span:hover { overflow-y: auto; } -#helpTable td { +#helpTable td, +#sumsTable td { width: 200px; padding: 9px; border: 1px solid #fff; @@ -369,7 +366,8 @@ h1 > span:hover { margin: 0; } -#help { +#help, +#sums { background-color: black; position: absolute; top: 0px; diff --git a/ui/ui.tmpl b/ui/ui.tmpl index 3d88439..437404a 100644 --- a/ui/ui.tmpl +++ b/ui/ui.tmpl @@ -30,6 +30,7 @@ Ctrl/Meta + Mcreate a new directory Ctrl/Meta + Xcut selected path Ctrl/Meta + Vpaste previously selected paths to directory + Ctrl/Meta + Zcopy checksums of selected file Ctrl + clickdownload selected item as archive click file icon rename item double click file icondelete item @@ -38,6 +39,14 @@ any other letterfuzzy search + +