add other files view/edit
This commit is contained in:
@@ -67,10 +67,28 @@ func (h *Handlers) CreateNoteHandler(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Ensure title ends with .md
|
||||
if !strings.HasSuffix(title, ".md") {
|
||||
title += ".md"
|
||||
}
|
||||
// Determine extension logic
|
||||
ext := strings.TrimPrefix(strings.ToLower(filepath.Ext(title)), ".")
|
||||
if ext == "" {
|
||||
// No extension provided: default to markdown
|
||||
title += ".md"
|
||||
ext = "md"
|
||||
} else {
|
||||
// Has extension: allow if md or in allowed file extensions
|
||||
allowed := ext == "md"
|
||||
if !allowed {
|
||||
for _, a := range h.config.AllowedFileExtensions {
|
||||
if strings.EqualFold(a, ext) {
|
||||
allowed = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if !allowed {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "File extension not allowed"})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Create full path
|
||||
var notePath string
|
||||
@@ -101,12 +119,18 @@ func (h *Handlers) CreateNoteHandler(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": true,
|
||||
"message": "Note created successfully",
|
||||
"note_path": notePath,
|
||||
"redirect": "/note/" + notePath,
|
||||
})
|
||||
// Redirect based on extension
|
||||
redirect := "/note/" + notePath
|
||||
if strings.ToLower(ext) != "md" {
|
||||
redirect = "/view_text/" + notePath
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": true,
|
||||
"message": "Note created successfully",
|
||||
"note_path": notePath,
|
||||
"redirect": redirect,
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handlers) EditNotePageHandler(c *gin.Context) {
|
||||
|
||||
Reference in New Issue
Block a user