MCPcopy Index your code
hub / github.com/53AI/53AIHub / GetMaxKBApplicationProfile

Function GetMaxKBApplicationProfile

api/controller/maxkb.go:57–126  ·  view source on GitHub ↗

@Summary Get MaxKB application profile @Description 代理MaxKB应用配置查询接口 @Tags MaxKB @Accept json @Produce json @Security BearerAuth @Param bot-id query string true "Bot ID, format: bot-application-{token}" example:"bot-application-ddac703d701b5cf6dcb9fc4bcc365db7" @Success 200 {object} MaxKBProfileRespo

(c *gin.Context)

Source from the content-addressed store, hash-verified

55// @Success 200 {object} MaxKBProfileResponse
56// @Router /api/maxkb/application/profile [get]
57func GetMaxKBApplicationProfile(c *gin.Context) {
58 // 1. 解析bot-id参数
59 botID := c.Query("bot-id")
60 if botID == "" {
61 logger.SysErrorf("MaxKB请求失败: bot-id参数为空")
62 c.JSON(http.StatusBadRequest, model.ParamError.ToNewErrorResponse("bot-id parameter is required"))
63 return
64 }
65
66 logger.SysLogf("MaxKB请求 - bot-id: %s", botID)
67
68 // // 2. 验证bot-id格式并提取application token
69 // applicationToken, err := extractApplicationToken(botID)
70 // if err != nil {
71 // logger.SysErrorf("❌ bot-id格式错误: %v", err)
72 // c.JSON(http.StatusBadRequest, model.ParamError.ToErrorResponse(err))
73 // return
74 // }
75
76 // logger.SysLogf("🔑 提取到application token: %s", applicationToken)
77
78 // 2. 查询包含指定botID的MaxKB渠道
79 eid := config.GetEID(c)
80 channel, err := findMaxKBChannelByBotID(eid, botID)
81 if err != nil {
82 logger.SysErrorf("MaxKB渠道查询失败 - eid: %d, bot-id: %s, error: %v", eid, botID, err)
83 c.JSON(http.StatusNotFound, model.NotFound.ToErrorResponse(err))
84 return
85 }
86
87 // 3. 构建代理请求
88 fullBaseURL := channel.GetBaseURL()
89 if fullBaseURL == "" {
90 logger.SysErrorf("MaxKB渠道BaseURL为空")
91 c.JSON(http.StatusInternalServerError, model.SystemError.ToNewErrorResponse("channel base URL is empty"))
92 return
93 }
94
95 // 提取基础URL (只保留 scheme://host:port 部分)
96 baseURL, err := extractBaseURL(fullBaseURL)
97 if err != nil {
98 logger.SysErrorf("MaxKB BaseURL解析失败: %v", err)
99 c.JSON(http.StatusInternalServerError, model.SystemError.ToErrorResponse(err))
100 return
101 }
102
103 // 4. 发起代理请求
104 proxyURL := fmt.Sprintf("%s/api/application/profile", baseURL)
105 logger.SysLogf("MaxKB代理请求 - URL: %s", proxyURL)
106
107 response, err := makeMaxKBRequest(proxyURL, channel.Key)
108 if err != nil {
109 logger.SysErrorf("MaxKB代理请求失败: %v", err)
110 c.JSON(http.StatusInternalServerError, model.NetworkError.ToErrorResponse(err))
111 return
112 }
113
114 // 5. 解析响应并返回结果

Callers

nothing calls this directly

Calls 9

findMaxKBChannelByBotIDFunction · 0.85
extractBaseURLFunction · 0.85
makeMaxKBRequestFunction · 0.85
ToNewErrorResponseMethod · 0.80
GetEIDMethod · 0.80
ToErrorResponseMethod · 0.80
ToResponseMethod · 0.80
QueryMethod · 0.65
GetBaseURLMethod · 0.45

Tested by

no test coverage detected