From 2d865eb73559121a49c39aa15497373e641c8e0a Mon Sep 17 00:00:00 2001 From: CalciumIon <1808837298@qq.com> Date: Tue, 17 Dec 2024 15:33:16 +0800 Subject: [PATCH] refactor: Improve channel status update logic and clean up code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Simplified conditional checks in UpdateChannelStatusById function in channel.go to enhance readability. - Commented out unused image number check in relay-gemini.go for clarity. - Updated JSON field in en.json for currency consistency, changing "元" from "RMB/CNY" to "CNY" and added a space in "实付金额:" for formatting. --- model/channel.go | 17 +++++++++-------- relay/channel/gemini/relay-gemini.go | 6 +++--- web/src/i18n/locales/en.json | 4 ++-- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/model/channel.go b/model/channel.go index 236b1dd4..6be16fd2 100644 --- a/model/channel.go +++ b/model/channel.go @@ -292,19 +292,20 @@ func (channel *Channel) Delete() error { } var channelStatusLock sync.Mutex + func UpdateChannelStatusById(id int, status int, reason string) { - if (common.MemoryCacheEnabled) { + if common.MemoryCacheEnabled { channelStatusLock.Lock() - channelCache, err := CacheGetChannel(id) - // 如果缓存渠道存在,且状态已是目标状态,直接返回 - if channelCache != nil && channelCache.Status == status { + channelCache, _ := CacheGetChannel(id) + // 如果缓存渠道存在,且状态已是目标状态,直接返回 + if channelCache != nil && channelCache.Status == status { channelStatusLock.Unlock() - return + return } - // 如果缓存渠道不存在(说明已经被禁用),且要设置的状态不为启用,直接返回 - if channelCache == nil && status != common.ChannelStatusEnabled { + // 如果缓存渠道不存在(说明已经被禁用),且要设置的状态不为启用,直接返回 + if channelCache == nil && status != common.ChannelStatusEnabled { channelStatusLock.Unlock() - return + return } CacheUpdateChannelStatus(id, status) channelStatusLock.Unlock() diff --git a/relay/channel/gemini/relay-gemini.go b/relay/channel/gemini/relay-gemini.go index 5726508b..a19e5e69 100644 --- a/relay/channel/gemini/relay-gemini.go +++ b/relay/channel/gemini/relay-gemini.go @@ -103,9 +103,9 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest) *GeminiChatReques }) } else if part.Type == dto.ContentTypeImageURL { imageNum += 1 - if imageNum > GeminiVisionMaxImageNum { - continue - } + //if imageNum > GeminiVisionMaxImageNum { + // continue + //} // 判断是否是url if strings.HasPrefix(part.ImageUrl.(dto.MessageImageUrl).Url, "http") { // 是url,获取图片的类型和base64编码的数据 diff --git a/web/src/i18n/locales/en.json b/web/src/i18n/locales/en.json index 7aac2b5d..2282c2a2 100644 --- a/web/src/i18n/locales/en.json +++ b/web/src/i18n/locales/en.json @@ -797,7 +797,7 @@ "管理员未开启Stripe在线充值!": "The administrator has not enabled Stripe online recharge!", "当前充值1美金=": "Current recharge = 1 USD =", "请选择充值方式!": "Please choose a recharge method!", - "元": "RMB/CNY", + "元": "CNY", "充值记录": "Recharge record", "返利记录": "Rebate record", "确定要充值 $": "Confirm to top up $", @@ -963,7 +963,7 @@ "请输入星火大模型版本,注意是接口地址中的版本号,例如:v2[1]": "Please enter the Spark model version, note that it is the version number in the interface address, for example: v2.1", "等待中": "Waiting", "所有各厂聊天模型请统一使用OpenAI方式请求,支持OpenAI官方库": "Please use the OpenAI method to request all chat models from each factory, and support the OpenAI official library.", - "实付金额:": "Actual payment amount:", + "实付金额:": "Actual payment amount: ", "金额": "Amount", "充值金额": "Recharge amount", "易支付 实付金额:": "Easy Pay Actual payment amount:",