feat(settings): add settings management API endpoints

- Add GET /settings/get and POST /settings/set endpoints for managing system settings
- Implement config file persistence for settings changes
- Update config schema to include notification and webhook settings
- Add API documentation for new endpoints
- Move config path variables to global package for consistency
This commit is contained in:
2026-04-23 12:43:11 +08:00
parent 489c37e095
commit ac51641e93
6 changed files with 303 additions and 16 deletions
+13 -10
View File
@@ -22,41 +22,44 @@ import (
func main() {
postLog.Info(fmt.Sprintf("%s %s (Build %d.%s) by %s", global.Software.Name, global.Software.Version, global.Software.BuildVer, global.Software.BuildType, global.Software.Developer))
configPath := flag.String("config", "./config.json", "path to config file")
dbPath_data := flag.String("db", "./database.db", "path to database file")
dbPath_log := flag.String("log", "./logs.db", "path to logs database file")
global.ConfigPath = flag.String("config", "./config.json", "path to config file")
global.DBPath_data = flag.String("db", "./database.db", "path to database file")
global.DBPath_log = flag.String("log", "./logs.db", "path to logs database file")
flag.Parse()
if _, err := os.Stat(*configPath); os.IsNotExist(err) {
if _, err := os.Stat(*global.ConfigPath); os.IsNotExist(err) {
// Load the default config
configData, err := json.MarshalIndent(global.CurrentConfig, "", " ")
if err != nil {
postLog.Warning(fmt.Sprintf("Failed to marshal default config: %v", err))
} else if err := os.WriteFile(*configPath, configData, 0644); err != nil {
} else if err := os.WriteFile(*global.ConfigPath, configData, 0644); err != nil {
postLog.Warning(fmt.Sprintf("Failed to create default config file: %v", err))
}
postLog.Info(fmt.Sprintf("Created default config file at %s", *configPath))
postLog.Info(fmt.Sprintf("Created default config file at %s", *global.ConfigPath))
}
err := config.LoadConfig(*configPath, service.GetInitSystem)
err := config.LoadConfig(*global.ConfigPath, service.GetInitSystem)
if err != nil {
postLog.Fatal(fmt.Sprintf("Failed to load config: %v", err))
}
if global.Software.BuildType == "debug" { // If debug build, set debug mode to true
global.CurrentConfig.Debug = true
}
postLog.SetDebugMode(global.CurrentConfig.Debug)
global.Is.Debug = global.CurrentConfig.Debug
if err := postLog.InitLogsDatabase(*dbPath_log); err != nil {
if err := postLog.InitLogsDatabase(*global.DBPath_log); err != nil {
postLog.Fatal(fmt.Sprintf("Failed to initialize logs database: %v", err))
}
postLog.Info("Logs database initialized successfully")
if err := database.InitDatabase(*dbPath_data, *dbPath_log); err != nil {
if err := database.InitDatabase(*global.DBPath_data, *global.DBPath_log); err != nil {
postLog.Fatal(fmt.Sprintf("Failed to initialize database: %v", err))
}
postLog.Info("Database initialized successfully")
if err := database.InitFrpcDatabase(*dbPath_data); err != nil {
if err := database.InitFrpcDatabase(*global.DBPath_data); err != nil {
postLog.Fatal(fmt.Sprintf("Failed to initialize frpc database: %v", err))
}