ai_co_discuss 0.4.51 → 0.4.52
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/runner/admin_cli.mjs +3 -3
- package/runner/admin_panel.mjs +30 -6
- package/web/admin.css +1 -1
- package/web/admin.js +3 -3
- package/web/modern.js +2 -2
package/package.json
CHANGED
package/runner/admin_cli.mjs
CHANGED
|
@@ -40,11 +40,11 @@ export const HELP = `用法:codiscuss admin <命令> [参数](与管理面
|
|
|
40
40
|
service start|stop|restart 只启停共议服务(网站与讨论服务)
|
|
41
41
|
autostart on|off 登录 Windows 时自动启动
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
登录入口与访问方式(需打开托管管理)
|
|
44
44
|
entry start|stop 启动或停止登录入口
|
|
45
|
-
entry mode local|relay|tunnel
|
|
45
|
+
entry mode local|relay|tunnel 访问方式:仅这台电脑 | 线上中转 | 自有域名
|
|
46
46
|
entry join <接入码> 用接入码接入线上站点并切换到线上中转
|
|
47
|
-
entry connect <站点> <绑定令牌>
|
|
47
|
+
entry connect <站点> <绑定令牌> 只绑定线上站点(管理员远程用),不改访问方式
|
|
48
48
|
runtime sync 同步隔离账号的程序副本
|
|
49
49
|
|
|
50
50
|
托管账号
|
package/runner/admin_panel.mjs
CHANGED
|
@@ -12,6 +12,7 @@ import { randomBytes } from 'node:crypto';
|
|
|
12
12
|
import { closeSync, copyFileSync, cpSync, existsSync, lstatSync, mkdirSync, mkdtempSync, openSync, realpathSync, readdirSync, readFileSync, readSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
13
13
|
import http from 'node:http';
|
|
14
14
|
import { homedir, tmpdir } from 'node:os';
|
|
15
|
+
import tls from 'node:tls';
|
|
15
16
|
import { dirname, extname, join, resolve } from 'node:path';
|
|
16
17
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
17
18
|
import { parseArgs } from 'node:util';
|
|
@@ -43,7 +44,12 @@ const VERSION = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8')).ver
|
|
|
43
44
|
const NPM_PACKAGE = 'ai_co_discuss';
|
|
44
45
|
const LATEST_URL = `https://registry.npmjs.org/${NPM_PACKAGE}/latest`;
|
|
45
46
|
const LATEST_TTL_MS = 60 * 60 * 1000;
|
|
46
|
-
const
|
|
47
|
+
const OUTSIDE_TIMEOUT_MS = 15_000, OUTSIDE_ATTEMPTS = 2;
|
|
48
|
+
// Node 24 (OpenSSL 3.5) offers a post-quantum key share first, which makes its TLS greeting span several packets; behind
|
|
49
|
+
// a Clash (Mihomo) TUN such connections were reset more than half the time, while curl and browsers got through (seen
|
|
50
|
+
// 2026-11-14). What the panel fetches outside is public (the latest version, a site's entry address, the relay's state),
|
|
51
|
+
// so it offers the classic key shares only.
|
|
52
|
+
tls.DEFAULT_ECDH_CURVE = 'X25519:prime256v1:secp384r1';
|
|
47
53
|
const STATE_FILE = 'admin-panel.json';
|
|
48
54
|
// An update's progress and report, kept in the service directory (panel_updater.mjs writes it too), and how long an
|
|
49
55
|
// unfinished one blocks another.
|
|
@@ -95,10 +101,27 @@ function service_overview(data) {
|
|
|
95
101
|
|
|
96
102
|
let latest = { at: 0, version: '' };
|
|
97
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Fetch an outside address, trying once more when the connection is dropped; a request that stalls to its timeout is not
|
|
106
|
+
* tried again (that would keep the owner waiting). Failing is reported naming the host, not as a problem of the site.
|
|
107
|
+
*/
|
|
108
|
+
async function fetch_outside(url, timeout_ms) {
|
|
109
|
+
for (let attempt = 1; ; attempt += 1) {
|
|
110
|
+
try {
|
|
111
|
+
return await fetch(url, { signal: AbortSignal.timeout(timeout_ms) });
|
|
112
|
+
} catch (error) {
|
|
113
|
+
const timed_out = error.name === 'TimeoutError';
|
|
114
|
+
if (!timed_out && attempt < OUTSIDE_ATTEMPTS) continue;
|
|
115
|
+
const why = timed_out ? `${timeout_ms / 1000} 秒内没有响应` : `连接被断开(${error.cause?.code || error.message})`;
|
|
116
|
+
throw new Error(`连不上 ${new URL(url).host}:${why},请检查这台电脑的网络或代理后重试`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
98
121
|
/** The newest published version, asked of the npm registry at most once an hour (nothing about this computer is sent). */
|
|
99
122
|
async function latest_version(force = false) {
|
|
100
123
|
if (!force && latest.version && Date.now() - latest.at < LATEST_TTL_MS) return latest.version;
|
|
101
|
-
const response = await
|
|
124
|
+
const response = await fetch_outside(LATEST_URL, OUTSIDE_TIMEOUT_MS);
|
|
102
125
|
if (!response.ok) throw new Error(`查询新版本失败(HTTP ${response.status})`);
|
|
103
126
|
latest = { at: Date.now(), version: String((await response.json()).version || '') };
|
|
104
127
|
return latest.version;
|
|
@@ -503,7 +526,7 @@ function run_instance(data, name, command) {
|
|
|
503
526
|
// An account without its own Windows user runs as the owner and could read everything the owner can; it is not let
|
|
504
527
|
// run while people outside can reach the entry.
|
|
505
528
|
if (command === 'start' && process.platform === 'win32' && !read_os_users(data)[name] && entry_settings(data).mode !== 'local') {
|
|
506
|
-
throw new Error(`外网访问已开启,${name}
|
|
529
|
+
throw new Error(`外网访问已开启,${name} 未隔离(以你的身份运行),不能启动:请先隔离该账号,或把登录入口的访问方式改为“仅这台电脑”`);
|
|
507
530
|
}
|
|
508
531
|
if (command === 'start' && read_os_users(data)[name]) {
|
|
509
532
|
const { local_script } = shared_paths();
|
|
@@ -775,7 +798,7 @@ function bound_site(data) {
|
|
|
775
798
|
/** Ask the relay's entry Worker whether it is one and whether this computer is connected to it. */
|
|
776
799
|
async function relay_status(relay_url, machine) {
|
|
777
800
|
try {
|
|
778
|
-
const answer = await
|
|
801
|
+
const answer = await fetch_outside(`${relay_url}/_codiscuss/status?machine=${machine || '0'.repeat(32)}`, RELAY_CHECK_MS);
|
|
779
802
|
const result = await answer.json();
|
|
780
803
|
return result.service === 'codiscuss-entry' ? { reachable: true, online: Boolean(result.online) } : { reachable: false, online: false };
|
|
781
804
|
} catch { return { reachable: false, online: false }; }
|
|
@@ -820,7 +843,7 @@ async function set_entry_mode(data, mode) {
|
|
|
820
843
|
const users = read_os_users(data), accounts = read_accounts(data);
|
|
821
844
|
const exposed = [];
|
|
822
845
|
for (const [name, account] of Object.entries(accounts)) if (!users[name] && await instance_running(account.port)) exposed.push(name);
|
|
823
|
-
if (exposed.length) throw new Error(`未隔离的账号正在运行(${exposed.join('、')}
|
|
846
|
+
if (exposed.length) throw new Error(`未隔离的账号正在运行(${exposed.join('、')}),它们以你的身份运行,改用线上中转或自有域名前请先停止或隔离`);
|
|
824
847
|
}
|
|
825
848
|
save_entry_settings(data, { mode });
|
|
826
849
|
if (mode !== 'local' && !(await entry_status(data)).running) { await start_entry(data); save_entry_settings(data, { running: true }); }
|
|
@@ -893,7 +916,8 @@ async function join_relay(data, text) {
|
|
|
893
916
|
|
|
894
917
|
/** The entry Worker address an online site gives (`GET /api/entry`). */
|
|
895
918
|
async function site_entry_url(site) {
|
|
896
|
-
const
|
|
919
|
+
const answer = await fetch_outside(`${site}/api/entry`, OUTSIDE_TIMEOUT_MS);
|
|
920
|
+
const given = await answer.json().catch(() => ({}));
|
|
897
921
|
if (!given.entry_url) throw new Error(`${site} 没有提供入口地址:请部署线上站点的人在部署配置里设置 ENTRY_URL 并重新发布`);
|
|
898
922
|
return given.entry_url;
|
|
899
923
|
}
|