master
Bel LaPointe 2022-02-09 16:00:03 -07:00
parent ae7f9e18a8
commit 26f645e4dc
1 changed files with 24 additions and 3 deletions

View File

@ -50,6 +50,26 @@
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
function deleteFile() {
if (!confirm("would you like to delete this file?"))
return
const id = easyMDE.meta.id
if (!id || id.length == 0)
return
http("DELETE", "/api/v0/files/" + id, (body, status) => {
if (status != 200) {
alert(`failed to delete file ${id}: ${status}: ${body}`)
throw `failed to delete file ${id}: ${status}: ${body}`
}
drawTree()
var pid = id.slice(0, id.lastIndexOf("/"))
if (pid) {
drawFile(pid)
} else {
disableMDE()
}
})
}
function pushFile() {
const title = document.getElementById("title").innerHTML ? document.getElementById("title").innerHTML : ""
const body = easyMDE.value() ? easyMDE.value() : ""
@ -60,7 +80,7 @@
http("PUT", "/api/v0/files/" + id, (body, status) => {
if (status != 200) {
alert(`failed to push file ${id}: ${status}: ${body}`)
raise `failed to push file ${id}: ${status}: ${body}`
throw `failed to push file ${id}: ${status}: ${body}`
}
drawTree()
drawFile(id)
@ -75,7 +95,7 @@
}
http("GET", "/api/v0/files/"+id, (body, status, headers) => {
if (status != 200) {
raise `ERR loading file: ${status}: ${body}`
throw `ERR loading file: ${status}: ${body}`
}
const title = headers("title") ? headers("title") : ""
setMDE(id, title, body)
@ -141,7 +161,7 @@
}
http("GET", "/api/v0/tree", (body, status) => {
if (status != 200)
raise `bad status getting tree: ${status}: ${body}`
throw `bad status getting tree: ${status}: ${body}`
const tree = JSON.parse(body)
document.getElementById("tree").innerHTML = htmlifyBranch("", tree)
})
@ -176,6 +196,7 @@
<article id="article" style="display: none; flex-grow: 1; margin-left: 1em;">
<div>
<h1 style="display: flex; flex-direction: row;">
<input type="submit" value="DELETE" onclick="deleteFile(); return false;" style="margin-left: 5%; margin-right: 5%"/>
<span id="titlePath">
</span>
<span id="title" contenteditable style="flex-grow: 1;"></span>