view settings and images
This commit is contained in:
@@ -29,6 +29,12 @@ type Config struct {
|
||||
ImageSubfolderName string
|
||||
AllowedImageExtensions []string
|
||||
AllowedFileExtensions []string
|
||||
|
||||
// Visibility settings
|
||||
ShowImagesInTree bool
|
||||
ShowFilesInTree bool
|
||||
ShowImagesInFolder bool
|
||||
ShowFilesInFolder bool
|
||||
}
|
||||
|
||||
var defaultConfig = map[string]map[string]string{
|
||||
@@ -50,6 +56,11 @@ var defaultConfig = map[string]map[string]string{
|
||||
"IMAGE_SUBFOLDER_NAME": "attached",
|
||||
"ALLOWED_IMAGE_EXTENSIONS": "jpg, jpeg, png, webp, gif",
|
||||
"ALLOWED_FILE_EXTENSIONS": "txt, pdf, html, json, yaml, yml, conf, csv, cmd, bat, sh",
|
||||
// Visibility defaults
|
||||
"SHOW_IMAGES_IN_TREE": "false",
|
||||
"SHOW_FILES_IN_TREE": "true",
|
||||
"SHOW_IMAGES_IN_FOLDER": "true",
|
||||
"SHOW_FILES_IN_FOLDER": "true",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -90,6 +101,20 @@ func Load() (*Config, error) {
|
||||
config.AllowedFileExtensions = parseCommaSeparated(notesSection.Key("ALLOWED_FILE_EXTENSIONS").String())
|
||||
|
||||
config.ImagesHide, _ = notesSection.Key("IMAGES_HIDE").Bool()
|
||||
// New visibility flags (fallback to legacy IMAGES_HIDE for folder images if keys missing)
|
||||
config.ShowImagesInTree, _ = notesSection.Key("SHOW_IMAGES_IN_TREE").Bool()
|
||||
config.ShowFilesInTree, _ = notesSection.Key("SHOW_FILES_IN_TREE").Bool()
|
||||
if key := notesSection.Key("SHOW_IMAGES_IN_FOLDER"); key.String() != "" {
|
||||
config.ShowImagesInFolder, _ = key.Bool()
|
||||
} else {
|
||||
// fallback: if IMAGES_HIDE true => not shown
|
||||
config.ShowImagesInFolder = !config.ImagesHide
|
||||
}
|
||||
if key := notesSection.Key("SHOW_FILES_IN_FOLDER"); key.String() != "" {
|
||||
config.ShowFilesInFolder, _ = key.Bool()
|
||||
} else {
|
||||
config.ShowFilesInFolder = true
|
||||
}
|
||||
config.ImageStorageMode, _ = notesSection.Key("IMAGE_STORAGE_MODE").Int()
|
||||
config.ImageStoragePath = notesSection.Key("IMAGE_STORAGE_PATH").String()
|
||||
config.ImageSubfolderName = notesSection.Key("IMAGE_SUBFOLDER_NAME").String()
|
||||
@@ -231,6 +256,14 @@ func (c *Config) SaveSetting(section, key, value string) error {
|
||||
c.AllowedImageExtensions = parseCommaSeparated(value)
|
||||
case "ALLOWED_FILE_EXTENSIONS":
|
||||
c.AllowedFileExtensions = parseCommaSeparated(value)
|
||||
case "SHOW_IMAGES_IN_TREE":
|
||||
c.ShowImagesInTree = value == "true"
|
||||
case "SHOW_FILES_IN_TREE":
|
||||
c.ShowFilesInTree = value == "true"
|
||||
case "SHOW_IMAGES_IN_FOLDER":
|
||||
c.ShowImagesInFolder = value == "true"
|
||||
case "SHOW_FILES_IN_FOLDER":
|
||||
c.ShowFilesInFolder = value == "true"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -141,13 +141,21 @@ func (h *Handlers) GetFileExtensionsSettingsHandler(c *gin.Context) {
|
||||
"allowed_image_extensions": strings.Join(h.config.AllowedImageExtensions, ", "),
|
||||
"allowed_file_extensions": strings.Join(h.config.AllowedFileExtensions, ", "),
|
||||
"images_hide": h.config.ImagesHide,
|
||||
"show_images_in_tree": h.config.ShowImagesInTree,
|
||||
"show_files_in_tree": h.config.ShowFilesInTree,
|
||||
"show_images_in_folder": h.config.ShowImagesInFolder,
|
||||
"show_files_in_folder": h.config.ShowFilesInFolder,
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handlers) PostFileExtensionsSettingsHandler(c *gin.Context) {
|
||||
imageExtensions := strings.TrimSpace(c.PostForm("allowed_image_extensions"))
|
||||
fileExtensions := strings.TrimSpace(c.PostForm("allowed_file_extensions"))
|
||||
imagesHide := c.PostForm("images_hide") == "true"
|
||||
imagesHide := c.PostForm("images_hide") == "true" || c.PostForm("images_hide") == "on"
|
||||
showImagesInTree := c.PostForm("show_images_in_tree") == "true" || c.PostForm("show_images_in_tree") == "on"
|
||||
showFilesInTree := c.PostForm("show_files_in_tree") == "true" || c.PostForm("show_files_in_tree") == "on"
|
||||
showImagesInFolder := c.PostForm("show_images_in_folder") == "true" || c.PostForm("show_images_in_folder") == "on"
|
||||
showFilesInFolder := c.PostForm("show_files_in_folder") == "true" || c.PostForm("show_files_in_folder") == "on"
|
||||
|
||||
// Save settings
|
||||
if err := h.config.SaveSetting("MD_NOTES_APP", "ALLOWED_IMAGE_EXTENSIONS", imageExtensions); err != nil {
|
||||
@@ -169,9 +177,33 @@ func (h *Handlers) PostFileExtensionsSettingsHandler(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.config.SaveSetting("MD_NOTES_APP", "SHOW_IMAGES_IN_TREE", boolToStr(showImagesInTree)); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to save SHOW_IMAGES_IN_TREE"})
|
||||
return
|
||||
}
|
||||
if err := h.config.SaveSetting("MD_NOTES_APP", "SHOW_FILES_IN_TREE", boolToStr(showFilesInTree)); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to save SHOW_FILES_IN_TREE"})
|
||||
return
|
||||
}
|
||||
if err := h.config.SaveSetting("MD_NOTES_APP", "SHOW_IMAGES_IN_FOLDER", boolToStr(showImagesInFolder)); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to save SHOW_IMAGES_IN_FOLDER"})
|
||||
return
|
||||
}
|
||||
if err := h.config.SaveSetting("MD_NOTES_APP", "SHOW_FILES_IN_FOLDER", boolToStr(showFilesInFolder)); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to save SHOW_FILES_IN_FOLDER"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": true,
|
||||
"message": "File extension settings updated successfully",
|
||||
"reload_required": true,
|
||||
})
|
||||
}
|
||||
|
||||
func boolToStr(b bool) string {
|
||||
if b {
|
||||
return "true"
|
||||
}
|
||||
return "false"
|
||||
}
|
||||
|
||||
@@ -64,8 +64,19 @@ func buildTreeRecursive(currentPath string, node *models.TreeNode, hiddenDirs []
|
||||
}
|
||||
} else {
|
||||
child.Type = models.GetFileType(filepath.Ext(entry.Name()), cfg.AllowedImageExtensions, cfg.AllowedFileExtensions)
|
||||
// Only include markdown files and allowed file types in the tree
|
||||
if child.Type != models.FileTypeMarkdown && child.Type != models.FileTypeText {
|
||||
// Apply visibility for tree (left navigation)
|
||||
switch child.Type {
|
||||
case models.FileTypeMarkdown:
|
||||
// always show
|
||||
case models.FileTypeImage:
|
||||
if !cfg.ShowImagesInTree {
|
||||
continue
|
||||
}
|
||||
case models.FileTypeText:
|
||||
if !cfg.ShowFilesInTree {
|
||||
continue
|
||||
}
|
||||
default:
|
||||
continue
|
||||
}
|
||||
}
|
||||
@@ -130,11 +141,18 @@ func GetFolderContents(folderPath string, cfg *config.Config) ([]models.FileInfo
|
||||
fileInfo.DisplayName = entry.Name()
|
||||
}
|
||||
|
||||
// Skip images if they should be hidden
|
||||
if cfg.ImagesHide && fileInfo.Type == models.FileTypeImage {
|
||||
continue
|
||||
// Visibility for folder view
|
||||
if fileInfo.Type == models.FileTypeImage {
|
||||
// prefer new flag; fallback to legacy ImagesHide (handled by default in config load)
|
||||
if !cfg.ShowImagesInFolder {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if fileInfo.Type == models.FileTypeText {
|
||||
if !cfg.ShowFilesInFolder {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// Skip files that are not allowed
|
||||
if fileInfo.Type == models.FileTypeOther {
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user