Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

Commit 2b3644f

Browse files
authored
fix: 🐛 npm 包访问登陆网页空白 (#272)
2 parents bb60c93 + 33d4697 commit 2b3644f

File tree

5 files changed

+49
-30
lines changed

5 files changed

+49
-30
lines changed

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wechatbot-webhook",
3-
"version": "2.8.1-beta.2",
3+
"version": "2.8.1",
44
"description": "给微信里加个 webhook 机器人,支持docker部署",
55
"keywords": [
66
"wechat",

packages/cli/scripts/build.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,37 @@ fs.copyFileSync(
88
)
99

1010
function copyDirSync(src, dest) {
11-
fs.mkdirSync(dest, { recursive: true });
12-
fs.readdirSync(src).forEach(file => {
13-
const srcPath = path.join(src, file);
14-
const destPath = path.join(dest, file);
15-
if (fs.lstatSync(srcPath).isDirectory()) {
16-
copyDirSync(srcPath, destPath);
17-
} else {
18-
fs.copyFileSync(srcPath, destPath);
11+
if (!src) {
12+
throw new Error('src is null or undefined');
13+
}
14+
15+
try {
16+
// 如果目标目录存在,先清空它
17+
if (fs.existsSync(dest)) {
18+
fs.rmSync(dest, { recursive: true, force: true });
1919
}
20-
});
20+
21+
// 创建新的目标目录
22+
fs.mkdirSync(dest, { recursive: true });
23+
24+
// 复制文件
25+
fs.readdirSync(src).forEach(file => {
26+
const srcPath = path.join(src, file);
27+
const destPath = path.join(dest, file);
28+
if (fs.lstatSync(srcPath).isDirectory()) {
29+
copyDirSync(srcPath, destPath);
30+
} else {
31+
fs.copyFileSync(srcPath, destPath);
32+
}
33+
});
34+
} catch (err) {
35+
console.error(err);
36+
throw err;
37+
}
2138
}
2239

2340
copyDirSync(
24-
path.join(__dirname, '../../../static'),
41+
path.join(__dirname, '../../../src/static'),
2542
path.join(__dirname, '../static')
2643
)
2744

src/route/index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const Middleware = require('../middleware/index')
2-
const { serveStatic } = require('@hono/node-server/serve-static')
2+
const fs = require('fs')
3+
const path = require('path')
34
/**
45
* 注册路由
56
* @param {Object} param
@@ -19,7 +20,15 @@ module.exports = function registerRoute({ app, bot }) {
1920
app.use('*', attachData)
2021
// 全局鉴权
2122
app.use(Middleware.verifyToken)
22-
app.get('/static/*', serveStatic({ root: './' }))
23+
24+
// bugfix serveStatic cannot use a project root path, it actually based on cwd path
25+
app.get('/static/*', async (c) => {
26+
//获取*号的路径
27+
const filePath = path.join(__dirname, `../${c.req.path}`)
28+
return c.body(fs.readFileSync(filePath, {
29+
encoding: 'utf-8'
30+
}))
31+
})
2332

2433
require('./msg')({ app, bot })
2534
require('./login')({ app, bot })

src/route/login.js

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { streamSSE } = require('hono/streaming');
1+
const { streamSSE } = require('hono/streaming')
22

33
/**
44
* 注册login路由和处理上报逻辑
@@ -72,7 +72,8 @@ module.exports = function registerLoginCheck({ app, bot }) {
7272
})
7373
7474
eventSource.addEventListener ("login", (event) => {
75-
window.location.reload()
75+
eventSource.close()
76+
window.location.reload()
7677
})
7778
</script>
7879
</body>
@@ -83,23 +84,15 @@ module.exports = function registerLoginCheck({ app, bot }) {
8384
}
8485
)
8586

86-
let id = 0
8787
app.get('/sse', async (c) => {
88-
const { readable, writable } = new TransformStream();
89-
90-
id++
91-
9288
return streamSSE(c, async (stream) => {
93-
94-
95-
// c.bot.on('scan', async (qrcode) => {
96-
// console.log({qrcode})
97-
// })
98-
99-
await stream.writeSSE({
100-
event: !success ? 'qrcode' : 'login',
101-
data: message
102-
})
89+
while (true) {
90+
await stream.writeSSE({
91+
event: !success ? 'qrcode' : 'login',
92+
data: message
93+
})
94+
await stream.sleep(1000)
95+
}
10396
})
10497
})
10598

0 commit comments

Comments
 (0)