protocol-proxy 1.0.2 → 1.0.4
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/package.json +1 -1
- package/public/app.js +12 -2
- package/server.js +25 -4
package/package.json
CHANGED
package/public/app.js
CHANGED
|
@@ -444,8 +444,18 @@ async function deleteProxy(id) {
|
|
|
444
444
|
}
|
|
445
445
|
}
|
|
446
446
|
|
|
447
|
-
function editProxy(id) {
|
|
448
|
-
|
|
447
|
+
async function editProxy(id) {
|
|
448
|
+
try {
|
|
449
|
+
const res = await fetch(`/api/proxies/${id}`);
|
|
450
|
+
if (!res.ok) throw new Error('加载失败');
|
|
451
|
+
const full = await res.json();
|
|
452
|
+
// 用完整数据替换列表中的掩码数据
|
|
453
|
+
const idx = proxies.findIndex(p => p.id === id);
|
|
454
|
+
if (idx !== -1) proxies[idx] = { ...proxies[idx], ...full };
|
|
455
|
+
openModal(id);
|
|
456
|
+
} catch (err) {
|
|
457
|
+
showToast('加载代理配置失败: ' + err.message, true);
|
|
458
|
+
}
|
|
449
459
|
}
|
|
450
460
|
|
|
451
461
|
// ==================== 工具函数 ====================
|
package/server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
const path = require('path');
|
|
3
|
-
const { exec } = require('child_process');
|
|
3
|
+
const { exec, spawn } = require('child_process');
|
|
4
4
|
const os = require('os');
|
|
5
5
|
const fs = require('fs');
|
|
6
6
|
|
|
@@ -30,9 +30,9 @@ function showHelp() {
|
|
|
30
30
|
protocol-proxy - OpenAI / Anthropic 协议转换透明代理
|
|
31
31
|
|
|
32
32
|
用法:
|
|
33
|
-
protocol-proxy
|
|
34
|
-
protocol-proxy start
|
|
35
|
-
protocol-proxy stop
|
|
33
|
+
protocol-proxy 前台启动服务(Ctrl+C 停止)
|
|
34
|
+
protocol-proxy start 后台启动服务
|
|
35
|
+
protocol-proxy stop 停止后台服务
|
|
36
36
|
protocol-proxy status 查看运行状态
|
|
37
37
|
protocol-proxy help 显示帮助信息
|
|
38
38
|
protocol-proxy -v, --version 显示版本号
|
|
@@ -40,6 +40,22 @@ protocol-proxy - OpenAI / Anthropic 协议转换透明代理
|
|
|
40
40
|
`);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
function startDaemon() {
|
|
44
|
+
const pid = readPid();
|
|
45
|
+
if (pid && isProcessAlive(pid)) {
|
|
46
|
+
console.log(`服务已在运行 (PID: ${pid})`);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const child = spawn(process.execPath, [__filename, '--daemon'], {
|
|
51
|
+
detached: true,
|
|
52
|
+
stdio: 'ignore',
|
|
53
|
+
});
|
|
54
|
+
fs.writeFileSync(PID_FILE, String(child.pid));
|
|
55
|
+
child.unref();
|
|
56
|
+
console.log(`服务已在后台启动 (PID: ${child.pid})`);
|
|
57
|
+
}
|
|
58
|
+
|
|
43
59
|
function showVersion() {
|
|
44
60
|
console.log(pkg.version);
|
|
45
61
|
}
|
|
@@ -323,6 +339,11 @@ switch (cmd) {
|
|
|
323
339
|
showStatus();
|
|
324
340
|
break;
|
|
325
341
|
case 'start':
|
|
342
|
+
startDaemon();
|
|
343
|
+
break;
|
|
344
|
+
case '--daemon':
|
|
345
|
+
init();
|
|
346
|
+
break;
|
|
326
347
|
case undefined:
|
|
327
348
|
init();
|
|
328
349
|
break;
|