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.
52 lines
1.5 KiB
Go
52 lines
1.5 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
)
|
|
|
|
type renamePathRequest struct {
|
|
OldPath string `json:"old_path"`
|
|
NewPath string `json:"new_path"`
|
|
Recursive bool `json:"recursive"`
|
|
}
|
|
|
|
type renamePreview struct {
|
|
Count int `json:"count"`
|
|
}
|
|
|
|
func (s *Server) handleRenamePath(w http.ResponseWriter, r *http.Request) {
|
|
if !requirePathMutationPost(w, r) {
|
|
return
|
|
}
|
|
var req renamePathRequest
|
|
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.OldPath = normalizeAuthorizationPath(req.OldPath)
|
|
req.NewPath = normalizeAuthorizationPath(req.NewPath)
|
|
if req.OldPath == "" || req.NewPath == "" || req.OldPath == "/" || req.NewPath == "/" {
|
|
http.Error(w, "invalid path", http.StatusBadRequest)
|
|
return
|
|
}
|
|
snapshot, err := s.authorizedMutationSnapshot(r, "rename", "create", req.OldPath, req.NewPath, req.Recursive)
|
|
if err != nil {
|
|
writePathMutationError(w, err)
|
|
return
|
|
}
|
|
if r.URL.Query().Get("preview") == "1" {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
_ = json.NewEncoder(w).Encode(renamePreview{Count: len(snapshot.Paths())})
|
|
return
|
|
}
|
|
count, err := s.store.RenamePathsInDomainChecked(s.domainUUIDForRequest(r), req.OldPath, req.NewPath, req.Recursive, snapshot)
|
|
if err != nil {
|
|
writePathMutationError(w, err)
|
|
return
|
|
}
|
|
w.Header().Set("Content-Type", "application/json")
|
|
_ = json.NewEncoder(w).Encode(renamePreview{Count: count})
|
|
}
|