diff --git a/controller/channel.go b/controller/channel.go index a31e1f47..a4ef87c3 100644 --- a/controller/channel.go +++ b/controller/channel.go @@ -623,3 +623,44 @@ func BatchSetChannelTag(c *gin.Context) { }) 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 +} diff --git a/router/api-router.go b/router/api-router.go index 1720ff57..6251c8a2 100644 --- a/router/api-router.go +++ b/router/api-router.go @@ -105,6 +105,7 @@ func SetApiRouter(router *gin.Engine) { channelRoute.GET("/fetch_models/:id", controller.FetchUpstreamModels) channelRoute.POST("/fetch_models", controller.FetchModels) channelRoute.POST("/batch/tag", controller.BatchSetChannelTag) + channelRoute.GET("/tag/models", controller.GetTagModels) } tokenRoute := apiRouter.Group("/token") tokenRoute.Use(middleware.UserAuth()) diff --git a/web/src/pages/Channel/EditTagModal.js b/web/src/pages/Channel/EditTagModal.js index 52dd4bbb..695ed2b4 100644 --- a/web/src/pages/Channel/EditTagModal.js +++ b/web/src/pages/Channel/EditTagModal.js @@ -194,6 +194,24 @@ const EditTagModal = (props) => { }, [originModelOptions, inputs.models]); useEffect(() => { + const fetchTagModels = async () => { + if (!tag) return; + setLoading(true); + try { + const res = await API.get(`/api/channel/tag/models?tag=${tag}`); + if (res?.data?.success) { + const models = res.data.data ? res.data.data.split(',') : []; + setInputs((inputs) => ({ ...inputs, models: models })); + } else { + showError(res.data.message); + } + } catch (error) { + showError(error.message); + } finally { + setLoading(false); + } + }; + setInputs({ ...originInputs, tag: tag, @@ -201,7 +219,8 @@ const EditTagModal = (props) => { }); fetchModels().then(); fetchGroups().then(); - }, [visible]); + fetchTagModels().then(); // Call the new function + }, [visible, tag]); // Add tag to dependency array const addCustomModels = () => { if (customModel.trim() === '') return; @@ -347,6 +366,11 @@ const EditTagModal = (props) => {