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:
Anya Tokugawa committed 2026-09-27 14:44:43 +09:00
1 parent 288e6e94ac
commit c1175d389f
699 files changed
+110197 -4117

No files matched your search

+106 -77
View File
@@ -2,95 +2,124 @@ package server
import (
"encoding/json"
"errors"
"net/http"
"pageswiki/internal/store"
)
func (s *Server) handleRenamePathAPI(
w http.ResponseWriter,
r *http.Request,
) {
var req struct {
OldPath string `json:"old_path"`
NewPath string `json:"new_path"`
}
err := json.NewDecoder(
r.Body,
).Decode(&req)
if err != nil {
http.Error(
w,
err.Error(),
400,
)
return
}
err = s.store.RenamePath(
req.OldPath,
req.NewPath,
)
if err != nil {
http.Error(
w,
err.Error(),
500,
)
return
}
w.WriteHeader(
http.StatusNoContent,
)
// Kept for older in-process callers; the registered route uses handleRenamePath.
func (s *Server) handleRenamePathAPI(w http.ResponseWriter, r *http.Request) {
s.handleRenamePath(w, r)
}
func (s *Server) handleRemovePathAPI(
w http.ResponseWriter,
r *http.Request,
) {
var req struct {
Path string `json:"path"`
func requirePathMutationPost(w http.ResponseWriter, r *http.Request) bool {
if r.Method == http.MethodPost {
return true
}
w.Header().Set("Allow", http.MethodPost)
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
return false
}
err := json.NewDecoder(
r.Body,
).Decode(&req)
func writePathMutationError(w http.ResponseWriter, err error) {
status := http.StatusInternalServerError
switch {
case errors.Is(err, store.ErrAccessDenied):
status = http.StatusForbidden
case errors.Is(err, store.ErrPathConflict), errors.Is(err, store.ErrPathSnapshotChanged):
status = http.StatusConflict
case errors.Is(err, store.ErrPathNotFound):
status = http.StatusNotFound
case errors.Is(err, store.ErrPathMutationTooLarge):
status = http.StatusRequestEntityTooLarge
}
http.Error(w, err.Error(), status)
}
func (s *Server) handleRemovePathAPI(w http.ResponseWriter, r *http.Request) {
if !requirePathMutationPost(w, r) {
return
}
var req struct {
Path string `json:"path"`
Paths []string `json:"paths"`
Recursive bool `json:"recursive"`
}
r.Body = http.MaxBytesReader(w, r.Body, 1<<20)
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
if req.Path != "" {
req.Paths = append(req.Paths, req.Path)
}
if len(req.Paths) == 0 || len(req.Paths) > 1000 {
http.Error(w, "between 1 and 1000 paths are required", http.StatusBadRequest)
return
}
unique := map[string]bool{}
var snapshots []*store.PathMutationSnapshot
bindingCount := 0
for _, path := range req.Paths {
path = normalizeAuthorizationPath(path)
if path == "" || path == "/" {
http.Error(w, "invalid path", http.StatusBadRequest)
return
}
if unique[path] {
continue
}
unique[path] = true
snapshot, err := s.authorizedMutationSnapshot(r, "delete", "", path, "", req.Recursive)
if err != nil {
writePathMutationError(w, err)
return
}
bindingCount += len(snapshot.Paths())
if bindingCount > store.MaxPathMutationPaths {
writePathMutationError(w, store.ErrPathMutationTooLarge)
return
}
snapshots = append(snapshots, snapshot)
}
if _, err := s.store.RemovePathsInDomainChecked(s.domainUUIDForRequest(r), snapshots); err != nil {
writePathMutationError(w, err)
return
}
w.WriteHeader(http.StatusNoContent)
}
func (s *Server) handleCopyPathAPI(w http.ResponseWriter, r *http.Request) {
if !requirePathMutationPost(w, r) {
return
}
var req struct {
SourcePath string `json:"source_path"`
DestinationPath string `json:"destination_path"`
Recursive bool `json:"recursive"`
}
r.Body = http.MaxBytesReader(w, r.Body, 1<<20)
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
req.SourcePath = normalizeAuthorizationPath(req.SourcePath)
req.DestinationPath = normalizeAuthorizationPath(req.DestinationPath)
if req.SourcePath == "" || req.DestinationPath == "" || req.SourcePath == "/" || req.DestinationPath == "/" {
http.Error(w, "invalid path", http.StatusBadRequest)
return
}
snapshot, err := s.authorizedMutationSnapshot(r, "read", "create", req.SourcePath, req.DestinationPath, req.Recursive)
if err != nil {
http.Error(
w,
err.Error(),
400,
)
writePathMutationError(w, err)
return
}
err = s.store.RemovePath(
req.Path,
)
count, err := s.store.CopyPathsInDomainChecked(s.domainUUIDForRequest(r), req.SourcePath, req.DestinationPath, req.Recursive, snapshot)
if err != nil {
http.Error(
w,
err.Error(),
500,
)
writePathMutationError(w, err)
return
}
w.WriteHeader(
http.StatusNoContent,
)
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(map[string]int{"copied": count})
}