Implement Knowledge City platform, organizer and DAV integration
Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
This commit is contained in:
1 parent
288e6e94ac
commit
c1175d389f
699 files changed
+110197
-4117
No files matched your search
@@ -2,63 +2,76 @@ package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"pageswiki/internal/store"
|
||||
)
|
||||
|
||||
func (s *Server) handleRevisionListAPI(
|
||||
w http.ResponseWriter,
|
||||
r *http.Request,
|
||||
) {
|
||||
func revisionListOptions(r *http.Request) (string, int, error) {
|
||||
before := r.URL.Query().Get("before")
|
||||
if len(before) > 128 {
|
||||
return "", 0, store.ErrRevisionCursor
|
||||
}
|
||||
limit := 100
|
||||
if raw := r.URL.Query().Get("limit"); raw != "" {
|
||||
var err error
|
||||
limit, err = strconv.Atoi(raw)
|
||||
if err != nil || limit < 1 || limit > 200 {
|
||||
return "", 0, errors.New("limit must be between 1 and 200")
|
||||
}
|
||||
}
|
||||
return before, limit, nil
|
||||
}
|
||||
|
||||
uuid := r.URL.Query().Get(
|
||||
"uuid",
|
||||
)
|
||||
func revisionPageURL(r *http.Request, before string) string {
|
||||
query := r.URL.Query()
|
||||
query.Del("before")
|
||||
if before != "" {
|
||||
query.Set("before", before)
|
||||
}
|
||||
return (&url.URL{Path: r.URL.Path, RawQuery: query.Encode()}).String()
|
||||
}
|
||||
|
||||
rows, err := s.store.DB.Query(`
|
||||
SELECT
|
||||
uuid,
|
||||
message,
|
||||
created_at
|
||||
FROM revisions
|
||||
WHERE object_uuid = ?
|
||||
ORDER BY created_at DESC
|
||||
`, uuid)
|
||||
|
||||
if err != nil {
|
||||
http.Error(
|
||||
w,
|
||||
err.Error(),
|
||||
500,
|
||||
)
|
||||
func (s *Server) handleRevisionListAPI(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.Header().Set("Cache-Control", "private, no-store")
|
||||
w.Header().Set("Vary", "Authorization, Cookie")
|
||||
if r.Method != http.MethodGet && r.Method != http.MethodHead {
|
||||
w.Header().Set("Allow", "GET, HEAD")
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
defer rows.Close()
|
||||
|
||||
var out []map[string]any
|
||||
|
||||
for rows.Next() {
|
||||
|
||||
var revisionUUID string
|
||||
var message string
|
||||
var createdAt int64
|
||||
|
||||
err := rows.Scan(
|
||||
&revisionUUID,
|
||||
&message,
|
||||
&createdAt,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
continue
|
||||
object := r.URL.Query().Get("uuid")
|
||||
if object == "" || s.authorizeObjectForRequest(r, "read", object) != nil {
|
||||
http.Error(w, "forbidden", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
before, limit, err := revisionListOptions(r)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
page, err := s.store.ListRevisionPage(r.Context(), object, before, limit)
|
||||
if err != nil {
|
||||
if errors.Is(err, store.ErrRevisionCursor) {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
} else {
|
||||
http.Error(w, "revision listing unavailable", http.StatusServiceUnavailable)
|
||||
}
|
||||
|
||||
out = append(out, map[string]any{
|
||||
"uuid": revisionUUID,
|
||||
"message": message,
|
||||
"created_at": createdAt,
|
||||
})
|
||||
return
|
||||
}
|
||||
if page.Next != "" {
|
||||
w.Header().Set("X-Next-Cursor", page.Next)
|
||||
w.Header().Set("Link", "<"+revisionPageURL(r, page.Next)+">; rel=\"next\"")
|
||||
}
|
||||
out := make([]map[string]any, 0, len(page.Items))
|
||||
for _, item := range page.Items {
|
||||
out = append(out, map[string]any{"uuid": item.UUID, "message": item.Message, "created_at": item.CreatedAt, "lang": item.Language, "document_hash": item.DocumentHash})
|
||||
}
|
||||
if r.Method != http.MethodHead {
|
||||
_ = json.NewEncoder(w).Encode(out)
|
||||
}
|
||||
|
||||
_ = json.NewEncoder(w).Encode(out)
|
||||
}
|
||||
Reference in new issue
Block a user