Add columns, suggesting mode, verified pages, scanned PDF search and server translations
CI / go (Media) (push) Successful in 13m40s
CI / go (Server) (push) Failing after 23m20s
CI / go (Web-App) (push) Canceled after 0s
CI / frontend (push) Failing after 10m35s
Docs / build (push) Canceled after 0s
Docs / deploy (push) Canceled after 0s
CI / desktop (ubuntu-latest) (push) Failing after 3h4m42s
CI / desktop (macos-latest) (push) Canceled after 0s
CI / desktop (windows-latest) (push) Canceled after 0s
CI / mobile (push) Failing after 9m19s
CI / docker (push) Successful in 2h2m57s
CI / go (Media) (push) Successful in 13m40s
CI / go (Server) (push) Failing after 23m20s
CI / go (Web-App) (push) Canceled after 0s
CI / frontend (push) Failing after 10m35s
Docs / build (push) Canceled after 0s
Docs / deploy (push) Canceled after 0s
CI / desktop (ubuntu-latest) (push) Failing after 3h4m42s
CI / desktop (macos-latest) (push) Canceled after 0s
CI / desktop (windows-latest) (push) Canceled after 0s
CI / mobile (push) Failing after 9m19s
CI / docker (push) Successful in 2h2m57s
- Columns: /columns puts 2 to 4 columns side by side, with widths dragged between them; they stack on phones. HTML export and import keep them (also Notion column lists and Confluence page layouts). - Suggesting mode: edits become suggested insertions and deletions that editors accept or reject one by one or all at once. Text only. - Verified pages: editors verify a page for a while or without end; the verifier is notified when it runs out (migration 1764700000). - Scanned PDFs attached to pages are read by AI for search where a workspace turns it on. - The server writes error messages, emails, digests and phone notifications in English, Polish, German, French and Spanish; the apps send their language with each request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1696f2e77e
commit
c98b127f1e
94 files changed
+5042
-112
No files matched your search
@@ -15,6 +15,7 @@ import (
|
||||
"docwell/server/internal/apperr"
|
||||
"docwell/server/internal/audit"
|
||||
"docwell/server/internal/auth"
|
||||
"docwell/server/internal/i18n"
|
||||
)
|
||||
|
||||
// AIService is the AI layer (ADR-15).
|
||||
@@ -323,7 +324,7 @@ func (a *api) streamError(w http.ResponseWriter, out *sse, err error) {
|
||||
} else if r := err.Error(); r != "" && !strings.Contains(r, "context canceled") {
|
||||
a.log.Warn("ai stream failed", "err", err)
|
||||
}
|
||||
out.send("error", map[string]string{"message": msg})
|
||||
out.send("error", map[string]string{"message": i18n.Translate(responseLang(w), msg)})
|
||||
}
|
||||
|
||||
// mcpRoute serves the MCP endpoint. Its clients send API tokens (or
|
||||
|
||||
@@ -9,14 +9,17 @@ import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"docwell/server/internal/access"
|
||||
"docwell/server/internal/apperr"
|
||||
"docwell/server/internal/auth"
|
||||
"docwell/server/internal/i18n"
|
||||
)
|
||||
|
||||
// AuthService is the part of auth.Service the HTTP layer uses.
|
||||
type AuthService interface {
|
||||
SetLocale(ctx context.Context, userID, lang string) error
|
||||
Methods(ctx context.Context) (auth.Methods, error)
|
||||
Signup(ctx context.Context, in auth.SignupInput) (auth.Session, error)
|
||||
Login(ctx context.Context, email, password, mfaID string) (auth.Session, error)
|
||||
@@ -76,6 +79,8 @@ type api struct {
|
||||
// wsIntegrations: GitHub, Linear, Figma and Slack per workspace.
|
||||
wsIntegrations WorkspaceIntegrations
|
||||
log *slog.Logger
|
||||
// locales remembers which language was last stored per user (lang.go).
|
||||
locales sync.Map
|
||||
}
|
||||
|
||||
// requireUser lets in a signed-in user, or an API token acting as its owner
|
||||
@@ -101,6 +106,7 @@ func (a *api) requireUser(next http.HandlerFunc) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
r = r.WithContext(context.WithValue(ctx, ctxKey{}, u))
|
||||
a.rememberLocale(r, u)
|
||||
if r.Method == http.MethodGet || r.Method == http.MethodHead || a.audit == nil || unaudited[r.Pattern] {
|
||||
next(w, r)
|
||||
return
|
||||
@@ -275,9 +281,14 @@ func (a *api) writeError(w http.ResponseWriter, err error) {
|
||||
apperr.KindNotFound: http.StatusNotFound,
|
||||
apperr.KindConflict: http.StatusConflict,
|
||||
}[e.Kind]
|
||||
body := map[string]any{"error": e.Code, "message": e.Message}
|
||||
lang := responseLang(w)
|
||||
body := map[string]any{"error": e.Code, "message": i18n.Translate(lang, e.Message)}
|
||||
if len(e.Fields) > 0 {
|
||||
body["fields"] = e.Fields
|
||||
fields := make(map[string]string, len(e.Fields))
|
||||
for k, v := range e.Fields {
|
||||
fields[k] = i18n.Translate(lang, v)
|
||||
}
|
||||
body["fields"] = fields
|
||||
}
|
||||
writeJSON(w, status, body)
|
||||
return
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"docwell/server/internal/auth"
|
||||
"docwell/server/internal/i18n"
|
||||
)
|
||||
|
||||
// Languages: the apps send the language they show in Accept-Language. Each
|
||||
// response says its language in Content-Language, error messages are
|
||||
// translated into it (writeError), and the request's context carries it for
|
||||
// text written while handling it (invite emails). A signed-in person's last
|
||||
// language is stored for the emails and notifications they get later.
|
||||
|
||||
// withLang sets a request's language on its context and response.
|
||||
func withLang(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
lang := i18n.Match(r.Header.Get("Accept-Language"))
|
||||
w.Header().Set("Content-Language", lang)
|
||||
next.ServeHTTP(w, r.WithContext(i18n.WithLang(r.Context(), lang)))
|
||||
})
|
||||
}
|
||||
|
||||
// responseLang is the language withLang chose for a response.
|
||||
func responseLang(w http.ResponseWriter) string {
|
||||
if l := w.Header().Get("Content-Language"); i18n.IsSupported(l) {
|
||||
return l
|
||||
}
|
||||
return i18n.Default
|
||||
}
|
||||
|
||||
// rememberLocale stores the language a signed-in person uses when it
|
||||
// changed (in the background; once per user and language per process).
|
||||
func (a *api) rememberLocale(r *http.Request, u auth.User) {
|
||||
lang, ok := i18n.MatchOK(r.Header.Get("Accept-Language"))
|
||||
if !ok || u.ID == "" || lang == u.Locale {
|
||||
return
|
||||
}
|
||||
if prev, seen := a.locales.Load(u.ID); seen && prev == lang {
|
||||
return
|
||||
}
|
||||
a.locales.Store(u.ID, lang)
|
||||
go func() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
if err := a.auth.SetLocale(ctx, u.ID, lang); err != nil {
|
||||
a.locales.Delete(u.ID)
|
||||
a.log.Warn("remember locale", "user", u.ID, "err", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
@@ -65,7 +65,7 @@ type routeMux struct {
|
||||
|
||||
func (m *routeMux) Handle(pattern string, h http.Handler) {
|
||||
m.patterns = append(m.patterns, pattern)
|
||||
m.ServeMux.Handle(pattern, h)
|
||||
m.ServeMux.Handle(pattern, withLang(h))
|
||||
}
|
||||
|
||||
func (m *routeMux) HandleFunc(pattern string, h func(http.ResponseWriter, *http.Request)) {
|
||||
|
||||
@@ -42,6 +42,8 @@ type SpaceService interface {
|
||||
ListArchive(ctx context.Context, c access.Caller, spaceID string) ([]directory.ArchivedPage, error)
|
||||
PinPage(ctx context.Context, c access.Caller, id string) (directory.Page, error)
|
||||
UnpinPage(ctx context.Context, c access.Caller, id string) (directory.Page, error)
|
||||
VerifyPage(ctx context.Context, c access.Caller, id string, days int) (directory.Page, error)
|
||||
UnverifyPage(ctx context.Context, c access.Caller, id string) (directory.Page, error)
|
||||
ListPinned(ctx context.Context, c access.Caller, spaceID string) ([]directory.PinnedPage, error)
|
||||
}
|
||||
|
||||
@@ -123,6 +125,20 @@ func (a *api) spaceRoutes(mux *routeMux) {
|
||||
p, err := a.dir.UnpinPage(r.Context(), caller(r), r.PathValue("id"))
|
||||
a.respond(w, p, err)
|
||||
}))
|
||||
mux.HandleFunc("PUT /api/v1/pages/{id}/verify", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
||||
var in struct {
|
||||
Days int `json:"days"`
|
||||
}
|
||||
if !a.decode(w, r, &in) {
|
||||
return
|
||||
}
|
||||
p, err := a.dir.VerifyPage(r.Context(), caller(r), r.PathValue("id"), in.Days)
|
||||
a.respond(w, p, err)
|
||||
}))
|
||||
mux.HandleFunc("DELETE /api/v1/pages/{id}/verify", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
||||
p, err := a.dir.UnverifyPage(r.Context(), caller(r), r.PathValue("id"))
|
||||
a.respond(w, p, 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)
|
||||
|
||||
Reference in new issue
Block a user