Skip to content

Commit cfc7123

Browse files
feat: ⚡ 完整的聊天功能支持,并无需登录即可畅聊
1 parent 7ced173 commit cfc7123

File tree

10 files changed

+807
-438
lines changed

10 files changed

+807
-438
lines changed

.vscode/launch.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
"request": "launch",
1111
"mode": "auto",
1212
"program": "${workspaceFolder}",
13+
"env": {
14+
"Go-Proxy-BingAI-Debug": "true"
15+
}
1316
}
1417
]
1518
}

api/web.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ import (
66
)
77

88
func WebStatic(w http.ResponseWriter, r *http.Request) {
9-
http.StripPrefix("/web/", http.FileServer(http.FS(web.WebFS))).ServeHTTP(w, r)
9+
http.StripPrefix("/web/", http.FileServer(web.GetWebFS())).ServeHTTP(w, r)
1010
}

common/proxy.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@ func NewSingleHostReverseProxy(target *url.URL) *httputil.ReverseProxy {
100100
log.Println("代理异常 :", err)
101101
res.Write([]byte(err.Error()))
102102
}
103+
104+
// tr := &http.Transport{
105+
// TLSClientConfig: &tls.Config{
106+
// // 如果只设置 InsecureSkipVerify: true对于这个问题不会有任何改变
107+
// InsecureSkipVerify: true,
108+
// ClientAuth: tls.NoClientCert,
109+
// },
110+
// }
111+
103112
// 代理请求 请求回来的内容 报错自动调用
104113
return &httputil.ReverseProxy{Director: director, ModifyResponse: modifyFunc, ErrorHandler: errorHandler}
105114
}

web/chat.html

Lines changed: 96 additions & 49 deletions
Large diffs are not rendered by default.

web/css/index.css

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ html {
2828
overflow-y: scroll
2929
}
3030

31-
.chat-container {
32-
position: fixed;
33-
width: 100vw;
34-
height: 100vh;
35-
z-index: 0;
36-
}
3731

