Enha: extentions for filepicker
This commit is contained in:
@@ -28,6 +28,7 @@ STT_LANG = "en" # Language for speech recognition (for WHISPER_BINARY mode)
|
|||||||
STT_SR = 16000 # Sample rate for audio recording
|
STT_SR = 16000 # Sample rate for audio recording
|
||||||
DBPATH = "gflt.db"
|
DBPATH = "gflt.db"
|
||||||
FilePickerDir = "." # Directory where file picker should start
|
FilePickerDir = "." # Directory where file picker should start
|
||||||
|
FilePickerExts = "png,jpg,jpeg,gif,webp" # Comma-separated list of allowed file extensions for file picker
|
||||||
#
|
#
|
||||||
FetchModelNameAPI = "http://localhost:8080/v1/models"
|
FetchModelNameAPI = "http://localhost:8080/v1/models"
|
||||||
# external search tool
|
# external search tool
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ type Config struct {
|
|||||||
STT_LANG string `toml:"STT_LANG"`
|
STT_LANG string `toml:"STT_LANG"`
|
||||||
DBPATH string `toml:"DBPATH"`
|
DBPATH string `toml:"DBPATH"`
|
||||||
FilePickerDir string `toml:"FilePickerDir"`
|
FilePickerDir string `toml:"FilePickerDir"`
|
||||||
|
FilePickerExts string `toml:"FilePickerExts"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadConfigOrDefault(fn string) *Config {
|
func LoadConfigOrDefault(fn string) *Config {
|
||||||
@@ -101,6 +102,7 @@ func LoadConfigOrDefault(fn string) *Config {
|
|||||||
config.FetchModelNameAPI = "http://localhost:8080/v1/models"
|
config.FetchModelNameAPI = "http://localhost:8080/v1/models"
|
||||||
config.STT_SR = 16000
|
config.STT_SR = 16000
|
||||||
config.FilePickerDir = "." // Default to current directory
|
config.FilePickerDir = "." // Default to current directory
|
||||||
|
config.FilePickerExts = "png,jpg,jpeg,gif,webp" // Default allowed extensions
|
||||||
}
|
}
|
||||||
config.CurrentAPI = config.ChatAPI
|
config.CurrentAPI = config.ChatAPI
|
||||||
config.APIMap = map[string]string{
|
config.APIMap = map[string]string{
|
||||||
|
|||||||
54
tables.go
54
tables.go
@@ -563,6 +563,27 @@ func makeFilePicker() *tview.Flex {
|
|||||||
// Track currently displayed directory (changes as user navigates)
|
// Track currently displayed directory (changes as user navigates)
|
||||||
currentDisplayDir := startDir
|
currentDisplayDir := startDir
|
||||||
|
|
||||||
|
// Helper function to check if a file has an allowed extension from config
|
||||||
|
hasAllowedExtension := func(filename string) bool {
|
||||||
|
// If no allowed extensions are specified in config, allow all files
|
||||||
|
if cfg.FilePickerExts == "" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Split the allowed extensions from the config string
|
||||||
|
allowedExts := strings.Split(cfg.FilePickerExts, ",")
|
||||||
|
|
||||||
|
lowerFilename := strings.ToLower(strings.TrimSpace(filename))
|
||||||
|
|
||||||
|
for _, ext := range allowedExts {
|
||||||
|
ext = strings.TrimSpace(ext) // Remove any whitespace around the extension
|
||||||
|
if ext != "" && strings.HasSuffix(lowerFilename, "."+ext) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// Helper function to check if a file is an image
|
// Helper function to check if a file is an image
|
||||||
isImageFile := func(filename string) bool {
|
isImageFile := func(filename string) bool {
|
||||||
imageExtensions := []string{".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp", ".tiff", ".svg"}
|
imageExtensions := []string{".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp", ".tiff", ".svg"}
|
||||||
@@ -690,22 +711,25 @@ func makeFilePicker() *tview.Flex {
|
|||||||
statusView.SetText("Current: " + newDir)
|
statusView.SetText("Current: " + newDir)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
// Capture the file name for the closure to avoid loop variable issues
|
// Only show files that have allowed extensions (from config)
|
||||||
fileName := name
|
if hasAllowedExtension(name) {
|
||||||
fullFilePath := path.Join(dir, fileName)
|
// Capture the file name for the closure to avoid loop variable issues
|
||||||
listView.AddItem(fileName, "(File)", 0, func() {
|
fileName := name
|
||||||
selectedFile = fullFilePath
|
fullFilePath := path.Join(dir, fileName)
|
||||||
statusView.SetText("Selected: " + selectedFile)
|
listView.AddItem(fileName, "(File)", 0, func() {
|
||||||
|
selectedFile = fullFilePath
|
||||||
// Check if the file is an image
|
|
||||||
if isImageFile(fileName) {
|
|
||||||
// For image files, offer to attach to the next LLM message
|
|
||||||
statusView.SetText("Selected image: " + selectedFile + " (Press Load to attach)")
|
|
||||||
} else {
|
|
||||||
// For non-image files, display as before
|
|
||||||
statusView.SetText("Selected: " + selectedFile)
|
statusView.SetText("Selected: " + selectedFile)
|
||||||
}
|
|
||||||
})
|
// Check if the file is an image
|
||||||
|
if isImageFile(fileName) {
|
||||||
|
// For image files, offer to attach to the next LLM message
|
||||||
|
statusView.SetText("Selected image: " + selectedFile + " (Press Load to attach)")
|
||||||
|
} else {
|
||||||
|
// For non-image files, display as before
|
||||||
|
statusView.SetText("Selected: " + selectedFile)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user