fix: getDashboardInfo 改为读取 config.yaml
openclaw 配置文件路径从 openclaw.json 迁移到 config/config.yaml,用正则提取 token 和 port 字段。 Made-with: Cursor
This commit is contained in:
17
lib/frpc.js
17
lib/frpc.js
@@ -20,23 +20,24 @@ const TTYD_PORT = 7681;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 从 openclaw 配置文件中提取 dashboard token 和端口。
|
* 从 openclaw 配置文件中提取 dashboard token 和端口。
|
||||||
* openclaw 将 gateway token 持久化存储在 ~/.openclaw/openclaw.json 中,
|
* openclaw 将配置持久化存储在 ~/.openclaw/config/config.yaml 中,
|
||||||
* 直接读取比执行命令更可靠(不依赖 PATH、不需要进程启动等待)。
|
* 直接读取比执行命令更可靠(不依赖 PATH、不需要进程启动等待)。
|
||||||
* systemd 服务的 ProtectHome=read-only 允许读取 /home 下的文件。
|
* systemd 服务的 ProtectHome=read-only 允许读取 /home 下的文件。
|
||||||
*/
|
*/
|
||||||
function getDashboardInfo() {
|
function getDashboardInfo() {
|
||||||
const configCandidates = [
|
const configCandidates = [
|
||||||
path.join(os.homedir(), '.openclaw', 'openclaw.json'),
|
path.join(os.homedir(), '.openclaw', 'config', 'config.yaml'),
|
||||||
'/home/sts/.openclaw/openclaw.json',
|
'/home/sts/.openclaw/config/config.yaml',
|
||||||
'/root/.openclaw/openclaw.json',
|
'/root/.openclaw/config/config.yaml',
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const cfgPath of configCandidates) {
|
for (const cfgPath of configCandidates) {
|
||||||
try {
|
try {
|
||||||
const raw = fs.readFileSync(cfgPath, 'utf8');
|
const raw = fs.readFileSync(cfgPath, 'utf8');
|
||||||
const config = JSON.parse(raw);
|
const tokenMatch = raw.match(/^\s*token:\s*["']?([A-Za-z0-9_\-\.]+)["']?\s*$/m);
|
||||||
const token = config?.gateway?.auth?.token;
|
const portMatch = raw.match(/^\s*port:\s*(\d+)\s*$/m);
|
||||||
const port = config?.gateway?.port || 18789;
|
const token = tokenMatch?.[1];
|
||||||
|
const port = portMatch ? Number(portMatch[1]) : 18789;
|
||||||
if (token) {
|
if (token) {
|
||||||
log.info('dashboard', `从配置文件读取: port=${port}, token=${token.substring(0, 8)}...`);
|
log.info('dashboard', `从配置文件读取: port=${port}, token=${token.substring(0, 8)}...`);
|
||||||
return Promise.resolve({ dashboard_port: port, dashboard_token: token });
|
return Promise.resolve({ dashboard_port: port, dashboard_token: token });
|
||||||
|
|||||||
Reference in New Issue
Block a user