3832
.chat-nav {
3933
position: fixed;
@@ -146,7 +140,14 @@ html {
146140
margin: 0 auto;
147141
}
148142

149-
.chat-login .chat-login-btn-save {
143+
.chat-login-btn-group {
144+
display: flex;
145+
justify-content: center;
146+
align-items: center;
147+
}
148+
149+
.chat-login-btn-group .chat-login-btn-save,
150+
.chat-login-btn-group .chat-login-btn-cancel {
150151
border-image: linear-gradient(81.62deg, #2870ea 8.72%, #1b4aef 85.01%);
151152
background: linear-gradient(81.62deg, #2870ea 8.72%, #1b4aef 85.01%);
152153
border-radius: 1vmin;
@@ -165,6 +166,11 @@ html {
165166
user-select: none;
166167
}
167168

169+
.chat-login-btn-group .chat-login-btn-cancel {
170+
background: #fff;
171+
color: #111;
172+
}
173+
168174
@media screen and (min-width: 750px) {
169175
.chat-login-bg .chat-login {
170176
width: 40vw;
@@ -183,7 +189,8 @@ html {
183189
font-size: 16px;
184190
}
185191

186-
.chat-login .chat-login-btn-save {
192+
.chat-login-btn-group .chat-login-btn-save,
193+
.chat-login-btn-group .chat-login-btn-cancel {
187194
width: 104px;
188195
height: 50px;
189196
line-height: 50px;

web/js/index.js

Lines changed: 166 additions & 350 deletions
Large diffs are not rendered by default.

web/js/sw/workbox-sw.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/js/sydneyfullscreenconv.js

Lines changed: 451 additions & 0 deletions
Large diffs are not rendered by default.

web/sw.js

Lines changed: 50 additions & 27 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 = '1.1.0';
4+
const SW_VERSION = '1.2.0';
55
const CACHE_PREFIX = 'BingAI';
66

77
workbox.setConfig({ debug: false, logLevel: 'warn' });
@@ -19,42 +19,62 @@ workbox.precaching.precacheAndRoute([
1919
// css
2020
{
2121
url: '/web/css/index.css',
22-
revision: '2023.05.03',
22+
revision: '2023.05.05',
2323
},
2424
// js
25-
{
26-
url: '/web/js/index.js',
27-
revision: '2023.05.03',
28-
},
2925
{
3026
url: '/web/js/sw/workbox-sw.js',
31-
revision: '2023.05.03',
27+
revision: '2023.05.05',
3228
},
3329
{
3430
url: '/web/js/sw/workbox-window.prod.umd.min.js',
35-
revision: '2023.05.03',
31+
revision: '2023.05.05',
32+
},
33+
{
34+
url: '/rp/oJ7sDoXkkNOICsnFb57ZJHBrHcw.br.js',
35+
revision: '2023.05.05',
36+
},
37+
{
38+
url: '/rp/q6gG3uKBf5j5T2ZgRG-BbgRzW_I.br.js',
39+
revision: '2023.05.05',
40+
},
41+
{
42+
url: '/rp/YFRe970EMtFzujI9pBYZBGpdHEo.br.js',
43+
revision: '2023.05.05',
3644
},
3745
{
3846
url: '/rp/LOB20GsbD-KR9Gwi_Ukp8-BJZCQ.br.js',
39-
revision: '2023.05.04',
47+
revision: '2023.05.05',
48+
},
49+
{
50+
url: '/rp/6slp3E-BqFf904Cz6cCWPY1bh9E.br.js',
51+
revision: '2023.05.05',
52+
},
53+
{
54+
url: '/web/js/sydneyfullscreenconv.js',
55+
revision: '2023.05.05',
56+
},
57+
{
58+
url: '/web/js/index.js',
59+
revision: '2023.05.05',
4060
},
4161
// html
4262
{
4363
url: '/web/chat.html',
44-
revision: '2023.05.03',
64+
revision: '2023.05.05',
4565
},
4666
// ico
4767
{
4868
url: '/sa/simg/favicon-trans-bg-blue-mg.ico',
49-
revision: '2023.05.03',
69+
revision: '2023.05.05',
5070
},
5171
]);
5272

5373
workbox.precaching.cleanupOutdatedCaches();
5474

5575
// image
5676
workbox.routing.registerRoute(
57-
({ request }) => request.destination === 'image',
77+
({ request }) => request.destination === 'image' && !request.url.includes('/fd/ls/l'),
5878
new workbox.strategies.CacheFirst({
5979
cacheName: `${CACHE_PREFIX}-image`,
6080
plugins: [
@@ -93,7 +113,7 @@ workbox.routing.registerRoute(
93113
);
94114

95115
// service worker通过message和主线程通讯
96-
self.addEventListener('message', event => {
116+
self.addEventListener('message', (event) => {
97117
const replyPort = event.ports[0];
98118
const message = event.data;
99119
// console.log(`sw message : `, message);
@@ -103,18 +123,21 @@ self.addEventListener('message', event => {
103123
});
104124

105125
// 安装阶段可删除旧缓存等等
106-
self.addEventListener('install', async event => {
107-
await caches.open(`${CACHE_PREFIX}-js`).then(async cache => {
108-
const requests = await cache.keys();
109-
return await Promise.all(
110-
requests.map(request => {
111-
if (true || request.url.includes('xxx')) {
112-
console.log(`del old cache : `, request.url);
113-
return cache.delete(request);
114-
} else {
115-
return Promise.resolve();
116-
}
117-
})
118-
);
119-
});
126+
self.addEventListener('install', async (event) => {
127+
const cacheKeys = await caches.keys();
128+
for (const cacheKey of cacheKeys) {
129+
await caches.open(cacheKey).then(async (cache) => {
130+
const requests = await cache.keys();
131+
return await Promise.all(
132+
requests.map((request) => {
133+
if (true || request.url.includes('xxx')) {
134+
console.log(`del cache : `, request.url);
135+
return cache.delete(request);
136+
} else {
137+
return Promise.resolve();
138+
}
139+
})
140+
);
141+
});
142+
}
120143
});

web/web.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
package web
22

3-
import "embed"
3+
import (
4+
"embed"
5+
"net/http"
6+
"os"
7+
)
48

59
//go:embed *
6-
var WebFS embed.FS
10+
var webFS embed.FS
11+
12+
func GetWebFS() http.FileSystem {
13+
debugMode := os.Getenv("Go-Proxy-BingAI-Debug")
14+
if debugMode != "" {
15+
return http.Dir("web")
16+
} else {
17+
return http.FS(webFS)
18+
}
19+
}

0 commit comments

Comments
 (0)