2023-04-22 20:39:27 +08:00
|
|
|
package router
|
|
|
|
|
|
|
|
|
|
import (
|
2025-10-11 15:30:09 +08:00
|
|
|
"github.com/QuantumNous/new-api/controller"
|
|
|
|
|
"github.com/QuantumNous/new-api/middleware"
|
2023-07-15 12:41:21 +08:00
|
|
|
|
|
|
|
|
"github.com/gin-contrib/gzip"
|
|
|
|
|
"github.com/gin-gonic/gin"
|
2023-04-22 20:39:27 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func SetApiRouter(router *gin.Engine) {
|
|
|
|
|
apiRouter := router.Group("/api")
|
2023-04-25 21:56:07 +08:00
|
|
|
apiRouter.Use(gzip.Gzip(gzip.DefaultCompression))
|
2023-04-22 20:39:27 +08:00
|
|
|
apiRouter.Use(middleware.GlobalAPIRateLimit())
|
|
|
|
|
{
|
2025-04-03 18:57:15 +08:00
|
|
|
apiRouter.GET("/setup", controller.GetSetup)
|
|
|
|
|
apiRouter.POST("/setup", controller.PostSetup)
|
2023-04-22 20:39:27 +08:00
|
|
|
apiRouter.GET("/status", controller.GetStatus)
|
2025-06-11 02:28:36 +08:00
|
|
|
apiRouter.GET("/uptime/status", controller.GetUptimeKumaStatus)
|
2024-05-12 19:07:33 +08:00
|
|
|
apiRouter.GET("/models", middleware.UserAuth(), controller.DashboardListModels)
|
2024-03-04 19:32:59 +08:00
|
|
|
apiRouter.GET("/status/test", middleware.AdminAuth(), controller.TestStatus)
|
2023-04-22 20:39:27 +08:00
|
|
|
apiRouter.GET("/notice", controller.GetNotice)
|
2025-10-08 10:43:47 +08:00
|
|
|
apiRouter.GET("/user-agreement", controller.GetUserAgreement)
|
|
|
|
|
apiRouter.GET("/privacy-policy", controller.GetPrivacyPolicy)
|
2023-04-22 20:39:27 +08:00
|
|
|
apiRouter.GET("/about", controller.GetAbout)
|
2024-03-23 19:09:09 +08:00
|
|
|
//apiRouter.GET("/midjourney", controller.GetMidjourney)
|
2023-05-13 21:27:49 +08:00
|
|
|
apiRouter.GET("/home_page_content", controller.GetHomePageContent)
|
2024-05-15 23:56:26 +08:00
|
|
|
apiRouter.GET("/pricing", middleware.TryUserAuth(), controller.GetPricing)
|
2025-08-10 21:22:53 +08:00
|
|
|
apiRouter.GET("/verification", middleware.EmailVerificationRateLimit(), middleware.TurnstileCheck(), controller.SendEmailVerification)
|
2023-04-22 20:39:27 +08:00
|
|
|
apiRouter.GET("/reset_password", middleware.CriticalRateLimit(), middleware.TurnstileCheck(), controller.SendPasswordResetEmail)
|
|
|
|
|
apiRouter.POST("/user/reset", middleware.CriticalRateLimit(), controller.ResetPassword)
|
|
|
|
|
apiRouter.GET("/oauth/github", middleware.CriticalRateLimit(), controller.GitHubOAuth)
|
2025-11-22 18:38:24 +08:00
|
|
|
apiRouter.GET("/oauth/discord", middleware.CriticalRateLimit(), controller.DiscordOAuth)
|
2025-02-28 15:18:03 +08:00
|
|
|
apiRouter.GET("/oauth/oidc", middleware.CriticalRateLimit(), controller.OidcAuth)
|
2024-11-10 23:56:22 +08:00
|
|
|
apiRouter.GET("/oauth/linuxdo", middleware.CriticalRateLimit(), controller.LinuxdoOAuth)
|
2023-09-15 00:24:20 +08:00
|
|
|
apiRouter.GET("/oauth/state", middleware.CriticalRateLimit(), controller.GenerateOAuthCode)
|
2023-04-22 20:39:27 +08:00
|
|
|
apiRouter.GET("/oauth/wechat", middleware.CriticalRateLimit(), controller.WeChatAuth)
|
2024-12-27 18:32:11 +08:00
|
|
|
apiRouter.GET("/oauth/wechat/bind", middleware.CriticalRateLimit(), controller.WeChatBind)
|
|
|
|
|
apiRouter.GET("/oauth/email/bind", middleware.CriticalRateLimit(), controller.EmailBind)
|
2024-03-02 17:15:52 +08:00
|
|
|
apiRouter.GET("/oauth/telegram/login", middleware.CriticalRateLimit(), controller.TelegramLogin)
|
2024-12-27 18:32:11 +08:00
|
|
|
apiRouter.GET("/oauth/telegram/bind", middleware.CriticalRateLimit(), controller.TelegramBind)
|
2025-06-19 08:57:34 +08:00
|
|
|
apiRouter.GET("/ratio_config", middleware.CriticalRateLimit(), controller.GetRatioConfig)
|
2023-04-22 20:39:27 +08:00
|
|
|
|
2025-07-10 16:29:38 +08:00
|
|
|
apiRouter.POST("/stripe/webhook", controller.StripeWebhook)
|
2025-09-08 23:07:05 +08:00
|
|
|
apiRouter.POST("/creem/webhook", controller.CreemWebhook)
|
2025-07-10 16:29:38 +08:00
|
|
|
|
2025-09-30 12:12:50 +08:00
|
|
|
// Universal secure verification routes
|
|
|
|
|
apiRouter.POST("/verify", middleware.UserAuth(), middleware.CriticalRateLimit(), controller.UniversalVerify)
|
|
|
|
|
apiRouter.GET("/verify/status", middleware.UserAuth(), controller.GetVerificationStatus)
|
|
|
|
|
|
2023-04-22 20:39:27 +08:00
|
|
|
userRoute := apiRouter.Group("/user")
|
|
|
|
|
{
|
|
|
|
|
userRoute.POST("/register", middleware.CriticalRateLimit(), middleware.TurnstileCheck(), controller.Register)
|
2023-11-06 22:11:05 +08:00
|
|
|
userRoute.POST("/login", middleware.CriticalRateLimit(), middleware.TurnstileCheck(), controller.Login)
|
2025-08-02 14:53:28 +08:00
|
|
|
userRoute.POST("/login/2fa", middleware.CriticalRateLimit(), controller.Verify2FALogin)
|
2025-09-29 17:45:09 +08:00
|
|
|
userRoute.POST("/passkey/login/begin", middleware.CriticalRateLimit(), controller.PasskeyLoginBegin)
|
|
|
|
|
userRoute.POST("/passkey/login/finish", middleware.CriticalRateLimit(), controller.PasskeyLoginFinish)
|
2023-08-14 22:16:32 +08:00
|
|
|
//userRoute.POST("/tokenlog", middleware.CriticalRateLimit(), controller.TokenLog)
|
2023-04-22 20:39:27 +08:00
|
|
|
userRoute.GET("/logout", controller.Logout)
|
2023-08-14 22:16:32 +08:00
|
|
|
userRoute.GET("/epay/notify", controller.EpayNotify)
|
2024-09-18 05:19:10 +08:00
|
|
|
userRoute.GET("/groups", controller.GetUserGroups)
|
2023-04-22 20:39:27 +08:00
|
|
|
|
|
|
|
|
selfRoute := userRoute.Group("/")
|
2023-04-23 18:24:11 +08:00
|
|
|
selfRoute.Use(middleware.UserAuth())
|
2023-04-22 20:39:27 +08:00
|
|
|
{
|
2024-10-14 16:15:10 +08:00
|
|
|
selfRoute.GET("/self/groups", controller.GetUserGroups)
|
2023-04-22 20:39:27 +08:00
|
|
|
selfRoute.GET("/self", controller.GetSelf)
|
2023-11-21 16:35:51 +08:00
|
|
|
selfRoute.GET("/models", controller.GetUserModels)
|
2023-04-22 20:39:27 +08:00
|
|
|
selfRoute.PUT("/self", controller.UpdateSelf)
|
2023-08-06 22:28:07 +08:00
|
|
|
selfRoute.DELETE("/self", controller.DeleteSelf)
|
2023-04-26 20:54:39 +08:00
|
|
|
selfRoute.GET("/token", controller.GenerateAccessToken)
|
2025-09-29 17:45:09 +08:00
|
|
|
selfRoute.GET("/passkey", controller.PasskeyStatus)
|
|
|
|
|
selfRoute.POST("/passkey/register/begin", controller.PasskeyRegisterBegin)
|
|
|
|
|
selfRoute.POST("/passkey/register/finish", controller.PasskeyRegisterFinish)
|
|
|
|
|
selfRoute.POST("/passkey/verify/begin", controller.PasskeyVerifyBegin)
|
|
|
|
|
selfRoute.POST("/passkey/verify/finish", controller.PasskeyVerifyFinish)
|
|
|
|
|
selfRoute.DELETE("/passkey", controller.PasskeyDelete)
|
2023-06-17 18:12:58 +08:00
|
|
|
selfRoute.GET("/aff", controller.GetAffCode)
|
2025-09-12 19:11:17 +08:00
|
|
|
selfRoute.GET("/topup/info", controller.GetTopUpInfo)
|
✨ feat: Add topup billing history with admin manual completion
Implement comprehensive topup billing system with user history viewing and admin management capabilities.
## Features Added
### Frontend
- Add topup history modal with paginated billing records
- Display order details: trade number, payment method, amount, money, status, create time
- Implement empty state with proper illustrations
- Add payment method column with localized display (Stripe, Alipay, WeChat)
- Add admin manual completion feature for pending orders
- Add Coins icon for recharge amount display
- Integrate "Bills" button in RechargeCard header
- Optimize code quality by using shared utility functions (isAdmin)
- Extract constants for status and payment method mappings
- Use React.useMemo for performance optimization
### Backend
- Create GET `/api/user/topup/self` endpoint for user topup history with pagination
- Create POST `/api/user/topup/complete` endpoint for admin manual order completion
- Add `payment_method` field to TopUp model for tracking payment types
- Implement `GetUserTopUps` method with proper pagination and ordering
- Implement `ManualCompleteTopUp` with transaction safety and row-level locking
- Add application-level mutex locks to prevent concurrent order processing
- Record payment method in Epay and Stripe payment flows
- Ensure idempotency and data consistency with proper error handling
### Internationalization
- Add i18n keys for Chinese (zh), English (en), and French (fr)
- Support for billing-related UI text and status messages
## Technical Improvements
- Use database transactions with FOR UPDATE row-level locking
- Implement sync.Map-based mutex for order-level concurrency control
- Proper error handling and user-friendly toast notifications
- Follow existing codebase patterns for empty states and modals
- Maintain code quality with extracted render functions and constants
## Files Changed
- Backend: controller/topup.go, controller/topup_stripe.go, model/topup.go, router/api-router.go
- Frontend: web/src/components/topup/modals/TopupHistoryModal.jsx (new), web/src/components/topup/RechargeCard.jsx, web/src/components/topup/index.jsx
- i18n: web/src/i18n/locales/{zh,en,fr}.json
2025-10-07 00:22:45 +08:00
|
|
|
selfRoute.GET("/topup/self", controller.GetUserTopUps)
|
2025-07-10 16:29:38 +08:00
|
|
|
selfRoute.POST("/topup", middleware.CriticalRateLimit(), controller.TopUp)
|
|
|
|
|
selfRoute.POST("/pay", middleware.CriticalRateLimit(), controller.RequestEpay)
|
2023-08-14 22:16:32 +08:00
|
|
|
selfRoute.POST("/amount", controller.RequestAmount)
|
2025-07-10 16:29:38 +08:00
|
|
|
selfRoute.POST("/stripe/pay", middleware.CriticalRateLimit(), controller.RequestStripePay)
|
|
|
|
|
selfRoute.POST("/stripe/amount", controller.RequestStripeAmount)
|
2025-09-08 23:07:05 +08:00
|
|
|
selfRoute.POST("/creem/pay", middleware.CriticalRateLimit(), controller.RequestCreemPay)
|
2023-11-21 16:35:51 +08:00
|
|
|
selfRoute.POST("/aff_transfer", controller.TransferAffQuota)
|
2025-02-18 14:54:21 +08:00
|
|
|
selfRoute.PUT("/setting", controller.UpdateUserSetting)
|
2025-08-10 21:22:53 +08:00
|
|
|
|
2025-08-02 14:53:28 +08:00
|
|
|
// 2FA routes
|
|
|
|
|
selfRoute.GET("/2fa/status", controller.Get2FAStatus)
|
|
|
|
|
selfRoute.POST("/2fa/setup", controller.Setup2FA)
|
|
|
|
|
selfRoute.POST("/2fa/enable", controller.Enable2FA)
|
|
|
|
|
selfRoute.POST("/2fa/disable", controller.Disable2FA)
|
|
|
|
|
selfRoute.POST("/2fa/backup_codes", controller.RegenerateBackupCodes)
|
2026-01-02 23:00:33 +08:00
|
|
|
|
|
|
|
|
// Check-in routes
|
|
|
|
|
selfRoute.GET("/checkin", controller.GetCheckinStatus)
|
|
|
|
|
selfRoute.POST("/checkin", controller.DoCheckin)
|
2023-04-22 20:39:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
adminRoute := userRoute.Group("/")
|
2023-04-23 18:24:11 +08:00
|
|
|
adminRoute.Use(middleware.AdminAuth())
|
2023-04-22 20:39:27 +08:00
|
|
|
{
|
|
|
|
|
adminRoute.GET("/", controller.GetAllUsers)
|
2025-10-07 00:46:47 +08:00
|
|
|
adminRoute.GET("/topup", controller.GetAllTopUps)
|
|
|
|
|
adminRoute.POST("/topup/complete", controller.AdminCompleteTopUp)
|
2023-04-22 20:39:27 +08:00
|
|
|
adminRoute.GET("/search", controller.SearchUsers)
|
|
|
|
|
adminRoute.GET("/:id", controller.GetUser)
|
|
|
|
|
adminRoute.POST("/", controller.CreateUser)
|
|
|
|
|
adminRoute.POST("/manage", controller.ManageUser)
|
|
|
|
|
adminRoute.PUT("/", controller.UpdateUser)
|
|
|
|
|
adminRoute.DELETE("/:id", controller.DeleteUser)
|
2025-09-30 13:18:18 +08:00
|
|
|
adminRoute.DELETE("/:id/reset_passkey", controller.AdminResetPasskey)
|
2025-08-10 21:22:53 +08:00
|
|
|
|
2025-08-02 14:53:28 +08:00
|
|
|
// Admin 2FA routes
|
|
|
|
|
adminRoute.GET("/2fa/stats", controller.Admin2FAStats)
|
|
|
|
|
adminRoute.DELETE("/:id/2fa", controller.AdminDisable2FA)
|
2023-04-22 20:39:27 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
optionRoute := apiRouter.Group("/option")
|
2023-04-23 18:24:11 +08:00
|
|
|
optionRoute.Use(middleware.RootAuth())
|
2023-04-22 20:39:27 +08:00
|
|
|
{
|
|
|
|
|
optionRoute.GET("/", controller.GetOptions)
|
|
|
|
|
optionRoute.PUT("/", controller.UpdateOption)
|
2024-05-24 15:28:16 +08:00
|
|
|
optionRoute.POST("/rest_model_ratio", controller.ResetModelRatio)
|
2025-06-14 01:05:09 +08:00
|
|
|
optionRoute.POST("/migrate_console_setting", controller.MigrateConsoleSetting) // 用于迁移检测的旧键,下个版本会删除
|
2023-04-22 20:39:27 +08:00
|
|
|
}
|
2025-06-19 08:57:34 +08:00
|
|
|
ratioSyncRoute := apiRouter.Group("/ratio_sync")
|
|
|
|
|
ratioSyncRoute.Use(middleware.RootAuth())
|
|
|
|
|
{
|
|
|
|
|
ratioSyncRoute.GET("/channels", controller.GetSyncableChannels)
|
|
|
|
|
ratioSyncRoute.POST("/fetch", controller.FetchUpstreamRatios)
|
|
|
|
|
}
|
2023-04-22 22:02:59 +08:00
|
|
|
channelRoute := apiRouter.Group("/channel")
|
|
|
|
|
channelRoute.Use(middleware.AdminAuth())
|
2023-04-22 20:39:27 +08:00
|
|
|
{
|
2023-04-22 22:02:59 +08:00
|
|
|
channelRoute.GET("/", controller.GetAllChannels)
|
|
|
|
|
channelRoute.GET("/search", controller.SearchChannels)
|
2024-03-03 15:53:48 +08:00
|
|
|
channelRoute.GET("/models", controller.ChannelListModels)
|
2025-02-28 21:13:30 +08:00
|
|
|
channelRoute.GET("/models_enabled", controller.EnabledListModels)
|
2023-04-22 22:02:59 +08:00
|
|
|
channelRoute.GET("/:id", controller.GetChannel)
|
2025-11-11 21:44:44 +08:00
|
|
|
channelRoute.POST("/:id/key", middleware.RootAuth(), middleware.CriticalRateLimit(), middleware.DisableCache(), middleware.SecureVerificationRequired(), controller.GetChannelKey)
|
2023-05-15 12:36:55 +08:00
|
|
|
channelRoute.GET("/test", controller.TestAllChannels)
|
2023-05-15 10:48:52 +08:00
|
|
|
channelRoute.GET("/test/:id", controller.TestChannel)
|
2023-05-21 16:09:54 +08:00
|
|
|
channelRoute.GET("/update_balance", controller.UpdateAllChannelsBalance)
|
|
|
|
|
channelRoute.GET("/update_balance/:id", controller.UpdateChannelBalance)
|
2023-04-22 22:02:59 +08:00
|
|
|
channelRoute.POST("/", controller.AddChannel)
|
|
|
|
|
channelRoute.PUT("/", controller.UpdateChannel)
|
2023-10-14 17:25:48 +08:00
|
|
|
channelRoute.DELETE("/disabled", controller.DeleteDisabledChannel)
|
2024-11-19 01:13:18 +08:00
|
|
|
channelRoute.POST("/tag/disabled", controller.DisableTagChannels)
|
|
|
|
|
channelRoute.POST("/tag/enabled", controller.EnableTagChannels)
|
|
|
|
|
channelRoute.PUT("/tag", controller.EditTagChannels)
|
2023-04-22 22:02:59 +08:00
|
|
|
channelRoute.DELETE("/:id", controller.DeleteChannel)
|
2023-12-14 16:35:03 +08:00
|
|
|
channelRoute.POST("/batch", controller.DeleteChannelBatch)
|
2024-01-10 13:23:43 +08:00
|
|
|
channelRoute.POST("/fix", controller.FixChannelsAbilities)
|
2024-05-21 22:16:20 +08:00
|
|
|
channelRoute.GET("/fetch_models/:id", controller.FetchUpstreamModels)
|
2024-12-24 18:02:08 +08:00
|
|
|
channelRoute.POST("/fetch_models", controller.FetchModels)
|
2025-12-28 15:55:35 +08:00
|
|
|
channelRoute.POST("/ollama/pull", controller.OllamaPullModel)
|
|
|
|
|
channelRoute.POST("/ollama/pull/stream", controller.OllamaPullModelStream)
|
|
|
|
|
channelRoute.DELETE("/ollama/delete", controller.OllamaDeleteModel)
|
|
|
|
|
channelRoute.GET("/ollama/version/:id", controller.OllamaVersion)
|
2024-12-25 14:19:00 +08:00
|
|
|
channelRoute.POST("/batch/tag", controller.BatchSetChannelTag)
|
2025-06-08 01:16:27 +08:00
|
|
|
channelRoute.GET("/tag/models", controller.GetTagModels)
|
2025-07-14 21:54:53 +08:00
|
|
|
channelRoute.POST("/copy/:id", controller.CopyChannel)
|
2025-08-04 16:52:31 +08:00
|
|
|
channelRoute.POST("/multi_key/manage", controller.ManageMultiKeys)
|
2023-04-22 20:39:27 +08:00
|
|
|
}
|
2023-04-23 11:31:00 +08:00
|
|
|
tokenRoute := apiRouter.Group("/token")
|
|
|
|
|
tokenRoute.Use(middleware.UserAuth())
|
|
|
|
|
{
|
|
|
|
|
tokenRoute.GET("/", controller.GetAllTokens)
|
|
|
|
|
tokenRoute.GET("/search", controller.SearchTokens)
|
|
|
|
|
tokenRoute.GET("/:id", controller.GetToken)
|
|
|
|
|
tokenRoute.POST("/", controller.AddToken)
|
|
|
|
|
tokenRoute.PUT("/", controller.UpdateToken)
|
|
|
|
|
tokenRoute.DELETE("/:id", controller.DeleteToken)
|
2025-06-22 16:35:30 +08:00
|
|
|
tokenRoute.POST("/batch", controller.DeleteTokenBatch)
|
2023-04-23 11:31:00 +08:00
|
|
|
}
|
2025-08-23 15:45:43 +08:00
|
|
|
|
|
|
|
|
usageRoute := apiRouter.Group("/usage")
|
|
|
|
|
usageRoute.Use(middleware.CriticalRateLimit())
|
|
|
|
|
{
|
|
|
|
|
tokenUsageRoute := usageRoute.Group("/token")
|
|
|
|
|
tokenUsageRoute.Use(middleware.TokenAuth())
|
|
|
|
|
{
|
|
|
|
|
tokenUsageRoute.GET("/", controller.GetTokenUsage)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-26 17:02:26 +08:00
|
|
|
redemptionRoute := apiRouter.Group("/redemption")
|
|
|
|
|
redemptionRoute.Use(middleware.AdminAuth())
|
|
|
|
|
{
|
|
|
|
|
redemptionRoute.GET("/", controller.GetAllRedemptions)
|
|
|
|
|
redemptionRoute.GET("/search", controller.SearchRedemptions)
|
|
|
|
|
redemptionRoute.GET("/:id", controller.GetRedemption)
|
|
|
|
|
redemptionRoute.POST("/", controller.AddRedemption)
|
|
|
|
|
redemptionRoute.PUT("/", controller.UpdateRedemption)
|
2025-06-13 20:51:20 +08:00
|
|
|
redemptionRoute.DELETE("/invalid", controller.DeleteInvalidRedemption)
|
2023-04-26 17:02:26 +08:00
|
|
|
redemptionRoute.DELETE("/:id", controller.DeleteRedemption)
|
|
|
|
|
}
|
2023-06-09 16:59:00 +08:00
|
|
|
logRoute := apiRouter.Group("/log")
|
|
|
|
|
logRoute.GET("/", middleware.AdminAuth(), controller.GetAllLogs)
|
2023-09-17 17:09:56 +08:00
|
|
|
logRoute.DELETE("/", middleware.AdminAuth(), controller.DeleteHistoryLogs)
|
2023-06-24 15:28:11 +08:00
|
|
|
logRoute.GET("/stat", middleware.AdminAuth(), controller.GetLogsStat)
|
|
|
|
|
logRoute.GET("/self/stat", middleware.UserAuth(), controller.GetLogsSelfStat)
|
2023-06-09 16:59:00 +08:00
|
|
|
logRoute.GET("/search", middleware.AdminAuth(), controller.SearchAllLogs)
|
|
|
|
|
logRoute.GET("/self", middleware.UserAuth(), controller.GetUserLogs)
|
|
|
|
|
logRoute.GET("/self/search", middleware.UserAuth(), controller.SearchUserLogs)
|
2023-09-18 01:42:04 +08:00
|
|
|
|
2024-01-07 18:31:14 +08:00
|
|
|
dataRoute := apiRouter.Group("/data")
|
|
|
|
|
dataRoute.GET("/", middleware.AdminAuth(), controller.GetAllQuotaDates)
|
2024-01-07 19:47:35 +08:00
|
|
|
dataRoute.GET("/self", middleware.UserAuth(), controller.GetUserQuotaDates)
|
2024-01-07 18:31:14 +08:00
|
|
|
|
2023-09-18 01:42:04 +08:00
|
|
|
logRoute.Use(middleware.CORS())
|
|
|
|
|
{
|
|
|
|
|
logRoute.GET("/token", controller.GetLogByKey)
|
|
|
|
|
}
|
2023-06-11 11:08:16 +08:00
|
|
|
groupRoute := apiRouter.Group("/group")
|
|
|
|
|
groupRoute.Use(middleware.AdminAuth())
|
|
|
|
|
{
|
|
|
|
|
groupRoute.GET("/", controller.GetGroups)
|
|
|
|
|
}
|
2025-08-04 02:54:37 +08:00
|
|
|
|
|
|
|
|
prefillGroupRoute := apiRouter.Group("/prefill_group")
|
|
|
|
|
prefillGroupRoute.Use(middleware.AdminAuth())
|
|
|
|
|
{
|
|
|
|
|
prefillGroupRoute.GET("/", controller.GetPrefillGroups)
|
|
|
|
|
prefillGroupRoute.POST("/", controller.CreatePrefillGroup)
|
|
|
|
|
prefillGroupRoute.PUT("/", controller.UpdatePrefillGroup)
|
|
|
|
|
prefillGroupRoute.DELETE("/:id", controller.DeletePrefillGroup)
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-14 22:16:32 +08:00
|
|
|
mjRoute := apiRouter.Group("/mj")
|
|
|
|
|
mjRoute.GET("/self", middleware.UserAuth(), controller.GetUserMidjourney)
|
|
|
|
|
mjRoute.GET("/", middleware.AdminAuth(), controller.GetAllMidjourney)
|
2024-06-12 20:37:42 +08:00
|
|
|
|
|
|
|
|
taskRoute := apiRouter.Group("/task")
|
|
|
|
|
{
|
|
|
|
|
taskRoute.GET("/self", middleware.UserAuth(), controller.GetUserTask)
|
|
|
|
|
taskRoute.GET("/", middleware.AdminAuth(), controller.GetAllTask)
|
|
|
|
|
}
|
🚀 feat: Introduce full Model & Vendor Management suite (backend + frontend) and UI refinements
Backend
• Add `model/model_meta.go` and `model/vendor_meta.go` defining Model & Vendor entities with CRUD helpers, soft-delete and time stamps
• Create corresponding controllers `controller/model_meta.go`, `controller/vendor_meta.go` and register routes in `router/api-router.go`
• Auto-migrate new tables in DB startup logic
Frontend
• Build complete “Model Management” module under `/console/models`
- New pages, tables, filters, actions, hooks (`useModelsData`) and dynamic vendor tabs
- Modals `EditModelModal.jsx` & unified `EditVendorModal.jsx`; latter now uses default confirm/cancel footer and mobile-friendly modal sizing (`full-width` / `small`) via `useIsMobile`
• Update sidebar (`SiderBar.js`) and routing (`App.js`) to surface the feature
• Add helper updates (`render.js`) incl. `stringToColor`, dynamic LobeHub icon retrieval, and tag color palettes
Table UX improvements
• Replace separate status column with inline Enable / Disable buttons in operation column (matching channel table style)
• Limit visible tags to max 3; overflow represented as “+x” tag with padded `Popover` showing remaining tags
• Color all tags deterministically using `stringToColor` for consistent theming
• Change vendor column tag color to white for better contrast
Misc
• Minor layout tweaks, compact-mode toggle relocation, lint fixes and TypeScript/ESLint clean-up
These changes collectively deliver end-to-end model & vendor administration while unifying visual language across management tables.
2025-07-31 22:28:09 +08:00
|
|
|
|
|
|
|
|
vendorRoute := apiRouter.Group("/vendors")
|
2025-08-10 21:22:53 +08:00
|
|
|
vendorRoute.Use(middleware.AdminAuth())
|
|
|
|
|
{
|
|
|
|
|
vendorRoute.GET("/", controller.GetAllVendors)
|
|
|
|
|
vendorRoute.GET("/search", controller.SearchVendors)
|
|
|
|
|
vendorRoute.GET("/:id", controller.GetVendorMeta)
|
|
|
|
|
vendorRoute.POST("/", controller.CreateVendorMeta)
|
|
|
|
|
vendorRoute.PUT("/", controller.UpdateVendorMeta)
|
|
|
|
|
vendorRoute.DELETE("/:id", controller.DeleteVendorMeta)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
modelsRoute := apiRouter.Group("/models")
|
🚀 feat: Introduce full Model & Vendor Management suite (backend + frontend) and UI refinements
Backend
• Add `model/model_meta.go` and `model/vendor_meta.go` defining Model & Vendor entities with CRUD helpers, soft-delete and time stamps
• Create corresponding controllers `controller/model_meta.go`, `controller/vendor_meta.go` and register routes in `router/api-router.go`
• Auto-migrate new tables in DB startup logic
Frontend
• Build complete “Model Management” module under `/console/models`
- New pages, tables, filters, actions, hooks (`useModelsData`) and dynamic vendor tabs
- Modals `EditModelModal.jsx` & unified `EditVendorModal.jsx`; latter now uses default confirm/cancel footer and mobile-friendly modal sizing (`full-width` / `small`) via `useIsMobile`
• Update sidebar (`SiderBar.js`) and routing (`App.js`) to surface the feature
• Add helper updates (`render.js`) incl. `stringToColor`, dynamic LobeHub icon retrieval, and tag color palettes
Table UX improvements
• Replace separate status column with inline Enable / Disable buttons in operation column (matching channel table style)
• Limit visible tags to max 3; overflow represented as “+x” tag with padded `Popover` showing remaining tags
• Color all tags deterministically using `stringToColor` for consistent theming
• Change vendor column tag color to white for better contrast
Misc
• Minor layout tweaks, compact-mode toggle relocation, lint fixes and TypeScript/ESLint clean-up
These changes collectively deliver end-to-end model & vendor administration while unifying visual language across management tables.
2025-07-31 22:28:09 +08:00
|
|
|
modelsRoute.Use(middleware.AdminAuth())
|
|
|
|
|
{
|
✨ feat(models-sync): official upstream sync with conflict resolution UI, opt‑out flag, and backend resiliency
Backend
- Add endpoints:
- GET /api/models/sync_upstream/preview — diff preview (filters out models with sync_official = 0)
- POST /api/models/sync_upstream — apply sync (create missing; optionally overwrite selected fields)
- Respect opt‑out: skip models with sync_official = 0 in both preview and apply
- Return detailed stats: created_models, created_vendors, updated_models, skipped_models, plus created_list / updated_list
- Add model.Model.SyncOfficial (default 1); auto‑migrated by GORM
- Make HTTP fetching robust:
- Shared http.Client (connection reuse) with 3x exponential backoff retry
- 10MB response cap; keep existing IPv4‑first for *.github.io
- Vendor handling:
- New ensureVendorID helper (cache lookup → DB lookup → create), reduces round‑trips
- Transactional overwrite to avoid partial updates
- Small cleanups and clearer helpers (containsField, coalesce, chooseStatus)
Frontend
- ModelsActions: add “Sync official” button with Popover (p‑2) explaining community contribution; loading = syncing || previewing; preview → conflict modal → apply flow
- New UpstreamConflictModal:
- Per‑field columns (description/icon/tags/vendor/name_rule/status) with column‑level checkbox to select all
- Cell with Checkbox + Tag (“Click to view differences”) and Popover (p‑2) showing Local vs Official values
- Auto‑hide columns with no conflicts; responsive width; use native Semi Modal footer
- Full i18n coverage
- useModelsData: add syncing/previewing states; new methods previewUpstreamDiff, applyUpstreamOverwrite, syncUpstream; refresh vendors/models after apply
- EditModelModal: add “Participate in official sync” switch; persisted as sync_official
- ModelsColumnDefs: add “Participate in official sync” column
i18n
- Add missing English keys for the new UI and messages; fix quoting issues
Refs
- Upstream metadata: https://github.com/basellm/llm-metadata
2025-09-02 02:04:22 +08:00
|
|
|
modelsRoute.GET("/sync_upstream/preview", controller.SyncUpstreamPreview)
|
|
|
|
|
modelsRoute.POST("/sync_upstream", controller.SyncUpstreamModels)
|
2025-08-03 22:51:24 +08:00
|
|
|
modelsRoute.GET("/missing", controller.GetMissingModels)
|
2025-08-10 21:22:53 +08:00
|
|
|
modelsRoute.GET("/", controller.GetAllModelsMeta)
|
|
|
|
|
modelsRoute.GET("/search", controller.SearchModelsMeta)
|
🚀 feat: Introduce full Model & Vendor Management suite (backend + frontend) and UI refinements
Backend
• Add `model/model_meta.go` and `model/vendor_meta.go` defining Model & Vendor entities with CRUD helpers, soft-delete and time stamps
• Create corresponding controllers `controller/model_meta.go`, `controller/vendor_meta.go` and register routes in `router/api-router.go`
• Auto-migrate new tables in DB startup logic
Frontend
• Build complete “Model Management” module under `/console/models`
- New pages, tables, filters, actions, hooks (`useModelsData`) and dynamic vendor tabs
- Modals `EditModelModal.jsx` & unified `EditVendorModal.jsx`; latter now uses default confirm/cancel footer and mobile-friendly modal sizing (`full-width` / `small`) via `useIsMobile`
• Update sidebar (`SiderBar.js`) and routing (`App.js`) to surface the feature
• Add helper updates (`render.js`) incl. `stringToColor`, dynamic LobeHub icon retrieval, and tag color palettes
Table UX improvements
• Replace separate status column with inline Enable / Disable buttons in operation column (matching channel table style)
• Limit visible tags to max 3; overflow represented as “+x” tag with padded `Popover` showing remaining tags
• Color all tags deterministically using `stringToColor` for consistent theming
• Change vendor column tag color to white for better contrast
Misc
• Minor layout tweaks, compact-mode toggle relocation, lint fixes and TypeScript/ESLint clean-up
These changes collectively deliver end-to-end model & vendor administration while unifying visual language across management tables.
2025-07-31 22:28:09 +08:00
|
|
|
modelsRoute.GET("/:id", controller.GetModelMeta)
|
|
|
|
|
modelsRoute.POST("/", controller.CreateModelMeta)
|
|
|
|
|
modelsRoute.PUT("/", controller.UpdateModelMeta)
|
|
|
|
|
modelsRoute.DELETE("/:id", controller.DeleteModelMeta)
|
|
|
|
|
}
|
2025-12-28 15:55:35 +08:00
|
|
|
|
|
|
|
|
// Deployments (model deployment management)
|
|
|
|
|
deploymentsRoute := apiRouter.Group("/deployments")
|
|
|
|
|
deploymentsRoute.Use(middleware.AdminAuth())
|
|
|
|
|
{
|
|
|
|
|
// List and search deployments
|
|
|
|
|
deploymentsRoute.GET("/", controller.GetAllDeployments)
|
|
|
|
|
deploymentsRoute.GET("/search", controller.SearchDeployments)
|
|
|
|
|
|
|
|
|
|
// Connection utilities
|
|
|
|
|
deploymentsRoute.POST("/test-connection", controller.TestIoNetConnection)
|
|
|
|
|
|
|
|
|
|
// Resource and configuration endpoints
|
|
|
|
|
deploymentsRoute.GET("/hardware-types", controller.GetHardwareTypes)
|
|
|
|
|
deploymentsRoute.GET("/locations", controller.GetLocations)
|
|
|
|
|
deploymentsRoute.GET("/available-replicas", controller.GetAvailableReplicas)
|
|
|
|
|
deploymentsRoute.POST("/price-estimation", controller.GetPriceEstimation)
|
|
|
|
|
deploymentsRoute.GET("/check-name", controller.CheckClusterNameAvailability)
|
|
|
|
|
|
|
|
|
|
// Create new deployment
|
|
|
|
|
deploymentsRoute.POST("/", controller.CreateDeployment)
|
|
|
|
|
|
|
|
|
|
// Individual deployment operations
|
|
|
|
|
deploymentsRoute.GET("/:id", controller.GetDeployment)
|
|
|
|
|
deploymentsRoute.GET("/:id/logs", controller.GetDeploymentLogs)
|
|
|
|
|
deploymentsRoute.GET("/:id/containers", controller.ListDeploymentContainers)
|
|
|
|
|
deploymentsRoute.GET("/:id/containers/:container_id", controller.GetContainerDetails)
|
|
|
|
|
deploymentsRoute.PUT("/:id", controller.UpdateDeployment)
|
|
|
|
|
deploymentsRoute.PUT("/:id/name", controller.UpdateDeploymentName)
|
|
|
|
|
deploymentsRoute.POST("/:id/extend", controller.ExtendDeployment)
|
|
|
|
|
deploymentsRoute.DELETE("/:id", controller.DeleteDeployment)
|
|
|
|
|
|
|
|
|
|
// Future batch operations:
|
|
|
|
|
// deploymentsRoute.POST("/:id/start", controller.StartDeployment)
|
|
|
|
|
// deploymentsRoute.POST("/:id/stop", controller.StopDeployment)
|
|
|
|
|
// deploymentsRoute.POST("/:id/restart", controller.RestartDeployment)
|
|
|
|
|
// deploymentsRoute.POST("/batch_delete", controller.BatchDeleteDeployments)
|
|
|
|
|
// deploymentsRoute.POST("/batch_start", controller.BatchStartDeployments)
|
|
|
|
|
// deploymentsRoute.POST("/batch_stop", controller.BatchStopDeployments)
|
|
|
|
|
}
|
2023-04-22 20:39:27 +08:00
|
|
|
}
|
|
|
|
|
}
|