diff --git a/main.go b/main.go index 03f47b1..2887258 100644 --- a/main.go +++ b/main.go @@ -218,6 +218,11 @@ func handleRead(w http.ResponseWriter, fsys *client.Fsys, p string) { writeJSON(w, http.StatusOK, parseIdx(content)) return } + if path.Base(p) == "chat" { + w.Header().Set("Content-Type", "text/plain; charset=utf-8") + w.Write(content) + return + } writeJSON(w, http.StatusOK, parseContent(content, path.Base(p))) } @@ -318,12 +323,24 @@ func handleWrite(w http.ResponseWriter, r *http.Request, fsys *client.Fsys, p st writeJSON(w, http.StatusBadRequest, map[string]string{"error": err.Error()}) return } + // If the body has a single key matching the file name, write just the value. + // Otherwise serialize as key=value lines (e.g. for "new"). + var payload []byte + base := path.Base(p) + if len(m) == 1 { + if v, ok := m[base]; ok { + payload = []byte(fmt.Sprintf("%v", v)) + } + } + if payload == nil { + payload = serializeKV(m) + } fid, err := fsys.Open(p, plan9.OWRITE) if err != nil { writeJSON(w, http.StatusNotFound, map[string]string{"error": err.Error()}) return } - n, err := fid.Write(serializeKV(m)) + n, err := fid.Write(payload) fid.Close() if err != nil { writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})