Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

430 Zeilen
22 KiB

  1. package router
  2. import (
  3. "github.com/QuantumNous/new-api/controller"
  4. "github.com/QuantumNous/new-api/middleware"
  5. // Import oauth package to register providers via init()
  6. _ "github.com/QuantumNous/new-api/oauth"
  7. "github.com/gin-contrib/gzip"
  8. "github.com/gin-gonic/gin"
  9. )
  10. func SetApiRouter(router *gin.Engine) {
  11. apiRouter := router.Group("/api")
  12. apiRouter.Use(gzip.Gzip(gzip.DefaultCompression))
  13. apiRouter.Use(middleware.BodyStorageCleanup()) // 清理请求体存储
  14. apiRouter.Use(middleware.GlobalAPIRateLimit())
  15. {
  16. apiRouter.GET("/setup", controller.GetSetup)
  17. apiRouter.POST("/setup", controller.PostSetup)
  18. apiRouter.GET("/status", controller.GetStatus)
  19. apiRouter.GET("/uptime/status", controller.GetUptimeKumaStatus)
  20. apiRouter.GET("/models", middleware.UserAuth(), controller.DashboardListModels)
  21. apiRouter.GET("/status/test", middleware.AdminAuth(), controller.TestStatus)
  22. apiRouter.GET("/notice", controller.GetNotice)
  23. apiRouter.GET("/user-agreement", controller.GetUserAgreement)
  24. apiRouter.GET("/privacy-policy", controller.GetPrivacyPolicy)
  25. apiRouter.GET("/terms", controller.GetTermsOfService)
  26. apiRouter.GET("/usage-policy", controller.GetUsagePolicy)
  27. apiRouter.GET("/about", controller.GetAbout)
  28. //apiRouter.GET("/midjourney", controller.GetMidjourney)
  29. apiRouter.GET("/home_page_content", controller.GetHomePageContent)
  30. apiRouter.GET("/pricing", middleware.TryUserAuth(), controller.GetPricing)
  31. apiRouter.GET("/channel-pricing/model/*name", middleware.TryUserAuth(), controller.GetChannelPricingByModelWithChannelInfo)
  32. apiRouter.GET("/captcha", controller.GetCaptcha)
  33. apiRouter.GET("/verification", middleware.EmailVerificationRateLimit(), middleware.TurnstileCheck(), controller.SendEmailVerification)
  34. apiRouter.GET("/reset_password", middleware.CriticalRateLimit(), middleware.TurnstileCheck(), controller.SendPasswordResetEmail)
  35. apiRouter.POST("/user/reset", middleware.CriticalRateLimit(), controller.ResetPassword)
  36. // OAuth routes - specific routes must come before :provider wildcard
  37. apiRouter.GET("/oauth/state", middleware.CriticalRateLimit(), controller.GenerateOAuthCode)
  38. apiRouter.GET("/oauth/email/bind", middleware.CriticalRateLimit(), controller.EmailBind)
  39. // Non-standard OAuth (WeChat, Telegram) - keep original routes
  40. apiRouter.GET("/oauth/wechat", middleware.CriticalRateLimit(), controller.WeChatAuth)
  41. apiRouter.GET("/oauth/wechat/bind", middleware.CriticalRateLimit(), controller.WeChatBind)
  42. apiRouter.GET("/oauth/telegram/login", middleware.CriticalRateLimit(), controller.TelegramLogin)
  43. apiRouter.GET("/oauth/telegram/bind", middleware.CriticalRateLimit(), controller.TelegramBind)
  44. // Standard OAuth providers (GitHub, Discord, OIDC, LinuxDO) - unified route
  45. apiRouter.GET("/oauth/:provider", middleware.CriticalRateLimit(), controller.HandleOAuth)
  46. apiRouter.GET("/ratio_config", middleware.CriticalRateLimit(), controller.GetRatioConfig)
  47. apiRouter.POST("/stripe/webhook", controller.StripeWebhook)
  48. apiRouter.POST("/creem/webhook", controller.CreemWebhook)
  49. apiRouter.POST("/wechat/pay/webhook", controller.WechatPayWebhook)
  50. apiRouter.POST("/alipay/pay/webhook", controller.AlipayPayWebhook)
  51. // Universal secure verification routes
  52. apiRouter.POST("/verify", middleware.UserAuth(), middleware.CriticalRateLimit(), controller.UniversalVerify)
  53. userRoute := apiRouter.Group("/user")
  54. {
  55. userRoute.POST("/register", middleware.CriticalRateLimit(), middleware.TurnstileCheck(), controller.Register)
  56. userRoute.POST("/login", middleware.CriticalRateLimit(), middleware.TurnstileCheck(), controller.Login)
  57. userRoute.POST("/login/2fa", middleware.CriticalRateLimit(), controller.Verify2FALogin)
  58. userRoute.POST("/passkey/login/begin", middleware.CriticalRateLimit(), controller.PasskeyLoginBegin)
  59. userRoute.POST("/passkey/login/finish", middleware.CriticalRateLimit(), controller.PasskeyLoginFinish)
  60. //userRoute.POST("/tokenlog", middleware.CriticalRateLimit(), controller.TokenLog)
  61. userRoute.GET("/logout", controller.Logout)
  62. userRoute.POST("/epay/notify", controller.EpayNotify)
  63. userRoute.GET("/epay/notify", controller.EpayNotify)
  64. userRoute.GET("/groups", controller.GetUserGroups)
  65. selfRoute := userRoute.Group("/")
  66. selfRoute.Use(middleware.UserAuth())
  67. {
  68. selfRoute.GET("/self/groups", controller.GetUserGroups)
  69. selfRoute.GET("/self", controller.GetSelf)
  70. selfRoute.GET("/models", controller.GetUserModels)
  71. selfRoute.GET("/channels", controller.GetUserChannelsForBinding)
  72. selfRoute.PUT("/self", controller.UpdateSelf)
  73. selfRoute.DELETE("/self", controller.DeleteSelf)
  74. selfRoute.GET("/token", controller.GenerateAccessToken)
  75. selfRoute.GET("/passkey", controller.PasskeyStatus)
  76. selfRoute.POST("/passkey/register/begin", controller.PasskeyRegisterBegin)
  77. selfRoute.POST("/passkey/register/finish", controller.PasskeyRegisterFinish)
  78. selfRoute.POST("/passkey/verify/begin", controller.PasskeyVerifyBegin)
  79. selfRoute.POST("/passkey/verify/finish", controller.PasskeyVerifyFinish)
  80. selfRoute.DELETE("/passkey", controller.PasskeyDelete)
  81. selfRoute.GET("/aff", controller.GetAffCode)
  82. selfRoute.GET("/topup/info", controller.GetTopUpInfo)
  83. selfRoute.GET("/topup/self", controller.GetUserTopUps)
  84. selfRoute.POST("/topup", middleware.CriticalRateLimit(), controller.TopUp)
  85. selfRoute.POST("/pay", middleware.CriticalRateLimit(), controller.RequestEpay)
  86. selfRoute.POST("/amount", controller.RequestAmount)
  87. selfRoute.POST("/stripe/pay", middleware.CriticalRateLimit(), controller.RequestStripePay)
  88. selfRoute.POST("/stripe/amount", controller.RequestStripeAmount)
  89. selfRoute.POST("/creem/pay", middleware.CriticalRateLimit(), controller.RequestCreemPay)
  90. selfRoute.POST("/wechat/pay/amount", controller.RequestWechatPayAmount)
  91. selfRoute.POST("/wechat/pay", controller.RequestWechatPay)
  92. selfRoute.GET("/wechat/pay/status", controller.WechatPayStatus)
  93. selfRoute.POST("/alipay/pay/amount", controller.RequestAlipayPayAmount)
  94. selfRoute.POST("/alipay/pay", controller.RequestAlipayPay)
  95. selfRoute.GET("/alipay/pay/status", controller.AlipayPayStatus)
  96. selfRoute.POST("/aff_transfer", controller.TransferAffQuota)
  97. selfRoute.PUT("/setting", controller.UpdateUserSetting)
  98. // 2FA routes
  99. selfRoute.GET("/2fa/status", controller.Get2FAStatus)
  100. selfRoute.POST("/2fa/setup", controller.Setup2FA)
  101. selfRoute.POST("/2fa/enable", controller.Enable2FA)
  102. selfRoute.POST("/2fa/disable", controller.Disable2FA)
  103. selfRoute.POST("/2fa/backup_codes", controller.RegenerateBackupCodes)
  104. // Check-in routes
  105. selfRoute.GET("/checkin", controller.GetCheckinStatus)
  106. selfRoute.POST("/checkin", middleware.TurnstileCheck(), controller.DoCheckin)
  107. // Custom OAuth bindings
  108. selfRoute.GET("/oauth/bindings", controller.GetUserOAuthBindings)
  109. selfRoute.DELETE("/oauth/bindings/:provider_id", controller.UnbindCustomOAuth)
  110. }
  111. adminRoute := userRoute.Group("/")
  112. adminRoute.Use(middleware.AdminAuth())
  113. {
  114. adminRoute.GET("/", controller.GetAllUsers)
  115. adminRoute.GET("/topup", controller.GetAllTopUps)
  116. adminRoute.POST("/topup/complete", controller.AdminCompleteTopUp)
  117. adminRoute.GET("/search", controller.SearchUsers)
  118. adminRoute.GET("/:id/oauth/bindings", controller.GetUserOAuthBindingsByAdmin)
  119. adminRoute.DELETE("/:id/oauth/bindings/:provider_id", controller.UnbindCustomOAuthByAdmin)
  120. adminRoute.DELETE("/:id/bindings/:binding_type", controller.AdminClearUserBinding)
  121. adminRoute.GET("/:id", controller.GetUser)
  122. adminRoute.POST("/", controller.CreateUser)
  123. adminRoute.POST("/manage", controller.ManageUser)
  124. adminRoute.PUT("/", controller.UpdateUser)
  125. adminRoute.DELETE("/:id", controller.DeleteUser)
  126. adminRoute.DELETE("/:id/reset_passkey", controller.AdminResetPasskey)
  127. // Admin 2FA routes
  128. adminRoute.GET("/2fa/stats", controller.Admin2FAStats)
  129. adminRoute.DELETE("/:id/2fa", controller.AdminDisable2FA)
  130. }
  131. }
  132. // Subscription billing (plans, purchase, admin management)
  133. subscriptionRoute := apiRouter.Group("/subscription")
  134. subscriptionRoute.Use(middleware.UserAuth())
  135. {
  136. subscriptionRoute.GET("/plans", controller.GetSubscriptionPlans)
  137. subscriptionRoute.GET("/self", controller.GetSubscriptionSelf)
  138. subscriptionRoute.PUT("/self/preference", controller.UpdateSubscriptionPreference)
  139. subscriptionRoute.POST("/epay/pay", middleware.CriticalRateLimit(), controller.SubscriptionRequestEpay)
  140. subscriptionRoute.POST("/stripe/pay", middleware.CriticalRateLimit(), controller.SubscriptionRequestStripePay)
  141. subscriptionRoute.POST("/creem/pay", middleware.CriticalRateLimit(), controller.SubscriptionRequestCreemPay)
  142. subscriptionRoute.POST("/wechat/pay", middleware.CriticalRateLimit(), controller.SubscriptionRequestWechatPay)
  143. }
  144. subscriptionAdminRoute := apiRouter.Group("/subscription/admin")
  145. subscriptionAdminRoute.Use(middleware.AdminAuth())
  146. {
  147. subscriptionAdminRoute.GET("/plans", controller.AdminListSubscriptionPlans)
  148. subscriptionAdminRoute.POST("/plans", controller.AdminCreateSubscriptionPlan)
  149. subscriptionAdminRoute.PUT("/plans/:id", controller.AdminUpdateSubscriptionPlan)
  150. subscriptionAdminRoute.PATCH("/plans/:id", controller.AdminUpdateSubscriptionPlanStatus)
  151. subscriptionAdminRoute.POST("/bind", controller.AdminBindSubscription)
  152. // User subscription management (admin)
  153. subscriptionAdminRoute.GET("/users/:id/subscriptions", controller.AdminListUserSubscriptions)
  154. subscriptionAdminRoute.POST("/users/:id/subscriptions", controller.AdminCreateUserSubscription)
  155. subscriptionAdminRoute.POST("/user_subscriptions/:id/invalidate", controller.AdminInvalidateUserSubscription)
  156. subscriptionAdminRoute.DELETE("/user_subscriptions/:id", controller.AdminDeleteUserSubscription)
  157. }
  158. // Subscription payment callbacks (no auth)
  159. apiRouter.POST("/subscription/epay/notify", controller.SubscriptionEpayNotify)
  160. apiRouter.GET("/subscription/epay/notify", controller.SubscriptionEpayNotify)
  161. apiRouter.GET("/subscription/epay/return", controller.SubscriptionEpayReturn)
  162. apiRouter.POST("/subscription/epay/return", controller.SubscriptionEpayReturn)
  163. optionRoute := apiRouter.Group("/option")
  164. optionRoute.Use(middleware.RootAuth())
  165. {
  166. optionRoute.GET("/", controller.GetOptions)
  167. optionRoute.PUT("/", controller.UpdateOption)
  168. optionRoute.GET("/channel_affinity_cache", controller.GetChannelAffinityCacheStats)
  169. optionRoute.DELETE("/channel_affinity_cache", controller.ClearChannelAffinityCache)
  170. optionRoute.POST("/rest_model_ratio", controller.ResetModelRatio)
  171. optionRoute.POST("/migrate_console_setting", controller.MigrateConsoleSetting) // 用于迁移检测的旧键,下个版本会删除
  172. }
  173. // 渠道定价路由(管理员权限)
  174. channelPricingRoute := apiRouter.Group("/channel_pricing")
  175. channelPricingRoute.Use(middleware.AdminAuth())
  176. {
  177. channelPricingRoute.GET("/", controller.GetAllChannelPricing)
  178. channelPricingRoute.GET("/with_tags", controller.GetChannelPricingWithTags)
  179. channelPricingRoute.GET("/model/:name", controller.GetChannelPricingByModel)
  180. channelPricingRoute.POST("/", controller.CreateChannelPricing)
  181. channelPricingRoute.POST("/batch", controller.BatchCreateChannelPricing)
  182. channelPricingRoute.POST("/copy_global/:channel_id", controller.CopyGlobalPricing)
  183. channelPricingRoute.DELETE("/:id", controller.DeleteChannelPricing)
  184. channelPricingRoute.POST("/set_default", controller.SetDefaultChannel)
  185. channelPricingRoute.DELETE("/default/*name", controller.ClearDefaultChannel)
  186. }
  187. // 定价标签路由(管理员权限)
  188. pricingTagRoute := apiRouter.Group("/pricing_tag")
  189. pricingTagRoute.Use(middleware.AdminAuth())
  190. {
  191. pricingTagRoute.GET("/", controller.GetAllPricingTags)
  192. pricingTagRoute.POST("/", controller.CreatePricingTag)
  193. pricingTagRoute.PUT("/:id", controller.UpdatePricingTag)
  194. pricingTagRoute.DELETE("/:id", controller.DeletePricingTag)
  195. }
  196. // 邮箱后缀额度规则路由(管理员权限)
  197. emailQuotaRuleRoute := apiRouter.Group("/email_quota_rule")
  198. emailQuotaRuleRoute.Use(middleware.AdminAuth())
  199. {
  200. emailQuotaRuleRoute.GET("/", controller.GetAllEmailQuotaRules)
  201. emailQuotaRuleRoute.POST("/", controller.CreateEmailQuotaRule)
  202. emailQuotaRuleRoute.PUT("/:id", controller.UpdateEmailQuotaRule)
  203. emailQuotaRuleRoute.DELETE("/:id", controller.DeleteEmailQuotaRule)
  204. }
  205. // Custom OAuth provider management (root only)
  206. customOAuthRoute := apiRouter.Group("/custom-oauth-provider")
  207. customOAuthRoute.Use(middleware.RootAuth())
  208. {
  209. customOAuthRoute.POST("/discovery", controller.FetchCustomOAuthDiscovery)
  210. customOAuthRoute.GET("/", controller.GetCustomOAuthProviders)
  211. customOAuthRoute.GET("/:id", controller.GetCustomOAuthProvider)
  212. customOAuthRoute.POST("/", controller.CreateCustomOAuthProvider)
  213. customOAuthRoute.PUT("/:id", controller.UpdateCustomOAuthProvider)
  214. customOAuthRoute.DELETE("/:id", controller.DeleteCustomOAuthProvider)
  215. }
  216. performanceRoute := apiRouter.Group("/performance")
  217. performanceRoute.Use(middleware.RootAuth())
  218. {
  219. performanceRoute.GET("/stats", controller.GetPerformanceStats)
  220. performanceRoute.DELETE("/disk_cache", controller.ClearDiskCache)
  221. performanceRoute.POST("/reset_stats", controller.ResetPerformanceStats)
  222. performanceRoute.POST("/gc", controller.ForceGC)
  223. }
  224. ratioSyncRoute := apiRouter.Group("/ratio_sync")
  225. ratioSyncRoute.Use(middleware.RootAuth())
  226. {
  227. ratioSyncRoute.GET("/channels", controller.GetSyncableChannels)
  228. ratioSyncRoute.POST("/fetch", controller.FetchUpstreamRatios)
  229. }
  230. channelRoute := apiRouter.Group("/channel")
  231. channelRoute.Use(middleware.AdminAuth())
  232. {
  233. channelRoute.GET("/", controller.GetAllChannels)
  234. channelRoute.GET("/search", controller.SearchChannels)
  235. channelRoute.GET("/models", controller.ChannelListModels)
  236. channelRoute.GET("/models_enabled", controller.EnabledListModels)
  237. channelRoute.GET("/:id", controller.GetChannel)
  238. channelRoute.POST("/:id/key", middleware.RootAuth(), middleware.CriticalRateLimit(), middleware.DisableCache(), middleware.SecureVerificationRequired(), controller.GetChannelKey)
  239. channelRoute.GET("/test", controller.TestAllChannels)
  240. channelRoute.GET("/test/:id", controller.TestChannel)
  241. channelRoute.GET("/update_balance", controller.UpdateAllChannelsBalance)
  242. channelRoute.GET("/update_balance/:id", controller.UpdateChannelBalance)
  243. channelRoute.POST("/", controller.AddChannel)
  244. channelRoute.PUT("/", controller.UpdateChannel)
  245. channelRoute.DELETE("/disabled", controller.DeleteDisabledChannel)
  246. channelRoute.POST("/tag/disabled", controller.DisableTagChannels)
  247. channelRoute.POST("/tag/enabled", controller.EnableTagChannels)
  248. channelRoute.PUT("/tag", controller.EditTagChannels)
  249. channelRoute.DELETE("/:id", controller.DeleteChannel)
  250. channelRoute.POST("/batch", controller.DeleteChannelBatch)
  251. channelRoute.POST("/fix", controller.FixChannelsAbilities)
  252. channelRoute.GET("/fetch_models/:id", controller.FetchUpstreamModels)
  253. channelRoute.POST("/fetch_models", middleware.RootAuth(), controller.FetchModels)
  254. channelRoute.POST("/codex/oauth/start", controller.StartCodexOAuth)
  255. channelRoute.POST("/codex/oauth/complete", controller.CompleteCodexOAuth)
  256. channelRoute.POST("/:id/codex/oauth/start", controller.StartCodexOAuthForChannel)
  257. channelRoute.POST("/:id/codex/oauth/complete", controller.CompleteCodexOAuthForChannel)
  258. channelRoute.POST("/:id/codex/refresh", controller.RefreshCodexChannelCredential)
  259. channelRoute.GET("/:id/codex/usage", controller.GetCodexChannelUsage)
  260. channelRoute.POST("/ollama/pull", controller.OllamaPullModel)
  261. channelRoute.POST("/ollama/pull/stream", controller.OllamaPullModelStream)
  262. channelRoute.DELETE("/ollama/delete", controller.OllamaDeleteModel)
  263. channelRoute.GET("/ollama/version/:id", controller.OllamaVersion)
  264. channelRoute.POST("/batch/tag", controller.BatchSetChannelTag)
  265. channelRoute.GET("/tag/models", controller.GetTagModels)
  266. channelRoute.POST("/copy/:id", controller.CopyChannel)
  267. channelRoute.POST("/multi_key/manage", controller.ManageMultiKeys)
  268. }
  269. tokenRoute := apiRouter.Group("/token")
  270. tokenRoute.Use(middleware.UserAuth())
  271. {
  272. tokenRoute.GET("/", controller.GetAllTokens)
  273. tokenRoute.GET("/search", middleware.SearchRateLimit(), controller.SearchTokens)
  274. tokenRoute.GET("/:id", controller.GetToken)
  275. tokenRoute.POST("/", controller.AddToken)
  276. tokenRoute.PUT("/", controller.UpdateToken)
  277. tokenRoute.DELETE("/:id", controller.DeleteToken)
  278. tokenRoute.POST("/batch", controller.DeleteTokenBatch)
  279. }
  280. usageRoute := apiRouter.Group("/usage")
  281. usageRoute.Use(middleware.CORS(), middleware.CriticalRateLimit())
  282. {
  283. tokenUsageRoute := usageRoute.Group("/token")
  284. tokenUsageRoute.Use(middleware.TokenAuthReadOnly())
  285. {
  286. tokenUsageRoute.GET("/", controller.GetTokenUsage)
  287. }
  288. }
  289. redemptionRoute := apiRouter.Group("/redemption")
  290. redemptionRoute.Use(middleware.AdminAuth())
  291. {
  292. redemptionRoute.GET("/", controller.GetAllRedemptions)
  293. redemptionRoute.GET("/search", controller.SearchRedemptions)
  294. redemptionRoute.GET("/:id", controller.GetRedemption)
  295. redemptionRoute.POST("/", controller.AddRedemption)
  296. redemptionRoute.PUT("/", controller.UpdateRedemption)
  297. redemptionRoute.DELETE("/invalid", controller.DeleteInvalidRedemption)
  298. redemptionRoute.DELETE("/:id", controller.DeleteRedemption)
  299. }
  300. logRoute := apiRouter.Group("/log")
  301. logRoute.GET("/", middleware.AdminAuth(), controller.GetAllLogs)
  302. logRoute.DELETE("/", middleware.AdminAuth(), controller.DeleteHistoryLogs)
  303. logRoute.GET("/stat", middleware.AdminAuth(), controller.GetLogsStat)
  304. logRoute.GET("/self/stat", middleware.UserAuth(), controller.GetLogsSelfStat)
  305. logRoute.GET("/channel_affinity_usage_cache", middleware.AdminAuth(), controller.GetChannelAffinityUsageCacheStats)
  306. logRoute.GET("/search", middleware.AdminAuth(), controller.SearchAllLogs)
  307. logRoute.GET("/self", middleware.UserAuth(), controller.GetUserLogs)
  308. logRoute.GET("/self/search", middleware.UserAuth(), middleware.SearchRateLimit(), controller.SearchUserLogs)
  309. dataRoute := apiRouter.Group("/data")
  310. dataRoute.GET("/", middleware.AdminAuth(), controller.GetAllQuotaDates)
  311. dataRoute.GET("/self", middleware.UserAuth(), controller.GetUserQuotaDates)
  312. logRoute.Use(middleware.CORS(), middleware.CriticalRateLimit())
  313. {
  314. logRoute.GET("/token", middleware.TokenAuthReadOnly(), controller.GetLogByKey)
  315. }
  316. groupRoute := apiRouter.Group("/group")
  317. groupRoute.Use(middleware.AdminAuth())
  318. {
  319. groupRoute.GET("/", controller.GetGroups)
  320. }
  321. prefillGroupRoute := apiRouter.Group("/prefill_group")
  322. prefillGroupRoute.Use(middleware.AdminAuth())
  323. {
  324. prefillGroupRoute.GET("/", controller.GetPrefillGroups)
  325. prefillGroupRoute.POST("/", controller.CreatePrefillGroup)
  326. prefillGroupRoute.PUT("/", controller.UpdatePrefillGroup)
  327. prefillGroupRoute.DELETE("/:id", controller.DeletePrefillGroup)
  328. }
  329. mjRoute := apiRouter.Group("/mj")
  330. mjRoute.GET("/self", middleware.UserAuth(), controller.GetUserMidjourney)
  331. mjRoute.GET("/", middleware.AdminAuth(), controller.GetAllMidjourney)
  332. taskRoute := apiRouter.Group("/task")
  333. {
  334. taskRoute.GET("/self", middleware.UserAuth(), controller.GetUserTask)
  335. taskRoute.GET("/", middleware.AdminAuth(), controller.GetAllTask)
  336. }
  337. vendorRoute := apiRouter.Group("/vendors")
  338. vendorRoute.Use(middleware.AdminAuth())
  339. {
  340. vendorRoute.GET("/", controller.GetAllVendors)
  341. vendorRoute.GET("/search", controller.SearchVendors)
  342. vendorRoute.GET("/:id", controller.GetVendorMeta)
  343. vendorRoute.POST("/", controller.CreateVendorMeta)
  344. vendorRoute.PUT("/", controller.UpdateVendorMeta)
  345. vendorRoute.PUT("/reorder", controller.ReorderVendors)
  346. vendorRoute.DELETE("/:id", controller.DeleteVendorMeta)
  347. }
  348. modelsRoute := apiRouter.Group("/models")
  349. modelsRoute.Use(middleware.AdminAuth())
  350. {
  351. modelsRoute.GET("/sync_upstream/preview", controller.SyncUpstreamPreview)
  352. modelsRoute.POST("/sync_upstream", controller.SyncUpstreamModels)
  353. modelsRoute.GET("/missing", controller.GetMissingModels)
  354. modelsRoute.GET("/", controller.GetAllModelsMeta)
  355. modelsRoute.GET("/search", controller.SearchModelsMeta)
  356. modelsRoute.GET("/:id", controller.GetModelMeta)
  357. modelsRoute.POST("/", controller.CreateModelMeta)
  358. modelsRoute.PUT("/", controller.UpdateModelMeta)
  359. modelsRoute.PUT("/reorder", controller.ReorderModels)
  360. modelsRoute.DELETE("/:id", controller.DeleteModelMeta)
  361. }
  362. // Deployments (model deployment management)
  363. deploymentsRoute := apiRouter.Group("/deployments")
  364. deploymentsRoute.Use(middleware.AdminAuth())
  365. {
  366. deploymentsRoute.GET("/settings", controller.GetModelDeploymentSettings)
  367. deploymentsRoute.POST("/settings/test-connection", controller.TestIoNetConnection)
  368. deploymentsRoute.GET("/", controller.GetAllDeployments)
  369. deploymentsRoute.GET("/search", controller.SearchDeployments)
  370. deploymentsRoute.POST("/test-connection", controller.TestIoNetConnection)
  371. deploymentsRoute.GET("/hardware-types", controller.GetHardwareTypes)
  372. deploymentsRoute.GET("/locations", controller.GetLocations)
  373. deploymentsRoute.GET("/available-replicas", controller.GetAvailableReplicas)
  374. deploymentsRoute.POST("/price-estimation", controller.GetPriceEstimation)
  375. deploymentsRoute.GET("/check-name", controller.CheckClusterNameAvailability)
  376. deploymentsRoute.POST("/", controller.CreateDeployment)
  377. deploymentsRoute.GET("/:id", controller.GetDeployment)
  378. deploymentsRoute.GET("/:id/logs", controller.GetDeploymentLogs)
  379. deploymentsRoute.GET("/:id/containers", controller.ListDeploymentContainers)
  380. deploymentsRoute.GET("/:id/containers/:container_id", controller.GetContainerDetails)
  381. deploymentsRoute.PUT("/:id", controller.UpdateDeployment)
  382. deploymentsRoute.PUT("/:id/name", controller.UpdateDeploymentName)
  383. deploymentsRoute.POST("/:id/extend", controller.ExtendDeployment)
  384. deploymentsRoute.DELETE("/:id", controller.DeleteDeployment)
  385. }
  386. // Region sync API routes (for inter-node communication)
  387. syncRoute := apiRouter.Group("/internal/sync")
  388. syncRoute.Use(middleware.SyncAuth())
  389. {
  390. syncRoute.POST("/user/create", controller.ReceiveSyncedUserCreate)
  391. syncRoute.POST("/quota/update", controller.ReceiveQuotaUpdate)
  392. syncRoute.POST("/quota/query", controller.QueryUserQuota)
  393. syncRoute.POST("/quota/batch-query", controller.BatchQueryUserQuota)
  394. syncRoute.POST("/quota/batch-deduct", controller.BatchDeductQuota)
  395. syncRoute.GET("/config", controller.GetSyncConfig)
  396. }
  397. }
  398. }