diff --git a/backend/internal/router/app/app_crypto_helper.go b/backend/internal/router/app/app_crypto_helper.go index 96a1e96..d0f12dc 100644 --- a/backend/internal/router/app/app_crypto_helper.go +++ b/backend/internal/router/app/app_crypto_helper.go @@ -1,7 +1,6 @@ package app import ( - "fmt" "verification-platform-backend/internal/database" "verification-platform-backend/internal/model" "verification-platform-backend/pkg/crypto" @@ -11,25 +10,26 @@ import ( func AppCryptoMiddleware() gin.HandlerFunc { return func(c *gin.Context) { - fmt.Printf("[AppCrypto] Middleware called\n") appKey := c.Param("appKey") - fmt.Printf("[AppCrypto] AppKey from param: %s\n", appKey) if appKey == "" { - fmt.Printf("[AppCrypto] AppKey is empty, skipping\n") c.Next() return } + if database.DB == nil { + c.JSON(500, gin.H{"code": 500, "message": "数据库未初始化"}) + c.Abort() + return + } + var app model.Application if err := database.DB.Where("app_key = ?", appKey).First(&app).Error; err != nil { - fmt.Printf("[AppCrypto] Database error: %v\n", err) - c.Next() + c.JSON(404, gin.H{"code": 404, "message": "应用不存在"}) + c.Abort() return } - fmt.Printf("[AppCrypto] App found: %+v\n", app) - var encryptType crypto.EncryptType switch app.EncryptType { case "aes": @@ -42,11 +42,9 @@ func AppCryptoMiddleware() gin.HandlerFunc { shouldEncrypt := encryptType != crypto.EncryptTypeNone - fmt.Printf("[AppCrypto] AppKey: %s, EncryptType: %s, EncryptKey: %s, ShouldEncrypt: %v\n", - appKey, app.EncryptType, app.EncryptKey, shouldEncrypt) - c.Set("should_encrypt_response", shouldEncrypt) c.Set("crypto_manager", crypto.NewCryptoManager(encryptType, app.EncryptKey)) + c.Set("app", &app) c.Next() } diff --git a/backend/internal/router/install/install.go b/backend/internal/router/install/install.go index 97976f6..28899fb 100644 --- a/backend/internal/router/install/install.go +++ b/backend/internal/router/install/install.go @@ -16,6 +16,7 @@ import ( "github.com/gin-gonic/gin" "github.com/glebarez/sqlite" + "github.com/spf13/viper" "golang.org/x/crypto/bcrypt" "gorm.io/driver/mysql" "gorm.io/gorm" @@ -232,6 +233,16 @@ func handleSetup(c *gin.Context) { log.Printf("Warning: failed to save config file: %v", err) } + viper.Set("app.jwt_secret", jwtSecret) + viper.Set("database.type", req.DbType) + if req.DbType == "mysql" { + viper.Set("database.host", req.DbHost) + viper.Set("database.port", req.DbPort) + viper.Set("database.name", req.DbName) + viper.Set("database.username", req.DbUsername) + viper.Set("database.password", req.DbPassword) + } + database.DB = newDB response.Success(c, gin.H{ diff --git a/frontend/src/pages/admin/index.vue b/frontend/src/pages/admin/index.vue index 83208dd..9c855c5 100644 --- a/frontend/src/pages/admin/index.vue +++ b/frontend/src/pages/admin/index.vue @@ -703,10 +703,16 @@ function initActivityChart() { onMounted(async () => { fetchCurrentUser() await fetchDashboard() - await nextTick() +}) - initMapChart() - initActivityChart() +watch(loading, async (newVal) => { + if (!newVal) { + await nextTick() + setTimeout(() => { + initMapChart() + initActivityChart() + }, 100) + } }) watch(isDark, () => {