🎨 feat(channel): add endpoint to retrieve models by tag
This commit is contained in:
@@ -623,3 +623,44 @@ func BatchSetChannelTag(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetTagModels(c *gin.Context) {
|
||||||
|
tag := c.Query("tag")
|
||||||
|
if tag == "" {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "tag不能为空",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
channels, err := model.GetChannelsByTag(tag, false) // Assuming false for idSort is fine here
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var longestModels string
|
||||||
|
maxLength := 0
|
||||||
|
|
||||||
|
// Find the longest models string among all channels with the given tag
|
||||||
|
for _, channel := range channels {
|
||||||
|
if channel.Models != "" {
|
||||||
|
currentModels := strings.Split(channel.Models, ",")
|
||||||
|
if len(currentModels) > maxLength {
|
||||||
|
maxLength = len(currentModels)
|
||||||
|
longestModels = channel.Models
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": true,
|
||||||
|
"message": "",
|
||||||
|
"data": longestModels,
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ func SetApiRouter(router *gin.Engine) {
|
|||||||
channelRoute.GET("/fetch_models/:id", controller.FetchUpstreamModels)
|
channelRoute.GET("/fetch_models/:id", controller.FetchUpstreamModels)
|
||||||
channelRoute.POST("/fetch_models", controller.FetchModels)
|
channelRoute.POST("/fetch_models", controller.FetchModels)
|
||||||
channelRoute.POST("/batch/tag", controller.BatchSetChannelTag)
|
channelRoute.POST("/batch/tag", controller.BatchSetChannelTag)
|
||||||
|
channelRoute.GET("/tag/models", controller.GetTagModels)
|
||||||
}
|
}
|
||||||
tokenRoute := apiRouter.Group("/token")
|
tokenRoute := apiRouter.Group("/token")
|
||||||
tokenRoute.Use(middleware.UserAuth())
|
tokenRoute.Use(middleware.UserAuth())
|
||||||
|
|||||||
Reference in New Issue
Block a user