mirror of
https://github.com/pldubouilh/gossa.git
synced 2026-08-29 13:27:02 -04:00
Add frontend functionality for checksum feature
This commit is contained in:
Vendored
+54
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user