Editor:
- Toggles (Tiptap Details). Open state is per reader, not saved.
- Embeds for YouTube, Vimeo, Loom, Figma, CodePen, Spotify, Google Docs
and Maps, in sandboxed frames. Other addresses become link cards.
- Link cards with title, description and picture read by docwell-server
(GET /link-preview). The fetcher refuses private, loopback, link-local
and CGNAT addresses after DNS resolution, redirects included.
- Block links: a margin button gives a block a short id and copies
/p/<id>#b-<block>. Opening one jumps to the block and flashes it.
- Markdown, HTML and PDF exports handle the new blocks; HTML import reads
<details> as a toggle.
Pages and spaces:
- History gets a Changes view: block and word diff against the previous
version or the page as it is now.
- Archive: archived pages leave the tree and become read-only but stay
readable; a space's Archive lists them with Unarchive. New migration
(pages.archived_at) and page.archived / page.unarchived webhook events.
- Full space export (GET /spaces/{id}/export): a zip of Markdown or HTML
files with subpages in folders, an index, and attachments under _files/.
Links between exported pages and to attachments become relative paths.
Desktop 1.0:
- Several servers, each with its own sign-in; old settings files carry over.
- Session tokens in the system keychain (go-keyring), moved out of
localStorage on first start.
- Native menu bar (File, Edit, View, Window, Help) with a Server submenu.
- docwell:// links may point at a block.
- Release workflow builds Windows NSIS, macOS DMG and Linux deb, rpm and
AppImage installers and attaches them to the release;
build/set-version.mjs stamps the version into their metadata.
Not yet run: the release workflow, the desktop menus by eye, and macOS or
Linux builds.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
176 lines
8.8 KiB
Go
176 lines
8.8 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
package httpapi
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"docwell/server/internal/access"
|
|
"docwell/server/internal/collab"
|
|
"docwell/server/internal/directory"
|
|
)
|
|
|
|
// SpaceService is the part of directory.Service that serves spaces and pages.
|
|
type SpaceService interface {
|
|
ListSpaces(ctx context.Context, c access.Caller, wsID string) ([]directory.Space, error)
|
|
CreateSpace(ctx context.Context, c access.Caller, wsID string, in directory.CreateSpaceInput) (directory.Space, error)
|
|
GetSpace(ctx context.Context, c access.Caller, id string) (directory.Space, error)
|
|
UpdateSpace(ctx context.Context, c access.Caller, id string, in directory.UpdateSpaceInput) (directory.Space, error)
|
|
DeleteSpace(ctx context.Context, c access.Caller, id string) error
|
|
ListSpaceMembers(ctx context.Context, c access.Caller, id string) ([]directory.Member, error)
|
|
SetSpaceMember(ctx context.Context, c access.Caller, id, email, role string) (directory.Member, error)
|
|
RemoveSpaceMember(ctx context.Context, c access.Caller, id, userID string) error
|
|
|
|
ListPages(ctx context.Context, c access.Caller, spaceID string) ([]directory.PageNode, error)
|
|
CreatePage(ctx context.Context, c access.Caller, spaceID string, in directory.CreatePageInput) (directory.Page, error)
|
|
GetPage(ctx context.Context, c access.Caller, id string) (directory.Page, error)
|
|
UpdatePage(ctx context.Context, c access.Caller, id string, in directory.UpdatePageInput) (directory.Page, error)
|
|
GetPageContent(ctx context.Context, c access.Caller, id string) (directory.PageContent, error)
|
|
SavePageContent(ctx context.Context, c access.Caller, id string, in directory.SavePageContentInput) (directory.PageContent, error)
|
|
CollabAccess(ctx context.Context, c access.Caller, id string) (canWrite bool, err error)
|
|
ListVersions(ctx context.Context, c access.Caller, id string) ([]collab.Version, error)
|
|
GetVersion(ctx context.Context, c access.Caller, id, versionID string) (directory.PageContent, error)
|
|
RestoreVersion(ctx context.Context, c access.Caller, id, versionID string) (directory.PageContent, error)
|
|
MovePage(ctx context.Context, c access.Caller, id string, in directory.MovePageInput) (directory.Page, error)
|
|
TrashPage(ctx context.Context, c access.Caller, id string) error
|
|
RestorePage(ctx context.Context, c access.Caller, id string) (directory.Page, error)
|
|
ListTrash(ctx context.Context, c access.Caller, spaceID string) ([]directory.TrashedPage, error)
|
|
PurgePage(ctx context.Context, c access.Caller, id string) error
|
|
ArchivePage(ctx context.Context, c access.Caller, id string) (directory.Page, error)
|
|
UnarchivePage(ctx context.Context, c access.Caller, id string) (directory.Page, error)
|
|
ListArchive(ctx context.Context, c access.Caller, spaceID string) ([]directory.ArchivedPage, error)
|
|
}
|
|
|
|
func (a *api) spaceRoutes(mux *routeMux) {
|
|
// Spaces. Rights are resolved per space (see access.SpaceRole).
|
|
mux.HandleFunc("GET /api/v1/workspaces/{id}/spaces", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
list, err := a.dir.ListSpaces(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, list, err)
|
|
}))
|
|
mux.HandleFunc("POST /api/v1/workspaces/{id}/spaces", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
var in directory.CreateSpaceInput
|
|
if !a.decode(w, r, &in) {
|
|
return
|
|
}
|
|
sp, err := a.dir.CreateSpace(r.Context(), caller(r), r.PathValue("id"), in)
|
|
a.respondStatus(w, http.StatusCreated, sp, err)
|
|
}))
|
|
mux.HandleFunc("GET /api/v1/spaces/{id}", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
sp, err := a.dir.GetSpace(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, sp, err)
|
|
}))
|
|
mux.HandleFunc("PATCH /api/v1/spaces/{id}", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
var in directory.UpdateSpaceInput
|
|
if !a.decode(w, r, &in) {
|
|
return
|
|
}
|
|
sp, err := a.dir.UpdateSpace(r.Context(), caller(r), r.PathValue("id"), in)
|
|
a.respond(w, sp, err)
|
|
}))
|
|
mux.HandleFunc("DELETE /api/v1/spaces/{id}", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
a.respondNoContent(w, a.dir.DeleteSpace(r.Context(), caller(r), r.PathValue("id")))
|
|
}))
|
|
mux.HandleFunc("GET /api/v1/spaces/{id}/members", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
members, err := a.dir.ListSpaceMembers(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, members, err)
|
|
}))
|
|
mux.HandleFunc("PUT /api/v1/spaces/{id}/members", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
var in struct{ Email, Role string }
|
|
if !a.decode(w, r, &in) {
|
|
return
|
|
}
|
|
m, err := a.dir.SetSpaceMember(r.Context(), caller(r), r.PathValue("id"), in.Email, in.Role)
|
|
a.respond(w, m, err)
|
|
}))
|
|
mux.HandleFunc("DELETE /api/v1/spaces/{id}/members/{userId}", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
a.respondNoContent(w, a.dir.RemoveSpaceMember(r.Context(), caller(r), r.PathValue("id"), r.PathValue("userId")))
|
|
}))
|
|
|
|
// Page tree and trash.
|
|
mux.HandleFunc("GET /api/v1/spaces/{id}/pages", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
pages, err := a.dir.ListPages(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, pages, err)
|
|
}))
|
|
mux.HandleFunc("POST /api/v1/spaces/{id}/pages", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
var in directory.CreatePageInput
|
|
if !a.decode(w, r, &in) {
|
|
return
|
|
}
|
|
p, err := a.dir.CreatePage(r.Context(), caller(r), r.PathValue("id"), in)
|
|
a.respondStatus(w, http.StatusCreated, p, err)
|
|
}))
|
|
mux.HandleFunc("GET /api/v1/spaces/{id}/trash", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
pages, err := a.dir.ListTrash(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, pages, err)
|
|
}))
|
|
mux.HandleFunc("GET /api/v1/spaces/{id}/archive", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
pages, err := a.dir.ListArchive(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, pages, err)
|
|
}))
|
|
mux.HandleFunc("GET /api/v1/pages/{id}", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
p, err := a.dir.GetPage(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, p, err)
|
|
}))
|
|
mux.HandleFunc("POST /api/v1/pages/{id}/archive", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
p, err := a.dir.ArchivePage(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, p, err)
|
|
}))
|
|
mux.HandleFunc("POST /api/v1/pages/{id}/unarchive", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
p, err := a.dir.UnarchivePage(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, p, err)
|
|
}))
|
|
mux.HandleFunc("PATCH /api/v1/pages/{id}", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
var in directory.UpdatePageInput
|
|
if !a.decode(w, r, &in) {
|
|
return
|
|
}
|
|
p, err := a.dir.UpdatePage(r.Context(), caller(r), r.PathValue("id"), in)
|
|
a.respond(w, p, err)
|
|
}))
|
|
mux.HandleFunc("GET /api/v1/pages/{id}/content", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
c, err := a.dir.GetPageContent(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, c, err)
|
|
}))
|
|
mux.HandleFunc("PUT /api/v1/pages/{id}/content", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
var in directory.SavePageContentInput
|
|
if !a.decodeMax(w, r, &in, 10<<20) {
|
|
return
|
|
}
|
|
c, err := a.dir.SavePageContent(r.Context(), caller(r), r.PathValue("id"), in)
|
|
a.respond(w, c, err)
|
|
}))
|
|
mux.HandleFunc("GET /api/v1/pages/{id}/versions", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
v, err := a.dir.ListVersions(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, v, err)
|
|
}))
|
|
mux.HandleFunc("GET /api/v1/pages/{id}/versions/{versionId}", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
c, err := a.dir.GetVersion(r.Context(), caller(r), r.PathValue("id"), r.PathValue("versionId"))
|
|
a.respond(w, c, err)
|
|
}))
|
|
mux.HandleFunc("POST /api/v1/pages/{id}/versions/{versionId}/restore", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
c, err := a.dir.RestoreVersion(r.Context(), caller(r), r.PathValue("id"), r.PathValue("versionId"))
|
|
a.respond(w, c, err)
|
|
}))
|
|
mux.HandleFunc("POST /api/v1/pages/{id}/move", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
var in directory.MovePageInput
|
|
if !a.decode(w, r, &in) {
|
|
return
|
|
}
|
|
p, err := a.dir.MovePage(r.Context(), caller(r), r.PathValue("id"), in)
|
|
a.respond(w, p, err)
|
|
}))
|
|
mux.HandleFunc("POST /api/v1/pages/{id}/restore", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
p, err := a.dir.RestorePage(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, p, err)
|
|
}))
|
|
// DELETE moves to the trash; ?permanent=true purges a page that is already there.
|
|
mux.HandleFunc("DELETE /api/v1/pages/{id}", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Query().Get("permanent") == "true" {
|
|
a.respondNoContent(w, a.dir.PurgePage(r.Context(), caller(r), r.PathValue("id")))
|
|
return
|
|
}
|
|
a.respondNoContent(w, a.dir.TrashPage(r.Context(), caller(r), r.PathValue("id")))
|
|
}))
|
|
}
|