From b7c742166a728c4c82d6df1f78ac1e054ad90be5 Mon Sep 17 00:00:00 2001 From: RedwindA Date: Sun, 8 Jun 2025 01:16:27 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=8E=A8=20feat(channel):=20add=20endpo?= =?UTF-8?q?int=20to=20retrieve=20models=20by=20tag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/channel.go | 41 +++++++++++++++++++++++++++++++++++++++++ router/api-router.go | 1 + 2 files changed, 42 insertions(+) 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()) From 49898928309ef72d5f2cbbb7c7c6a153b69904c8 Mon Sep 17 00:00:00 2001 From: RedwindA Date: Sun, 8 Jun 2025 01:16:39 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=90=9B=20fix(EditTagModal):=20add=20f?= =?UTF-8?q?etchTagModels=20function=20to=20retrieve=20models=20based=20on?= =?UTF-8?q?=20tag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/pages/Channel/EditTagModal.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/web/src/pages/Channel/EditTagModal.js b/web/src/pages/Channel/EditTagModal.js index 52dd4bbb..1b370297 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; From b47274bfadc637722f473bdfa217a30656406b23 Mon Sep 17 00:00:00 2001 From: RedwindA Date: Sun, 8 Jun 2025 13:23:59 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=90=9B=20fix(EditTagModal):=20add=20i?= =?UTF-8?q?nfo=20banner=20to=20clarify=20modelList=20behavior?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/pages/Channel/EditTagModal.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/web/src/pages/Channel/EditTagModal.js b/web/src/pages/Channel/EditTagModal.js index 1b370297..695ed2b4 100644 --- a/web/src/pages/Channel/EditTagModal.js +++ b/web/src/pages/Channel/EditTagModal.js @@ -366,6 +366,11 @@ const EditTagModal = (props) => {
{t('模型')} +