fix(handlers): normalize filename to prevent double .md extension
Strip .md suffix from filename when creating files to prevent filename.md.md from being created. This aligns with the behavior in FileHandler which also normalizes filenames from URLs. Fixes issue where files created with .md extension could not be deleted due to filename mismatch.
This commit is contained in:
@@ -104,7 +104,10 @@ func (h *Handler) createFile(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.storage.Save(req.Name, req.Content); err != nil {
|
||||
// Normalize filename by stripping .md extension if present
|
||||
name := strings.TrimSuffix(req.Name, ".md")
|
||||
|
||||
if err := h.storage.Save(name, req.Content); err != nil {
|
||||
h.log.WithError(err).Error("Failed to create file")
|
||||
h.sendError(w, http.StatusInternalServerError, "failed to create file")
|
||||
return
|
||||
@@ -112,7 +115,7 @@ func (h *Handler) createFile(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
json.NewEncoder(w).Encode(FileResponse{Name: req.Name, Content: req.Content})
|
||||
json.NewEncoder(w).Encode(FileResponse{Name: name, Content: req.Content})
|
||||
}
|
||||
|
||||
func (h *Handler) getFile(w http.ResponseWriter, r *http.Request, name string) {
|
||||
|
||||
Reference in New Issue
Block a user