Add projects
This commit is contained in:
parent
2d3a9ad623
commit
8b607dd700
1802 changed files with 503346 additions and 2 deletions
46
backend/internal/config/plugin_path.go
Normal file
46
backend/internal/config/plugin_path.go
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const defaultPluginsDir = "plugins"
|
||||
|
||||
// ResolvePluginsDir normalizes the plugin directory for consistent use throughout the app.
|
||||
// It expands a leading tilde (~) to the user's home directory and defaults empty values to plugins.
|
||||
func ResolvePluginsDir(pluginsDir string) (string, error) {
|
||||
pluginsDir = strings.TrimSpace(pluginsDir)
|
||||
if pluginsDir == "" {
|
||||
pluginsDir = defaultPluginsDir
|
||||
}
|
||||
if strings.HasPrefix(pluginsDir, "~") {
|
||||
homeDir, errUserHomeDir := os.UserHomeDir()
|
||||
if errUserHomeDir != nil {
|
||||
return "", fmt.Errorf("resolve plugins directory: %w", errUserHomeDir)
|
||||
}
|
||||
remainder := strings.TrimPrefix(pluginsDir, "~")
|
||||
remainder = strings.TrimLeft(remainder, "/\\")
|
||||
if remainder == "" {
|
||||
return filepath.Clean(homeDir), nil
|
||||
}
|
||||
normalized := strings.ReplaceAll(remainder, "\\", "/")
|
||||
return filepath.Clean(filepath.Join(homeDir, filepath.FromSlash(normalized))), nil
|
||||
}
|
||||
return filepath.Clean(pluginsDir), nil
|
||||
}
|
||||
|
||||
// ResolvePluginsDir resolves and stores the effective plugin directory.
|
||||
func (cfg *Config) ResolvePluginsDir() error {
|
||||
if cfg == nil {
|
||||
return nil
|
||||
}
|
||||
pluginsDir, errResolvePluginsDir := ResolvePluginsDir(cfg.Plugins.Dir)
|
||||
if errResolvePluginsDir != nil {
|
||||
return errResolvePluginsDir
|
||||
}
|
||||
cfg.Plugins.Dir = pluginsDir
|
||||
return nil
|
||||
}
|
||||
Loading…
Reference in a new issue