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.
 
 
 

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