put is upsert for files

This commit is contained in:
Bel LaPointe
2022-02-08 15:26:33 -07:00
parent d0cea24d88
commit 1e01088b92
2 changed files with 32 additions and 6 deletions

View File

@@ -268,11 +268,7 @@ func (server *Server) apiV0FilesIDPutHandler(w http.ResponseWriter, r *http.Requ
if err != nil {
return err
}
branch, ok := branches[id]
if !ok {
http.NotFound(w, r)
return nil
}
branch, _ := branches[id]
branch.Updated = time.Now().UTC()
if title := r.Header.Get("Title"); title != "" {
branch.Title = title
@@ -284,7 +280,14 @@ func (server *Server) apiV0FilesIDPutHandler(w http.ResponseWriter, r *http.Requ
if err := server.putContentHandler(server.diskFilePath(id), w, r); err != nil {
return err
}
return tree.Put(id, branch)
if err := tree.Put(id, branch); err != nil {
return err
}
return json.NewEncoder(w).Encode(map[string]map[string]string{
"data": map[string]string{
"filePath": path.Join("/api/v0/files", id),
},
})
}
func (server *Server) apiV0FilesIDGetHandler(w http.ResponseWriter, r *http.Request) error {