claude-opencode-viewer 2.6.4 → 2.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cov.js +32 -9
- package/index-pc.html +2207 -0
- package/package.json +1 -1
- package/server.js +38 -8
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createServer } from 'node:http';
|
|
3
|
-
import {
|
|
3
|
+
import { createServer as createHttpsServer } from 'node:https';
|
|
4
|
+
import { existsSync, createReadStream, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
4
5
|
import { join, dirname } from 'node:path';
|
|
5
6
|
import { fileURLToPath } from 'node:url';
|
|
6
7
|
import { networkInterfaces, platform, arch, homedir } from 'node:os';
|
|
@@ -14,7 +15,29 @@ import Database from 'better-sqlite3';
|
|
|
14
15
|
process.title = 'claude-opencode-viewer';
|
|
15
16
|
|
|
16
17
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
17
|
-
const PORT = 7008;
|
|
18
|
+
const PORT = parseInt(process.argv[2]) || 7008;
|
|
19
|
+
const IS_PC = process.argv.includes('--pc');
|
|
20
|
+
const USE_HTTPS = process.argv.includes('--https');
|
|
21
|
+
|
|
22
|
+
// 自签名证书生成
|
|
23
|
+
function getOrCreateCert() {
|
|
24
|
+
const certDir = join(homedir(), '.cov-certs');
|
|
25
|
+
const keyPath = join(certDir, 'key.pem');
|
|
26
|
+
const certPath = join(certDir, 'cert.pem');
|
|
27
|
+
|
|
28
|
+
if (existsSync(keyPath) && existsSync(certPath)) {
|
|
29
|
+
return { key: readFileSync(keyPath), cert: readFileSync(certPath) };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
console.log('🔐 首次使用 HTTPS,生成自签名证书...');
|
|
33
|
+
mkdirSync(certDir, { recursive: true });
|
|
34
|
+
execSync(
|
|
35
|
+
`openssl req -x509 -newkey rsa:2048 -keyout "${keyPath}" -out "${certPath}" -days 365 -nodes -subj "/CN=cov-self-signed"`,
|
|
36
|
+
{ stdio: 'pipe' }
|
|
37
|
+
);
|
|
38
|
+
console.log(`📁 证书已保存到 ${certDir}`);
|
|
39
|
+
return { key: readFileSync(keyPath), cert: readFileSync(certPath) };
|
|
40
|
+
}
|
|
18
41
|
|
|
19
42
|
// OpenCode 数据库路径(支持环境变量覆盖,自动检测 /halo 环境)
|
|
20
43
|
const OPENCODE_DB_PATH = process.env.OPENCODE_DB_PATH || join(
|
|
@@ -22,7 +45,7 @@ const OPENCODE_DB_PATH = process.env.OPENCODE_DB_PATH || join(
|
|
|
22
45
|
'opencode/opencode.db'
|
|
23
46
|
);
|
|
24
47
|
|
|
25
|
-
const MAX_BUFFER =
|
|
48
|
+
const MAX_BUFFER = 1024 * 1024; // 1MB
|
|
26
49
|
const execFileAsync = promisify(execFile);
|
|
27
50
|
|
|
28
51
|
let ptyModule = null;
|
|
@@ -406,13 +429,14 @@ function getSessionMessages(sessionId) {
|
|
|
406
429
|
}
|
|
407
430
|
}
|
|
408
431
|
|
|
409
|
-
const
|
|
432
|
+
const requestHandler = async (req, res) => {
|
|
410
433
|
if (req.url === '/' || req.url === '/index.html') {
|
|
411
434
|
res.writeHead(200, {
|
|
412
435
|
'Content-Type': 'text/html; charset=utf-8',
|
|
413
436
|
'Access-Control-Allow-Origin': '*',
|
|
437
|
+
'Cache-Control': 'no-cache, no-store, must-revalidate',
|
|
414
438
|
});
|
|
415
|
-
createReadStream(join(__dirname, 'index.html')).pipe(res);
|
|
439
|
+
createReadStream(join(__dirname, IS_PC ? 'index-pc.html' : 'index.html')).pipe(res);
|
|
416
440
|
return;
|
|
417
441
|
}
|
|
418
442
|
|
|
@@ -555,7 +579,11 @@ const server = createServer(async (req, res) => {
|
|
|
555
579
|
|
|
556
580
|
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
|
557
581
|
res.end('Not Found');
|
|
558
|
-
}
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
const server = USE_HTTPS
|
|
585
|
+
? createHttpsServer(getOrCreateCert(), requestHandler)
|
|
586
|
+
: createServer(requestHandler);
|
|
559
587
|
|
|
560
588
|
const wss = new WebSocketServer({ server, path: '/ws' });
|
|
561
589
|
|
|
@@ -738,11 +766,13 @@ wss.on('connection', (ws, req) => {
|
|
|
738
766
|
|
|
739
767
|
server.listen(PORT, '0.0.0.0', async () => {
|
|
740
768
|
const ip = getLocalIp();
|
|
769
|
+
const proto = USE_HTTPS ? 'https' : 'http';
|
|
741
770
|
console.log('\n' + '='.repeat(50));
|
|
742
771
|
console.log('✅ Claude OpenCode Viewer 已启动');
|
|
743
772
|
console.log('='.repeat(50));
|
|
744
|
-
console.log(`🖥️
|
|
745
|
-
console.log(`📱
|
|
773
|
+
console.log(`🖥️ 本地访问:${proto}://127.0.0.1:${PORT}`);
|
|
774
|
+
console.log(`📱 手机访问:${proto}://${ip}:${PORT}`);
|
|
775
|
+
if (USE_HTTPS) console.log('🔐 HTTPS 模式(首次访问需信任自签名证书)');
|
|
746
776
|
console.log('='.repeat(50));
|
|
747
777
|
console.log('\n按 Ctrl+C 停止服务\n');
|
|
748
778
|
|