Skip to content

Commit f877b2a

Browse files
feat: ⚡ 未登录用户更快创建会话
1 parent 2f0915f commit f877b2a

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

common/proxy.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ var (
3838
"https://cn.bing.com",
3939
"https://www.bing.com",
4040
}
41-
RAND_IP_COOKIE_NAME = "BingAI_Rand_IP"
41+
USER_TOKEN_COOKIE_NAME = "_U"
42+
RAND_IP_COOKIE_NAME = "BingAI_Rand_IP"
4243
)
4344

4445
func NewSingleHostReverseProxy(target *url.URL) *httputil.ReverseProxy {
@@ -77,6 +78,15 @@ func NewSingleHostReverseProxy(target *url.URL) *httputil.ReverseProxy {
7778
}
7879
req.Header.Set("X-Forwarded-For", randIP)
7980

81+
// 未登录用户,ua 包含 iPhone Mobile 居然秒创建会话id,应该搞了手机优先策略, Android 不行
82+
ckUserToken, _ := req.Cookie(USER_TOKEN_COOKIE_NAME)
83+
if ckUserToken == nil || ckUserToken.Value == "" {
84+
ua := req.UserAgent()
85+
if !strings.Contains(ua, "iPhone") && !strings.Contains(ua, "Mobile") {
86+
req.Header.Set("User-Agent", "iPhone Mobile "+ua)
87+
}
88+
}
89+
8090
for hKey, _ := range req.Header {
8191
if _, isExist := KEEP_HEADERS[hKey]; !isExist {
8292
req.Header.Del(hKey)

web/js/index.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ async function registerSW() {
108108
const newSWVersion = await wb.messageSW({ type: 'GET_VERSION' });
109109
if (newSWVersion !== oldSWVersion) {
110110
alert(`新版本 ${newSWVersion} 已就绪,刷新后即可体验 !`);
111-
window.location.reload();
111+
window.location.reload(true);
112112
}
113113
});
114114

@@ -140,13 +140,9 @@ async function tryCreateConversationId(trycount = 0) {
140140
}
141141
const conversationRes = await fetch('/turing/conversation/create', {
142142
credentials: 'include',
143-
}).then(async (res) => {
144-
if (res.status === 200 && res.body && !res.body.locked) {
145-
return await res.json();
146-
} else {
147-
return 'error';
148-
}
149-
});
143+
})
144+
.then((res) => res.json())
145+
.catch((err) => `error`);
150146
if (conversationRes?.result?.value === 'Success') {
151147
console.log('成功创建会话ID : ', conversationRes.conversationId);
152148
CIB.manager.conversation.updateId(conversationRes.conversationId, getConversationExpiry(), conversationRes.clientId, conversationRes.conversationSignature);

web/sw.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// 引入workbox 框架
22
importScripts('./js/sw/workbox-sw.js');
33

4-
const SW_VERSION = 'v1.3.4';
4+
const SW_VERSION = 'v1.3.5';
55
const CACHE_PREFIX = 'BingAI';
66

77
workbox.setConfig({ debug: false, logLevel: 'warn' });
@@ -56,12 +56,12 @@ workbox.precaching.precacheAndRoute([
5656
},
5757
{
5858
url: '/web/js/index.js',
59-
revision: '2023.05.06.15.30',
59+
revision: '2023.05.06.17',
6060
},
6161
// html
6262
{
6363
url: '/web/chat.html',
64-
revision: '2023.05.06.14',
64+
revision: '2023.05.06.16',
6565
},
6666
// ico
6767
{

0 commit comments

Comments
 (0)