You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

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