Skip to content

Commit

Permalink
feat: ⚡ 未登录用户更快创建会话
Browse files Browse the repository at this point in the history
  • Loading branch information
adams549659584 committed May 6, 2023
1 parent 2f0915f commit f877b2a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
12 changes: 11 additions & 1 deletion common/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ var (
"https://cn.bing.com",
"https://www.bing.com",
}
RAND_IP_COOKIE_NAME = "BingAI_Rand_IP"
USER_TOKEN_COOKIE_NAME = "_U"
RAND_IP_COOKIE_NAME = "BingAI_Rand_IP"
)

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

// 未登录用户,ua 包含 iPhone Mobile 居然秒创建会话id,应该搞了手机优先策略, Android 不行
ckUserToken, _ := req.Cookie(USER_TOKEN_COOKIE_NAME)
if ckUserToken == nil || ckUserToken.Value == "" {
ua := req.UserAgent()
if !strings.Contains(ua, "iPhone") && !strings.Contains(ua, "Mobile") {
req.Header.Set("User-Agent", "iPhone Mobile "+ua)
}
}

for hKey, _ := range req.Header {
if _, isExist := KEEP_HEADERS[hKey]; !isExist {
req.Header.Del(hKey)
Expand Down
12 changes: 4 additions & 8 deletions web/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ async function registerSW() {
const newSWVersion = await wb.messageSW({ type: 'GET_VERSION' });
if (newSWVersion !== oldSWVersion) {
alert(`新版本 ${newSWVersion} 已就绪,刷新后即可体验 !`);
window.location.reload();
window.location.reload(true);
}
});

Expand Down Expand Up @@ -140,13 +140,9 @@ async function tryCreateConversationId(trycount = 0) {
}
const conversationRes = await fetch('/turing/conversation/create', {
credentials: 'include',
}).then(async (res) => {
if (res.status === 200 && res.body && !res.body.locked) {
return await res.json();
} else {
return 'error';
}
});
})
.then((res) => res.json())
.catch((err) => `error`);
if (conversationRes?.result?.value === 'Success') {
console.log('成功创建会话ID : ', conversationRes.conversationId);
CIB.manager.conversation.updateId(conversationRes.conversationId, getConversationExpiry(), conversationRes.clientId, conversationRes.conversationSignature);
Expand Down
6 changes: 3 additions & 3 deletions web/sw.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 引入workbox 框架
importScripts('./js/sw/workbox-sw.js');

const SW_VERSION = 'v1.3.4';
const SW_VERSION = 'v1.3.5';
const CACHE_PREFIX = 'BingAI';

workbox.setConfig({ debug: false, logLevel: 'warn' });
Expand Down Expand Up @@ -56,12 +56,12 @@ workbox.precaching.precacheAndRoute([
},
{
url: '/web/js/index.js',
revision: '2023.05.06.15.30',
revision: '2023.05.06.17',
},
// html
{
url: '/web/chat.html',
revision: '2023.05.06.14',
revision: '2023.05.06.16',
},
// ico
{
Expand Down

0 comments on commit f877b2a

Please sign in to comment.