Add rendering routes and share UI to web server

The web UI was linking to /v1/ REST API paths that aren't served
through nginx. Added SVG/JPG/PDF rendering and share link endpoints
directly to the web server so everything works through port 443.

- Add render.go with SVG, JPG, PDF handlers for auth and share paths
- Register render routes and share management routes in web server
- Update template links from /v1/... to /notebooks/... paths
- Add share link creation, display, and revocation to notebook view

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-25 09:22:07 -07:00
parent ab2884a8e9
commit aeb12d9f50
4 changed files with 297 additions and 7 deletions

View File

@@ -128,15 +128,21 @@ func (ws *WebServer) handleNotebook(w http.ResponseWriter, r *http.Request) {
}
pages = append(pages, pageInfo{
Number: num,
SVGLink: fmt.Sprintf("/v1/notebooks/%d/pages/%d/svg", id, num),
SVGLink: fmt.Sprintf("/notebooks/%d/pages/%d/svg", id, num),
ViewLink: fmt.Sprintf("/notebooks/%d/pages/%d", id, num),
})
}
// Load share links for this notebook.
shareLinks, _ := share.ListLinks(ws.db, id, ws.baseURL)
ws.render(w, "notebook.html", map[string]any{
"Title": title,
"Pages": pages,
"PDFLink": fmt.Sprintf("/v1/notebooks/%d/pdf", id),
"ID": id,
"Title": title,
"Pages": pages,
"PDFLink": fmt.Sprintf("/notebooks/%d/pdf", id),
"ShareLinks": shareLinks,
"BaseURL": ws.baseURL,
})
}
@@ -155,9 +161,9 @@ func (ws *WebServer) handlePage(w http.ResponseWriter, r *http.Request) {
"NotebookTitle": title,
"PageNumber": num,
"BackLink": fmt.Sprintf("/notebooks/%d", id),
"SVGLink": fmt.Sprintf("/v1/notebooks/%d/pages/%d/svg", id, num),
"JPGLink": fmt.Sprintf("/v1/notebooks/%d/pages/%d/jpg", id, num),
"PDFLink": fmt.Sprintf("/v1/notebooks/%d/pdf", id),
"SVGLink": fmt.Sprintf("/notebooks/%d/pages/%d/svg", id, num),
"JPGLink": fmt.Sprintf("/notebooks/%d/pages/%d/jpg", id, num),
"PDFLink": fmt.Sprintf("/notebooks/%d/pdf", id),
})
}
@@ -202,6 +208,7 @@ func (ws *WebServer) handleShareNotebook(w http.ResponseWriter, r *http.Request)
"Title": title,
"Pages": pages,
"PDFLink": fmt.Sprintf("/s/%s/pdf", token),
"Shared": true,
})
}
@@ -228,6 +235,28 @@ func (ws *WebServer) handleSharePage(w http.ResponseWriter, r *http.Request) {
})
}
// --- Share management ---
func (ws *WebServer) handleCreateShare(w http.ResponseWriter, r *http.Request) {
id, _ := strconv.ParseInt(chi.URLParam(r, "id"), 10, 64)
_, _, err := share.CreateLink(ws.db, id, 0, ws.baseURL) // no expiry
if err != nil {
slog.Error("create share link", "error", err)
http.Error(w, "Failed to create share link", http.StatusInternalServerError)
return
}
http.Redirect(w, r, fmt.Sprintf("/notebooks/%d", id), http.StatusFound)
}
func (ws *WebServer) handleRevokeShare(w http.ResponseWriter, r *http.Request) {
id, _ := strconv.ParseInt(chi.URLParam(r, "id"), 10, 64)
token := r.FormValue("token")
if token != "" {
_ = share.RevokeLink(ws.db, token)
}
http.Redirect(w, r, fmt.Sprintf("/notebooks/%d", id), http.StatusFound)
}
// --- auth middleware ---
type ctxKey string