From 2647c2c2ce0c5c48da1ae80925521510266392ac Mon Sep 17 00:00:00 2001 From: Sora39831 <540587985@qq.com> Date: Fri, 3 Apr 2026 09:27:10 +0800 Subject: [PATCH] refactor: update InitDB callers to use new parameterless signature --- main.go | 12 ++++++------ web/service/server.go | 2 +- web/service/user_test.go | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index f8d3357b..a195c7ee 100644 --- a/main.go +++ b/main.go @@ -46,7 +46,7 @@ func runWebServer() { godotenv.Load() - err := database.InitDB(config.GetDBPath()) + err := database.InitDB() if err != nil { log.Fatalf("Error initializing database: %v", err) } @@ -131,7 +131,7 @@ func runWebServer() { // resetSetting resets all panel settings to their default values. func resetSetting() { - err := database.InitDB(config.GetDBPath()) + err := database.InitDB() if err != nil { fmt.Println("Failed to initialize database:", err) return @@ -218,7 +218,7 @@ func updateTgbotEnableSts(status bool) { // updateTgbotSetting updates Telegram bot settings including token, chat ID, and runtime schedule. func updateTgbotSetting(tgBotToken string, tgBotChatid string, tgBotRuntime string) { - err := database.InitDB(config.GetDBPath()) + err := database.InitDB() if err != nil { fmt.Println("Error initializing database:", err) return @@ -256,7 +256,7 @@ func updateTgbotSetting(tgBotToken string, tgBotChatid string, tgBotRuntime stri // updateSetting updates various panel settings including port, credentials, base path, listen IP, and two-factor authentication. func updateSetting(port int, username string, password string, webBasePath string, listenIP string, resetTwoFactor bool) { - err := database.InitDB(config.GetDBPath()) + err := database.InitDB() if err != nil { fmt.Println("Database initialization failed:", err) return @@ -315,7 +315,7 @@ func updateSetting(port int, username string, password string, webBasePath strin // updateCert updates the SSL certificate files for the panel. func updateCert(publicKey string, privateKey string) { - err := database.InitDB(config.GetDBPath()) + err := database.InitDB() if err != nil { fmt.Println(err) return @@ -392,7 +392,7 @@ func GetListenIP(getListen bool) { func migrateDb() { inboundService := service.InboundService{} - err := database.InitDB(config.GetDBPath()) + err := database.InitDB() if err != nil { log.Fatal(err) } diff --git a/web/service/server.go b/web/service/server.go index 2e0b34b8..3fec9e90 100644 --- a/web/service/server.go +++ b/web/service/server.go @@ -1009,7 +1009,7 @@ func (s *ServerService) ImportDB(file multipart.File) error { } // Open & migrate new DB - if err = database.InitDB(config.GetDBPath()); err != nil { + if err = database.InitDBWithPath(config.GetDBPath()); err != nil { if errRename := os.Rename(fallbackPath, config.GetDBPath()); errRename != nil { return common.NewErrorf("Error migrating db and restoring fallback: %v", errRename) } diff --git a/web/service/user_test.go b/web/service/user_test.go index 26a83c83..6e3c0c59 100644 --- a/web/service/user_test.go +++ b/web/service/user_test.go @@ -16,7 +16,7 @@ func setupTestDB(t *testing.T) { t.Setenv("XUI_DEBUG", "") t.Setenv("XUI_DB_FOLDER", tmpDir) dbPath := filepath.Join(tmpDir, "test.db") - if err := database.InitDB(dbPath); err != nil { + if err := database.InitDBWithPath(dbPath); err != nil { t.Fatalf("InitDB failed: %v", err) } t.Cleanup(func() { @@ -120,7 +120,7 @@ func TestUpdateFirstUser_CreateWhenNone(t *testing.T) { }() dbPath := filepath.Join(tmpDir, "empty.db") - if err := database.InitDB(dbPath); err != nil { + if err := database.InitDBWithPath(dbPath); err != nil { t.Fatalf("InitDB failed: %v", err) } defer database.CloseDB()