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 { if r.Method != http.MethodPost {
return "", errors.New("not found") 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") { if strings.HasPrefix(r.Header.Get("Content-Type"), "multipart/form-data") {
kb := int64(1 << 10) kb := int64(1 << 10)
mb := kb << 10 mb := kb << 10

View File

@ -1,30 +1,25 @@
A: 6c090e2f:
title: A title: Untitled (2022-02-09 00:08:51.502773 +0000 UTC)
deleted: false 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: "" pid: ""
AA: "98400812":
title: AA title: b
deleted: false deleted: false
updated: 2022-02-08T23:40:44.966702Z updated: 2022-02-09T00:08:36.820551Z
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
pid: "" pid: ""
b7fe2c91-6bd7-4b49-8590-4223ccc772ac: a84cdde6:
title: my file title title: c
deleted: false deleted: false
updated: 2022-02-08T19:43:47.438639Z updated: 2022-02-09T00:08:43.611391Z
pid: "" pid: ""
f927298b:
title: d
deleted: false
updated: 2022-02-09T00:08:48.393336Z
pid: "98400812"

View File

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