Add calendars, a web clipper, more importers and workspace snapshots
Phase F of the AFFiNE plan (ADR-16): - Calendars: people subscribe to iCal feeds (webcal, Google's secret address, Outlook) or CalDAV accounts in account settings; their events show at the top of journal pages in the reader's time zone. Repeats, moved and cancelled occurrences, IANA and Windows zones are handled. Events are read on demand and kept in memory for 15 minutes; passwords are sealed with DOCWELL_SECRET_KEY; sources follow the webhook address rules. New calendar_accounts collection. - Importers: zips of Markdown (Obsidian vaults, Bear TextBundles and .bear2bk, Readwise's Markdown, Docwell's own space export) keep folders as pages, resolve [[wikilinks]] and embeds by name, and turn front matter and #tags into properties and tags. OneNote .mht exports, Readwise CSV, and any other CSV as a database page. - Exports: PNG of a page drawn in the browser, print styles that print only the page in the light theme, and workspace snapshots (records, Yjs states, JSON and files in one zip) that restore as a new workspace. Old ids are swapped byte for byte inside the Yjs updates, so links point at the restored pages and comments stay anchored. - Web-Clipper/: a Manifest V3 extension for Chrome, Edge and Firefox that saves the article or the selection as Markdown through the import API with a personal API token. - OpenAPI, generated clients, translations and user docs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8c39b0aacb
commit
3d1cf362d7
71 files changed
+6951
-55
No files matched your search
@@ -59,17 +59,18 @@ func CurrentUser(ctx context.Context) (auth.User, bool) {
|
||||
}
|
||||
|
||||
type api struct {
|
||||
audit AuditService
|
||||
auth AuthService
|
||||
dir DirectoryService
|
||||
settings SettingsService
|
||||
files *auth.FileTokens
|
||||
instance InstanceService
|
||||
collab CollabHub
|
||||
previews LinkPreviewer
|
||||
push PushService
|
||||
ai AIService
|
||||
log *slog.Logger
|
||||
audit AuditService
|
||||
auth AuthService
|
||||
dir DirectoryService
|
||||
settings SettingsService
|
||||
files *auth.FileTokens
|
||||
instance InstanceService
|
||||
collab CollabHub
|
||||
previews LinkPreviewer
|
||||
push PushService
|
||||
ai AIService
|
||||
calendars CalendarService
|
||||
log *slog.Logger
|
||||
}
|
||||
|
||||
// requireUser lets in a signed-in user, or an API token acting as its owner
|
||||
@@ -224,6 +225,7 @@ func (a *api) routes(mux *routeMux) {
|
||||
a.commentRoutes(mux)
|
||||
a.adminRoutes(mux)
|
||||
a.aiRoutes(mux)
|
||||
a.calendarRoutes(mux)
|
||||
}
|
||||
|
||||
func (a *api) decode(w http.ResponseWriter, r *http.Request, v any) bool {
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"docwell/server/internal/access"
|
||||
"docwell/server/internal/apperr"
|
||||
"docwell/server/internal/calendar"
|
||||
)
|
||||
|
||||
// CalendarService reads people's calendars for their journals (ADR-16).
|
||||
type CalendarService interface {
|
||||
List(ctx context.Context, c access.Caller) ([]calendar.Account, error)
|
||||
Create(ctx context.Context, c access.Caller, in calendar.AccountInput) (calendar.Account, error)
|
||||
Update(ctx context.Context, c access.Caller, id string, in calendar.AccountInput) (calendar.Account, error)
|
||||
Delete(ctx context.Context, c access.Caller, id string) error
|
||||
Refresh(ctx context.Context, c access.Caller, id string) (calendar.Account, error)
|
||||
Events(ctx context.Context, c access.Caller, from, to, tz string) ([]calendar.Event, error)
|
||||
}
|
||||
|
||||
var errNoCalendars = apperr.NotFound("calendars are not available on this server")
|
||||
|
||||
func (a *api) withCalendars(next http.HandlerFunc) http.HandlerFunc {
|
||||
return a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
||||
if a.calendars == nil {
|
||||
a.writeError(w, errNoCalendars)
|
||||
return
|
||||
}
|
||||
next(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
func (a *api) calendarRoutes(mux *routeMux) {
|
||||
mux.HandleFunc("GET /api/v1/calendars", a.withCalendars(func(w http.ResponseWriter, r *http.Request) {
|
||||
v, err := a.calendars.List(r.Context(), caller(r))
|
||||
a.respond(w, v, err)
|
||||
}))
|
||||
mux.HandleFunc("POST /api/v1/calendars", a.withCalendars(func(w http.ResponseWriter, r *http.Request) {
|
||||
var in calendar.AccountInput
|
||||
if !a.decode(w, r, &in) {
|
||||
return
|
||||
}
|
||||
v, err := a.calendars.Create(r.Context(), caller(r), in)
|
||||
a.respondStatus(w, http.StatusCreated, v, err)
|
||||
}))
|
||||
mux.HandleFunc("PATCH /api/v1/calendars/{id}", a.withCalendars(func(w http.ResponseWriter, r *http.Request) {
|
||||
var in calendar.AccountInput
|
||||
if !a.decode(w, r, &in) {
|
||||
return
|
||||
}
|
||||
v, err := a.calendars.Update(r.Context(), caller(r), r.PathValue("id"), in)
|
||||
a.respond(w, v, err)
|
||||
}))
|
||||
mux.HandleFunc("DELETE /api/v1/calendars/{id}", a.withCalendars(func(w http.ResponseWriter, r *http.Request) {
|
||||
a.respondNoContent(w, a.calendars.Delete(r.Context(), caller(r), r.PathValue("id")))
|
||||
}))
|
||||
mux.HandleFunc("POST /api/v1/calendars/{id}/refresh", a.withCalendars(func(w http.ResponseWriter, r *http.Request) {
|
||||
v, err := a.calendars.Refresh(r.Context(), caller(r), r.PathValue("id"))
|
||||
a.respond(w, v, err)
|
||||
}))
|
||||
mux.HandleFunc("GET /api/v1/calendar/events", a.withCalendars(func(w http.ResponseWriter, r *http.Request) {
|
||||
q := r.URL.Query()
|
||||
v, err := a.calendars.Events(r.Context(), caller(r), q.Get("from"), q.Get("to"), q.Get("tz"))
|
||||
a.respond(w, v, err)
|
||||
}))
|
||||
}
|
||||
@@ -41,9 +41,11 @@ type Deps struct {
|
||||
// Audit records changes and serves the audit log; nil turns both off.
|
||||
Audit AuditService
|
||||
// AI serves chat, writing actions, profiles and MCP; nil turns them off.
|
||||
AI AIService
|
||||
Admin http.Handler
|
||||
Log *slog.Logger
|
||||
AI AIService
|
||||
// Calendars reads people's calendars for their journals; nil turns them off.
|
||||
Calendars CalendarService
|
||||
Admin http.Handler
|
||||
Log *slog.Logger
|
||||
}
|
||||
|
||||
// routeMux is a ServeMux that remembers its patterns, so a test can compare
|
||||
@@ -81,6 +83,9 @@ func newMux(d Deps) *routeMux {
|
||||
if d.AI != nil {
|
||||
a.ai = d.AI
|
||||
}
|
||||
if d.Calendars != nil {
|
||||
a.calendars = d.Calendars
|
||||
}
|
||||
a.routes(mux)
|
||||
a.fileRoutes(mux, max(d.MaxUpload, 1<<20))
|
||||
a.collabRoute(mux, d.CORSOrigins)
|
||||
|
||||
@@ -18,6 +18,8 @@ type TransferService interface {
|
||||
ExportPage(ctx context.Context, c access.Caller, id, format string) (directory.Export, error)
|
||||
ImportPages(ctx context.Context, c access.Caller, spaceID, parent string, files []directory.ImportFile) ([]directory.Page, error)
|
||||
PrepareSpaceExport(ctx context.Context, c access.Caller, spaceID, format string) (*directory.SpaceExport, error)
|
||||
PrepareSnapshot(ctx context.Context, c access.Caller, wsID string) (*directory.Snapshot, error)
|
||||
RestoreSnapshot(ctx context.Context, c access.Caller, in directory.RestoreInput) (directory.Workspace, error)
|
||||
}
|
||||
|
||||
// maxImportRequest caps one import request: up to 20 files, each within its
|
||||
@@ -54,6 +56,43 @@ func (a *api) transferRoutes(mux *routeMux) {
|
||||
a.log.Warn("space export failed", "space", r.PathValue("id"), "err", err)
|
||||
}
|
||||
}))
|
||||
mux.HandleFunc("GET /api/v1/workspaces/{id}/snapshot", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
||||
e, err := a.dir.PrepareSnapshot(r.Context(), caller(r), r.PathValue("id"))
|
||||
if err != nil {
|
||||
a.writeError(w, err)
|
||||
return
|
||||
}
|
||||
h := w.Header()
|
||||
h.Set("Content-Type", "application/zip")
|
||||
h.Set("Content-Disposition", mime.FormatMediaType("attachment", map[string]string{"filename": e.Filename}))
|
||||
h.Set("X-Content-Type-Options", "nosniff")
|
||||
if err := e.WriteTo(r.Context(), w); err != nil {
|
||||
a.log.Warn("snapshot failed", "workspace", r.PathValue("id"), "err", err)
|
||||
}
|
||||
}))
|
||||
mux.HandleFunc("POST /api/v1/workspaces/restore", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
||||
r.Body = http.MaxBytesReader(w, r.Body, directory.MaxSnapshot+1<<20)
|
||||
if err := r.ParseMultipartForm(32 << 20); err != nil { // The snapshot spills to a temporary file.
|
||||
writeJSON(w, http.StatusBadRequest, map[string]string{"error": "invalid", "message": "expected multipart/form-data with a snapshot file"})
|
||||
return
|
||||
}
|
||||
defer func() { _ = r.MultipartForm.RemoveAll() }()
|
||||
files := r.MultipartForm.File["file"]
|
||||
if len(files) != 1 {
|
||||
writeJSON(w, http.StatusBadRequest, map[string]string{"error": "invalid", "message": "send one snapshot file"})
|
||||
return
|
||||
}
|
||||
f, err := files[0].Open()
|
||||
if err != nil {
|
||||
a.writeError(w, err)
|
||||
return
|
||||
}
|
||||
defer func() { _ = f.Close() }()
|
||||
ws, err := a.dir.RestoreSnapshot(r.Context(), caller(r), directory.RestoreInput{
|
||||
Organization: r.FormValue("organization"), Name: r.FormValue("name"), File: f, Size: files[0].Size,
|
||||
})
|
||||
a.respondStatus(w, http.StatusCreated, ws, err)
|
||||
}))
|
||||
mux.HandleFunc("POST /api/v1/spaces/{id}/import", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
||||
r.Body = http.MaxBytesReader(w, r.Body, maxImportRequest)
|
||||
if err := r.ParseMultipartForm(32 << 20); err != nil { // Larger uploads spill to temporary files.
|
||||
|
||||
Reference in new issue
Block a user