diff --git a/assets/index.css b/assets/index.css index 113704e..dd307b4 100644 --- a/assets/index.css +++ b/assets/index.css @@ -132,7 +132,7 @@ body { } .paths-table .cell-actions { - width: 60px; + width: 75px; display: flex; padding-left: 0.6em; } @@ -175,7 +175,7 @@ body { } .action-btn { - padding-left: 0.4em; + padding-right: 0.3em; } .uploaders-table { diff --git a/assets/index.js b/assets/index.js index 2a2fc43..27b48cd 100644 --- a/assets/index.js +++ b/assets/index.js @@ -161,6 +161,7 @@ function addPath(file, index) { let encodedUrl = encodedStr(url); let actionDelete = ""; let actionDownload = ""; + let actionMove = ""; if (file.path_type.endsWith("Dir")) { url += "/"; encodedUrl += "/"; @@ -179,14 +180,19 @@ function addPath(file, index) { `; } if (DATA.allow_delete) { + actionMove = ` +
+ +
`; actionDelete = ` -
+
`; } let actionCell = ` ${actionDownload} + ${actionMove} ${actionDelete} ` @@ -205,7 +211,7 @@ function addPath(file, index) { } /** - * Delete pathitem + * Delete path * @param {number} index * @returns */ @@ -235,6 +241,38 @@ async function deletePath(index) { } } + +/** + * Move path + * @param {number} index + * @returns + */ +async function movePath(index) { + const file = DATA.paths[index]; + if (!file) return; + + let filePath = decodeURI(getUrl(file.name)); + let newPath = prompt("Enter new path", filePath) + if (!newPath || filePath === newPath) return; + const encodedNewPath = encodeURI(newPath); + + try { + const res = await fetch(getUrl(file.name), { + method: "MOVE", + headers: { + "Destination": encodedNewPath, + } + }); + if (res.status >= 200 && res.status < 300) { + location.href = encodedNewPath.split("/").slice(0, -1).join("/") + } else { + throw new Error(await res.text()) + } + } catch (err) { + alert(`Cannot move \`${filePath}\` to \`${newPath}\`, ${err.message}`); + } +} + function dropzone() { ["drag", "dragstart", "dragend", "dragover", "dragenter", "dragleave", "drop"].forEach(name => { document.addEventListener(name, e => {