Canvas support V1

This commit is contained in:
2026-10-04 15:28:06 +02:00
parent 7749d7c237
commit 2903986f44
20 changed files with 3223 additions and 482 deletions
+13 -1
View File
@@ -32,7 +32,7 @@ var tmplFuncs = template.FuncMap{
var (
pageTmpl = template.Must(template.New("page").Funcs(tmplFuncs).ParseFS(assets, "assets/layout.html", "assets/page/main.html"))
editTmpl = template.Must(template.New("edit").Funcs(tmplFuncs).ParseFS(assets, "assets/layout.html", "assets/editor/main.html"))
editTmpl = template.Must(template.New("edit").Funcs(tmplFuncs).ParseFS(assets, "assets/layout.html", "assets/editor/toolbar.html", "assets/editor/main.html"))
searchTmpl = template.Must(template.New("search").Funcs(tmplFuncs).ParseFS(assets, "assets/layout.html", "assets/search/main.html"))
)
@@ -241,6 +241,12 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
info, err := os.Stat(fsPath)
if err != nil {
if os.IsNotExist(err) {
// A canvas deleted or moved while open: don't let its autosave
// fall through to the page flow below.
if r.Method == http.MethodPost && isCanvasFile(urlPath) {
http.Error(w, "this canvas no longer exists", http.StatusNotFound)
return
}
// Non-existent path: redirect GETs to the canonical slash form so
// the browser URL is consistent, then serve an empty folder page.
// POSTs must not be redirected — the form action has no trailing
@@ -267,6 +273,8 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
urlPath += "/"
}
h.serveDir(w, r, urlPath, fsPath)
} else if isCanvasFile(fsPath) {
h.serveCanvas(w, r, urlPath, fsPath)
} else {
// ?w= on a file's own URL serves a thumbnail. Embeds use this form so
// their <img src> can stay relative to the page; /_thumb/<abs path>
@@ -474,6 +482,10 @@ func (h *handler) handlePost(w http.ResponseWriter, r *http.Request, urlPath, fs
h.handleSettings(w, r, urlPath, fsPath)
return
}
if query.Has("canvas") {
h.handleCanvasCreate(w, r, urlPath, fsPath)
return
}
if query.Has("calsync") {
h.handleCalendarSync(w, r, urlPath, fsPath)
return