Add notebook delete, fix button styling, rename Share button
- Add delete notebook handler with ownership check and CASCADE delete - Rename "Create Share Link" to "Share" - Fix action button heights: use inline-flex + align-items for consistent sizing across <a> and <button> elements Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -248,6 +248,23 @@ func (ws *WebServer) handleCreateShare(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, fmt.Sprintf("/notebooks/%d", id), http.StatusFound)
|
||||
}
|
||||
|
||||
func (ws *WebServer) handleDeleteNotebook(w http.ResponseWriter, r *http.Request) {
|
||||
userID := r.Context().Value(userIDKey).(int64)
|
||||
id, _ := strconv.ParseInt(chi.URLParam(r, "id"), 10, 64)
|
||||
|
||||
// Verify ownership before deleting.
|
||||
var ownerID int64
|
||||
err := ws.db.QueryRow("SELECT user_id FROM notebooks WHERE id = ?", id).Scan(&ownerID)
|
||||
if err != nil || ownerID != userID {
|
||||
http.Error(w, "Not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
// CASCADE deletes pages, strokes, and share_links.
|
||||
_, _ = ws.db.Exec("DELETE FROM notebooks WHERE id = ?", id)
|
||||
http.Redirect(w, r, "/notebooks", 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")
|
||||
|
||||
@@ -112,6 +112,7 @@ func Start(cfg Config) (*http.Server, error) {
|
||||
r.Get("/notebooks/{id}/pages/{num}/svg", ws.handlePageSVG)
|
||||
r.Get("/notebooks/{id}/pages/{num}/jpg", ws.handlePageJPG)
|
||||
r.Get("/notebooks/{id}/pdf", ws.handleNotebookPDF)
|
||||
r.Post("/notebooks/{id}/delete", ws.handleDeleteNotebook)
|
||||
r.Post("/notebooks/{id}/share", ws.handleCreateShare)
|
||||
r.Post("/notebooks/{id}/share/revoke", ws.handleRevokeShare)
|
||||
r.Get("/logout", ws.handleLogout)
|
||||
|
||||
Reference in New Issue
Block a user