From d90c0d9b8b5acf38a83f88f49171c81d9e2906c9 Mon Sep 17 00:00:00 2001 From: vacuity Date: Tue, 22 Aug 2023 15:58:58 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=9C=8D=E5=8A=A1=E5=99=A8):=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=A4=9A=E6=9C=8D=E5=8A=A1=E5=99=A8=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ info.json | 18 +++++++++++++++++- main.js | 30 +++++++++++++++++++++++++++--- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5e80e21..7f38e1b 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,8 @@ 5. 填写注册邮箱和密码 +注:服务器可以选择香港,如香港无法访问可选择美国 + ## 获取注册邮箱和密码 1. 访问 [此网站](https://chat.vacuity.me/),注册账号; diff --git a/info.json b/info.json index a65b2ce..8913309 100644 --- a/info.json +++ b/info.json @@ -1,6 +1,6 @@ { "identifier": "me.vacuity.chat.gptranslate", - "version": "0.1.0", + "version": "0.1.1", "category": "translate", "name": "GPTranslate", "summary": "调用chatgpt实现翻译功能", @@ -20,6 +20,22 @@ "type": "text", "title": "登录密码" }, + { + "identifier": "serverArea", + "type": "menu", + "title": "服务器选择", + "defaultValue": "hk", + "menuValues": [ + { + "title": "香港", + "value": "hk" + }, + { + "title": "美国", + "value": "usa" + } + ] + }, { "identifier": "useStreamFlag", "type": "menu", diff --git a/main.js b/main.js index 1dc9875..80448e9 100644 --- a/main.js +++ b/main.js @@ -33,6 +33,13 @@ var langMap = { 'ar': '阿拉伯语' }; +var hkHttp = "https://chat2.vacuity.me/vac-chat-api/chat/ext/loginTranslate"; +var hkStream = "https://chat2.vacuity.me/vac-chat-api/chat/ext/loginStreamTranslate"; +var hkWss = "wss://chat2.vacuity.me/vac-chat-api/stream/chat/chat"; +var usaHttp = "https://chat.vacuity.me/vac-chat-api/chat/ext/loginTranslate"; +var usaStream = "https://chat.vacuity.me/vac-chat-api/chat/ext/loginStreamTranslate"; +var usaWss = "wss://chat.vacuity.me/vac-chat-api/stream/chat/chat"; + var socket = ''; var readyState = false; var connectIng = true; @@ -72,9 +79,14 @@ function translate(query, completion) { function oldTranslate(query, completion) { + var area = $option.serverArea; + vacUrl = hkHttp; + if (area === 'usa') { + vacUrl = usaHttp; + } $http.request({ method: "POST", - url: "https://chat.vacuity.me/vac-chat-api/chat/ext/loginTranslate", + url: vacUrl, header: { "Content-Type": "application/json;charset=UTF-8" }, @@ -105,10 +117,15 @@ function oldTranslate(query, completion) { function newTrans(query, completion) { + var area = $option.serverArea; + vacUrl = hkStream; + if (area === 'usa') { + vacUrl = usaStream; + } resTxt = ''; $http.streamRequest({ method: "POST", - url: "https://chat.vacuity.me/vac-chat-api/chat/ext/loginStreamTranslate", + url: vacUrl, header: { "Content-Type": "application/json;charset=UTF-8" }, @@ -139,10 +156,17 @@ var timerId = 0; var signal = $signal.new() function initWebsocket() { + + var area = $option.serverArea; + vacUrl = hkWss; + if (area === 'usa') { + vacUrl = usaWss; + } + if (websocket == null) { $log.info(`initWebsocket`) websocket = $websocket.new({ - url: "wss://chat.vacuity.me/vac-chat-api/stream/chat/chat", + url: vacUrl, allowSelfSignedSSLCertificates: true, timeoutInterval: 100, header: {