embed web files for build
This commit is contained in:
@@ -41,9 +41,9 @@ type Config struct {
|
||||
DBPath string
|
||||
|
||||
// Auth settings
|
||||
RequireAdminActivation bool
|
||||
RequireAdminActivation bool
|
||||
RequireEmailConfirmation bool
|
||||
MFAEnabledByDefault bool
|
||||
MFAEnabledByDefault bool
|
||||
|
||||
// Email (SMTP) settings
|
||||
SMTPHost string
|
||||
@@ -54,11 +54,11 @@ type Config struct {
|
||||
SMTPUseTLS bool
|
||||
|
||||
// Security settings (failed-login thresholds and auto-ban config)
|
||||
PwdFailuresThreshold int
|
||||
MFAFailuresThreshold int
|
||||
FailuresWindowMinutes int
|
||||
AutoBanDurationHours int
|
||||
AutoBanPermanent bool
|
||||
PwdFailuresThreshold int
|
||||
MFAFailuresThreshold int
|
||||
FailuresWindowMinutes int
|
||||
AutoBanDurationHours int
|
||||
AutoBanPermanent bool
|
||||
}
|
||||
|
||||
var defaultConfig = map[string]map[string]string{
|
||||
@@ -91,9 +91,9 @@ var defaultConfig = map[string]map[string]string{
|
||||
"PATH": "data/gobsidian.db",
|
||||
},
|
||||
"AUTH": {
|
||||
"REQUIRE_ADMIN_ACTIVATION": "true",
|
||||
"REQUIRE_ADMIN_ACTIVATION": "true",
|
||||
"REQUIRE_EMAIL_CONFIRMATION": "true",
|
||||
"MFA_ENABLED_BY_DEFAULT": "false",
|
||||
"MFA_ENABLED_BY_DEFAULT": "false",
|
||||
},
|
||||
"EMAIL": {
|
||||
"SMTP_HOST": "",
|
||||
@@ -112,8 +112,20 @@ var defaultConfig = map[string]map[string]string{
|
||||
},
|
||||
}
|
||||
|
||||
// exeDir returns the directory containing the running executable.
|
||||
func exeDir() string {
|
||||
exe, err := os.Executable()
|
||||
if err != nil {
|
||||
wd, _ := os.Getwd()
|
||||
return wd
|
||||
}
|
||||
return filepath.Dir(exe)
|
||||
}
|
||||
|
||||
func Load() (*Config, error) {
|
||||
configPath := "settings.ini"
|
||||
baseDir := exeDir()
|
||||
// settings.ini lives next to the executable
|
||||
configPath := filepath.Join(baseDir, "settings.ini")
|
||||
|
||||
// Ensure config file exists
|
||||
if err := ensureConfigFile(configPath); err != nil {
|
||||
@@ -167,15 +179,23 @@ func Load() (*Config, error) {
|
||||
config.ImageStoragePath = notesSection.Key("IMAGE_STORAGE_PATH").String()
|
||||
config.ImageSubfolderName = notesSection.Key("IMAGE_SUBFOLDER_NAME").String()
|
||||
|
||||
// Convert relative paths to absolute
|
||||
// Convert relative paths to be next to the executable
|
||||
if !filepath.IsAbs(config.NotesDir) {
|
||||
wd, _ := os.Getwd()
|
||||
config.NotesDir = filepath.Join(wd, config.NotesDir)
|
||||
config.NotesDir = filepath.Join(baseDir, config.NotesDir)
|
||||
}
|
||||
|
||||
if !filepath.IsAbs(config.ImageStoragePath) && config.ImageStorageMode == 2 {
|
||||
wd, _ := os.Getwd()
|
||||
config.ImageStoragePath = filepath.Join(wd, config.ImageStoragePath)
|
||||
config.ImageStoragePath = filepath.Join(baseDir, config.ImageStoragePath)
|
||||
}
|
||||
|
||||
// Ensure these directories exist
|
||||
if err := os.MkdirAll(config.NotesDir, 0o755); err != nil {
|
||||
return nil, fmt.Errorf("failed to create notes directory: %w", err)
|
||||
}
|
||||
if config.ImageStorageMode == 2 {
|
||||
if err := os.MkdirAll(config.ImageStoragePath, 0o755); err != nil {
|
||||
return nil, fmt.Errorf("failed to create image storage directory: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Load DATABASE section
|
||||
@@ -184,8 +204,7 @@ func Load() (*Config, error) {
|
||||
config.DBPath = dbSection.Key("PATH").String()
|
||||
if config.DBType == "sqlite" {
|
||||
if !filepath.IsAbs(config.DBPath) {
|
||||
wd, _ := os.Getwd()
|
||||
config.DBPath = filepath.Join(wd, config.DBPath)
|
||||
config.DBPath = filepath.Join(baseDir, config.DBPath)
|
||||
}
|
||||
// ensure parent dir exists
|
||||
if err := os.MkdirAll(filepath.Dir(config.DBPath), 0o755); err != nil {
|
||||
@@ -222,6 +241,10 @@ func Load() (*Config, error) {
|
||||
func ensureConfigFile(configPath string) error {
|
||||
// Check if file exists
|
||||
if _, err := os.Stat(configPath); os.IsNotExist(err) {
|
||||
// ensure parent dir exists
|
||||
if err := os.MkdirAll(filepath.Dir(configPath), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
return createDefaultConfigFile(configPath)
|
||||
}
|
||||
|
||||
@@ -290,7 +313,7 @@ func parseCommaSeparated(value string) []string {
|
||||
}
|
||||
|
||||
func (c *Config) SaveSetting(section, key, value string) error {
|
||||
configPath := "settings.ini"
|
||||
configPath := filepath.Join(exeDir(), "settings.ini")
|
||||
cfg, err := ini.Load(configPath)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user