Skip to content

Commit

Permalink
feat(服务器): 增加多服务器选项
Browse files Browse the repository at this point in the history
  • Loading branch information
vacuityv committed Aug 22, 2023
1 parent 02699a2 commit d90c0d9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

5. 填写注册邮箱和密码

注:服务器可以选择香港,如香港无法访问可选择美国

## 获取注册邮箱和密码

1. 访问 [此网站](https://chat.vacuity.me/),注册账号;
Expand Down
18 changes: 17 additions & 1 deletion info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"identifier": "me.vacuity.chat.gptranslate",
"version": "0.1.0",
"version": "0.1.1",
"category": "translate",
"name": "GPTranslate",
"summary": "调用chatgpt实现翻译功能",
Expand All @@ -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",
Expand Down
30 changes: 27 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"
},
Expand Down Expand Up @@ -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"
},
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit d90c0d9

Please sign in to comment.