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.
57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
systemext "pageswiki/internal/extensions"
|
|
)
|
|
|
|
func (s *Server) handleSystemExtensions(w http.ResponseWriter, r *http.Request) {
|
|
domainUUID := s.domainUUIDForRequest(r)
|
|
if kind, _ := periodicalRoute(r.URL.Path); kind != "" {
|
|
s.handlePeriodical(w, r)
|
|
return
|
|
}
|
|
if r.URL.Path != "/_/api/v1/extension/" {
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
if !s.canManageAssets(r) {
|
|
http.Error(w, "forbidden", 403)
|
|
return
|
|
}
|
|
if r.Method == http.MethodPost {
|
|
var body struct {
|
|
ID string `json:"id"`
|
|
Enabled *bool `json:"enabled"`
|
|
}
|
|
if err := json.NewDecoder(http.MaxBytesReader(w, r.Body, 32<<10)).Decode(&body); err != nil || body.ID == "" || body.Enabled == nil {
|
|
http.Error(w, "id and enabled are required", http.StatusBadRequest)
|
|
return
|
|
}
|
|
known := false
|
|
for _, item := range systemext.Catalog() {
|
|
if item.ID == body.ID {
|
|
known = true
|
|
break
|
|
}
|
|
}
|
|
if !known {
|
|
http.Error(w, "unknown extension", http.StatusNotFound)
|
|
return
|
|
}
|
|
if err := s.setSystemExtensionEnabled(domainUUID, body.ID, *body.Enabled); err != nil {
|
|
http.Error(w, err.Error(), 500)
|
|
return
|
|
}
|
|
writeEventJSON(w, 200, map[string]any{"id": body.ID, "enabled": *body.Enabled})
|
|
return
|
|
}
|
|
if r.Method != http.MethodGet {
|
|
w.Header().Set("Allow", "GET, POST")
|
|
http.Error(w, "method not allowed", 405)
|
|
return
|
|
}
|
|
writeEventJSON(w, 200, map[string]any{"api_version": 1, "extensions": s.systemExtensionCatalog(domainUUID), "external_installation": false})
|
|
}
|