Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

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