diff --git a/backend/handlers/handlers.go b/backend/handlers/handlers.go index 043025b..20d01ce 100644 --- a/backend/handlers/handlers.go +++ b/backend/handlers/handlers.go @@ -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) {