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
@@ -0,0 +1,79 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// Executable editor configuration is admin-owned Domain config, not a Page
|
||||
// or a workspace file. Only a newly authorized Vim session receives it.
|
||||
type vimSettings struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
FontSize int `json:"font_size"`
|
||||
Vimrc string `json:"vimrc"`
|
||||
Colorscheme string `json:"colorscheme"`
|
||||
ColorName string `json:"color_name"`
|
||||
}
|
||||
|
||||
func (s *Server) domainVimSettings(domain string) vimSettings {
|
||||
settings := vimSettings{FontSize: 16}
|
||||
_ = json.Unmarshal([]byte(s.getDomainConfig("vim_wasm_settings", domain)), &settings)
|
||||
if settings.FontSize < 10 || settings.FontSize > 32 {
|
||||
settings.FontSize = 16
|
||||
}
|
||||
return settings
|
||||
}
|
||||
|
||||
func (s *Server) handleVimSettings(w http.ResponseWriter, r *http.Request) {
|
||||
principal := s.requestPrincipal(r)
|
||||
if principal == nil || principal.State != "active" || !s.canManageAssets(r) {
|
||||
http.Error(w, "forbidden", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
if r.Method != http.MethodPost {
|
||||
w.Header().Set("Allow", "POST")
|
||||
http.Error(w, "method not allowed", 405)
|
||||
return
|
||||
}
|
||||
if origin := r.Header.Get("Origin"); origin != "" {
|
||||
u, err := url.Parse(origin)
|
||||
if err != nil || !strings.EqualFold(u.Host, r.Host) {
|
||||
http.Error(w, "invalid origin", 403)
|
||||
return
|
||||
}
|
||||
}
|
||||
r.Body = http.MaxBytesReader(w, r.Body, 2<<20)
|
||||
if err := r.ParseForm(); err != nil {
|
||||
http.Error(w, "invalid settings request", 400)
|
||||
return
|
||||
}
|
||||
settings := vimSettings{Enabled: r.FormValue("vim_enabled") == "on", Vimrc: r.FormValue("vimrc"), Colorscheme: r.FormValue("colorscheme"), ColorName: strings.TrimSpace(r.FormValue("color_name"))}
|
||||
settings.FontSize, _ = strconv.Atoi(r.FormValue("font_size"))
|
||||
if r.FormValue("reset") == "true" {
|
||||
settings = vimSettings{FontSize: 16}
|
||||
}
|
||||
if settings.FontSize < 10 || settings.FontSize > 32 || len(settings.ColorName) > 200 || strings.ContainsAny(settings.ColorName, "/\\\r\n\x00") {
|
||||
http.Error(w, translate(s.getLocale(s.domainUUIDForRequest(r)), "vim.invalid"), 400)
|
||||
return
|
||||
}
|
||||
for _, value := range []string{settings.Vimrc, settings.Colorscheme} {
|
||||
if len(value) > 65536 || !utf8.ValidString(value) || strings.ContainsRune(value, 0) {
|
||||
http.Error(w, translate(s.getLocale(s.domainUUIDForRequest(r)), "vim.invalid"), 400)
|
||||
return
|
||||
}
|
||||
}
|
||||
encoded, _ := json.Marshal(settings)
|
||||
if err := s.store.SetConfigInDomain(s.domainUUIDForRequest(r), "vim_wasm_settings", string(encoded)); err != nil {
|
||||
http.Error(w, "could not save settings", 500)
|
||||
return
|
||||
}
|
||||
if strings.Contains(r.Header.Get("Accept"), "application/json") {
|
||||
writeEventJSON(w, 200, map[string]bool{"ok": true})
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, "/-/sys/config?panel=adapter-vim.wasm", http.StatusSeeOther)
|
||||
}
|
||||
Reference in new issue
Block a user