From a868a8a8b731c616189152c3ca165769deb6d3ad Mon Sep 17 00:00:00 2001 From: RockYang Date: Thu, 6 Jul 2023 10:34:01 +0800 Subject: [PATCH] opt: add tip message when no available key --- api/go/handler/chat_handler.go | 6 +++++- web/src/components/SendMsg.vue | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/api/go/handler/chat_handler.go b/api/go/handler/chat_handler.go index e18bdefa..88e48080 100644 --- a/api/go/handler/chat_handler.go +++ b/api/go/handler/chat_handler.go @@ -197,6 +197,10 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session types.ChatSession if strings.Contains(err.Error(), "context canceled") { logger.Info("用户取消了请求:", prompt) return nil + } else if strings.Contains(err.Error(), "no available key") { + replyMessage(ws, "抱歉😔😔😔,系统已经没有可用的 API KEY🔑,您可以导入自己的 API KEY🔑 继续使用!🙏🙏🙏") + replyMessage(ws, "![](/images/wx.png)") + return nil } else { logger.Error(err) } @@ -414,7 +418,7 @@ func (h *ChatHandler) doRequest(ctx context.Context, user vo.User, apiKey *strin var key model.ApiKey res := h.db.Where("user_id = ?", 0).Order("last_used_at ASC").First(&key) if res.Error != nil { - return nil, errors.New("no available key, please import key") + return nil, errors.New("no available key") } *apiKey = key.Value // 更新 API KEY 的最后使用时间 diff --git a/web/src/components/SendMsg.vue b/web/src/components/SendMsg.vue index bc0af64d..7abb5b8b 100644 --- a/web/src/components/SendMsg.vue +++ b/web/src/components/SendMsg.vue @@ -31,7 +31,7 @@ const sendMsg = () => { httpGet('/api/verify/token').then(res => { httpPost('/api/verify/sms', {token: res.data, mobile: props.mobile}).then(() => { ElMessage.success('短信发送成功') - let time = 10 + let time = 120 btnText.value = time const handler = setInterval(() => { time = time - 1