master
Bel LaPointe 2022-02-08 17:11:39 -07:00
parent 7b51fd077d
commit fc263d6c2d
4 changed files with 49 additions and 29 deletions

View File

@ -162,7 +162,7 @@ func (server *Server) postContentHandler(fileDir string, w http.ResponseWriter,
if r.Method != http.MethodPost {
return "", errors.New("not found")
}
id := uuid.New().String()
id := strings.Split(uuid.New().String(), "-")[0]
if strings.HasPrefix(r.Header.Get("Content-Type"), "multipart/form-data") {
kb := int64(1 << 10)
mb := kb << 10

View File

@ -1,30 +1,25 @@
A:
title: A
6c090e2f:
title: Untitled (2022-02-09 00:08:51.502773 +0000 UTC)
deleted: false
updated: 2022-02-08T23:40:44.951597Z
updated: 2022-02-09T00:08:51.502773Z
pid: f927298b
445b8601:
title: a
deleted: false
updated: 2022-02-09T00:08:32.478418Z
pid: ""
AA:
title: AA
"98400812":
title: b
deleted: false
updated: 2022-02-08T23:40:44.966702Z
pid: A
AAA:
title: AAA
deleted: false
updated: 2022-02-08T23:40:44.976068Z
pid: AA
AB:
title: AB
deleted: false
updated: 2022-02-08T23:40:44.985178Z
pid: A
B:
title: B
deleted: false
updated: 2022-02-08T23:40:44.995572Z
updated: 2022-02-09T00:08:36.820551Z
pid: ""
b7fe2c91-6bd7-4b49-8590-4223ccc772ac:
title: my file title
a84cdde6:
title: c
deleted: false
updated: 2022-02-08T19:43:47.438639Z
updated: 2022-02-09T00:08:43.611391Z
pid: ""
f927298b:
title: d
deleted: false
updated: 2022-02-09T00:08:48.393336Z
pid: "98400812"

View File

@ -34,11 +34,12 @@
</style>
<script>
function init() {
/* TODO when no drawFile, disable editor or somethin */
drawTree()
setInterval(drawTree, 10000)
var queryF = getParameterByName("f")
console.log("init query f:", queryF)
if (queryF && queryF.length != "") {
if (!queryF || queryF.length == "") {
drawFile(queryF)
}
}
@ -50,6 +51,25 @@
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
function pushFile() {
const title = document.getElementById("title").innerHTML ? document.getElementById("title").innerHTML : ""
const body = easyMDE.value() ? easyMDE.value() : ""
const id = easyMDE.meta.id ? easyMDE.meta.id : ""
const pid = easyMDE.meta.pid ? easyMDE.meta.pid : ""
var method = "PUT"
if (id == "")
method = "POST"
headers = {}
if (title)
headers["Title"] = title
if (pid)
headers["Pid"] = pid
http(method, "/api/v0/files" + (id == "" ? "" : "/"+id), (body, status) => {
console.log(status, body)
alert("todo")
}, body, headers)
drawTree()
}
function drawFile(id) {
if (!id || id.length < 1) {
return
@ -67,7 +87,7 @@
setMDE("", pid, "", "")
}
function setMDE(id, pid, title, body) {
console.log(`set MDE: id=${id}, pid=${pid}, title=${title}, body=${body}`)
alert("TODO: set title as attr for prettier here")
document.getElementById("titlePath").innerHTML = `${pid ? "... / " : ""}<a href="#?f=${pid}"><input type="button" value="${pid}" onclick="drawFile('${pid}');"></a> / `
if (pid == "") {
document.getElementById("titlePath").innerHTML = "/"
@ -81,6 +101,7 @@
}
function drawTree() {
function htmlifyBranch(pid, id, branch) {
/* TODO width limit title */
var children = ""
for (var child in branch.Children)
children += "\n" + htmlifyBranch(id, child, branch.Children[child])
@ -109,7 +130,7 @@
document.getElementById("tree").innerHTML = innerHTML
})
}
function http(method, remote, callback, body) {
function http(method, remote, callback, body, headers) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == XMLHttpRequest.DONE) {
@ -120,6 +141,10 @@
if (typeof body == "undefined") {
body = null
}
if (headers) {
for (var key in headers)
xmlhttp.setRequestHeader(key, headers[key])
}
xmlhttp.send(body);
}
</script>
@ -137,6 +162,7 @@
<span id="titlePath">
</span>
<span id="title" contenteditable style="flex-grow: 1;"></span>
<input type="submit" value="SAVE" onclick="pushFile(); return false;"/>
</h1>
<textarea id="my-text-area"></textarea>
</article>