Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

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