view settings and images
This commit is contained in:
@@ -29,6 +29,12 @@ type Config struct {
|
|||||||
ImageSubfolderName string
|
ImageSubfolderName string
|
||||||
AllowedImageExtensions []string
|
AllowedImageExtensions []string
|
||||||
AllowedFileExtensions []string
|
AllowedFileExtensions []string
|
||||||
|
|
||||||
|
// Visibility settings
|
||||||
|
ShowImagesInTree bool
|
||||||
|
ShowFilesInTree bool
|
||||||
|
ShowImagesInFolder bool
|
||||||
|
ShowFilesInFolder bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultConfig = map[string]map[string]string{
|
var defaultConfig = map[string]map[string]string{
|
||||||
@@ -50,6 +56,11 @@ var defaultConfig = map[string]map[string]string{
|
|||||||
"IMAGE_SUBFOLDER_NAME": "attached",
|
"IMAGE_SUBFOLDER_NAME": "attached",
|
||||||
"ALLOWED_IMAGE_EXTENSIONS": "jpg, jpeg, png, webp, gif",
|
"ALLOWED_IMAGE_EXTENSIONS": "jpg, jpeg, png, webp, gif",
|
||||||
"ALLOWED_FILE_EXTENSIONS": "txt, pdf, html, json, yaml, yml, conf, csv, cmd, bat, sh",
|
"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.AllowedFileExtensions = parseCommaSeparated(notesSection.Key("ALLOWED_FILE_EXTENSIONS").String())
|
||||||
|
|
||||||
config.ImagesHide, _ = notesSection.Key("IMAGES_HIDE").Bool()
|
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.ImageStorageMode, _ = notesSection.Key("IMAGE_STORAGE_MODE").Int()
|
||||||
config.ImageStoragePath = notesSection.Key("IMAGE_STORAGE_PATH").String()
|
config.ImageStoragePath = notesSection.Key("IMAGE_STORAGE_PATH").String()
|
||||||
config.ImageSubfolderName = notesSection.Key("IMAGE_SUBFOLDER_NAME").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)
|
c.AllowedImageExtensions = parseCommaSeparated(value)
|
||||||
case "ALLOWED_FILE_EXTENSIONS":
|
case "ALLOWED_FILE_EXTENSIONS":
|
||||||
c.AllowedFileExtensions = parseCommaSeparated(value)
|
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_image_extensions": strings.Join(h.config.AllowedImageExtensions, ", "),
|
||||||
"allowed_file_extensions": strings.Join(h.config.AllowedFileExtensions, ", "),
|
"allowed_file_extensions": strings.Join(h.config.AllowedFileExtensions, ", "),
|
||||||
"images_hide": h.config.ImagesHide,
|
"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) {
|
func (h *Handlers) PostFileExtensionsSettingsHandler(c *gin.Context) {
|
||||||
imageExtensions := strings.TrimSpace(c.PostForm("allowed_image_extensions"))
|
imageExtensions := strings.TrimSpace(c.PostForm("allowed_image_extensions"))
|
||||||
fileExtensions := strings.TrimSpace(c.PostForm("allowed_file_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
|
// Save settings
|
||||||
if err := h.config.SaveSetting("MD_NOTES_APP", "ALLOWED_IMAGE_EXTENSIONS", imageExtensions); err != nil {
|
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
|
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{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"success": true,
|
"success": true,
|
||||||
"message": "File extension settings updated successfully",
|
"message": "File extension settings updated successfully",
|
||||||
"reload_required": true,
|
"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 {
|
} else {
|
||||||
child.Type = models.GetFileType(filepath.Ext(entry.Name()), cfg.AllowedImageExtensions, cfg.AllowedFileExtensions)
|
child.Type = models.GetFileType(filepath.Ext(entry.Name()), cfg.AllowedImageExtensions, cfg.AllowedFileExtensions)
|
||||||
// Only include markdown files and allowed file types in the tree
|
// Apply visibility for tree (left navigation)
|
||||||
if child.Type != models.FileTypeMarkdown && child.Type != models.FileTypeText {
|
switch child.Type {
|
||||||
|
case models.FileTypeMarkdown:
|
||||||
|
// always show
|
||||||
|
case models.FileTypeImage:
|
||||||
|
if !cfg.ShowImagesInTree {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
case models.FileTypeText:
|
||||||
|
if !cfg.ShowFilesInTree {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
default:
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -130,11 +141,18 @@ func GetFolderContents(folderPath string, cfg *config.Config) ([]models.FileInfo
|
|||||||
fileInfo.DisplayName = entry.Name()
|
fileInfo.DisplayName = entry.Name()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip images if they should be hidden
|
// Visibility for folder view
|
||||||
if cfg.ImagesHide && fileInfo.Type == models.FileTypeImage {
|
if fileInfo.Type == models.FileTypeImage {
|
||||||
continue
|
// 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
|
// Skip files that are not allowed
|
||||||
if fileInfo.Type == models.FileTypeOther {
|
if fileInfo.Type == models.FileTypeOther {
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -617,6 +617,11 @@
|
|||||||
<span class="mr-2">📝</span>
|
<span class="mr-2">📝</span>
|
||||||
<span>{{.node.Name}}</span>
|
<span>{{.node.Name}}</span>
|
||||||
</a>
|
</a>
|
||||||
|
{{else if eq .node.Type "image"}}
|
||||||
|
<a href="/serve_attached_image/{{.node.Path}}" target="_blank" class="sidebar-item" title="View image in new tab">
|
||||||
|
<span class="mr-2">🖼️</span>
|
||||||
|
<span>{{.node.Name}}</span>
|
||||||
|
</a>
|
||||||
{{else}}
|
{{else}}
|
||||||
<a href="/view_text/{{.node.Path}}" class="sidebar-item">
|
<a href="/view_text/{{.node.Path}}" class="sidebar-item">
|
||||||
<span class="mr-2">📄</span>
|
<span class="mr-2">📄</span>
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ console.log('Hello, World!');
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Actions -->
|
<!-- Actions -->
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -74,6 +74,11 @@
|
|||||||
<i class="fas fa-edit"></i>
|
<i class="fas fa-edit"></i>
|
||||||
</a>
|
</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
{{if eq .Type "image"}}
|
||||||
|
<a href="/serve_attached_image/{{.Path}}" target="_blank" class="text-yellow-400 hover:text-yellow-300 p-2" title="View">
|
||||||
|
<i class="fas fa-eye"></i>
|
||||||
|
</a>
|
||||||
|
{{end}}
|
||||||
{{if ne .Type "dir"}}
|
{{if ne .Type "dir"}}
|
||||||
<a href="/download/{{.Path}}" class="text-green-400 hover:text-green-300 p-2" title="Download">
|
<a href="/download/{{.Path}}" class="text-green-400 hover:text-green-300 p-2" title="Download">
|
||||||
<i class="fas fa-download"></i>
|
<i class="fas fa-download"></i>
|
||||||
|
|||||||
@@ -145,6 +145,32 @@
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Visibility: Left Navigation (Tree) -->
|
||||||
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mt-4">
|
||||||
|
<div>
|
||||||
|
<div class="text-sm font-medium text-gray-300 mb-2">Left navigation (tree) visibility</div>
|
||||||
|
<label class="flex items-center space-x-2">
|
||||||
|
<input type="checkbox" id="show_images_in_tree" name="show_images_in_tree" class="h-4 w-4 text-blue-600 rounded border-gray-600 bg-gray-700">
|
||||||
|
<span class="text-sm text-gray-300">Show images in left navigation</span>
|
||||||
|
</label>
|
||||||
|
<label class="flex items-center space-x-2 mt-2">
|
||||||
|
<input type="checkbox" id="show_files_in_tree" name="show_files_in_tree" class="h-4 w-4 text-blue-600 rounded border-gray-600 bg-gray-700">
|
||||||
|
<span class="text-sm text-gray-300">Show other allowed files in left navigation</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div class="text-sm font-medium text-gray-300 mb-2">Folder view visibility</div>
|
||||||
|
<label class="flex items-center space-x-2">
|
||||||
|
<input type="checkbox" id="show_images_in_folder" name="show_images_in_folder" class="h-4 w-4 text-blue-600 rounded border-gray-600 bg-gray-700">
|
||||||
|
<span class="text-sm text-gray-300">Show images in folder view</span>
|
||||||
|
</label>
|
||||||
|
<label class="flex items-center space-x-2 mt-2">
|
||||||
|
<input type="checkbox" id="show_files_in_folder" name="show_files_in_folder" class="h-4 w-4 text-blue-600 rounded border-gray-600 bg-gray-700">
|
||||||
|
<span class="text-sm text-gray-300">Show other allowed files in folder view</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="flex justify-end">
|
<div class="flex justify-end">
|
||||||
<button type="submit" class="btn-primary">
|
<button type="submit" class="btn-primary">
|
||||||
<i class="fas fa-save mr-2"></i>Save Extension Settings
|
<i class="fas fa-save mr-2"></i>Save Extension Settings
|
||||||
@@ -186,6 +212,11 @@
|
|||||||
document.getElementById('allowed_image_extensions').value = data.allowed_image_extensions || '';
|
document.getElementById('allowed_image_extensions').value = data.allowed_image_extensions || '';
|
||||||
document.getElementById('allowed_file_extensions').value = data.allowed_file_extensions || '';
|
document.getElementById('allowed_file_extensions').value = data.allowed_file_extensions || '';
|
||||||
document.getElementById('images_hide').checked = data.images_hide || false;
|
document.getElementById('images_hide').checked = data.images_hide || false;
|
||||||
|
// New visibility flags
|
||||||
|
document.getElementById('show_images_in_tree').checked = !!data.show_images_in_tree;
|
||||||
|
document.getElementById('show_files_in_tree').checked = !!data.show_files_in_tree;
|
||||||
|
document.getElementById('show_images_in_folder').checked = !!data.show_images_in_folder;
|
||||||
|
document.getElementById('show_files_in_folder').checked = !!data.show_files_in_folder;
|
||||||
})
|
})
|
||||||
.catch(error => console.error('Error loading file extensions settings:', error));
|
.catch(error => console.error('Error loading file extensions settings:', error));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user