mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 08:22:47 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -47,7 +47,9 @@ function summarizeSources(sources: Array<string | undefined>): {
|
||||
|
||||
function existsSyncMaybe(p: string | undefined): boolean | null {
|
||||
const path = p?.trim() || "";
|
||||
if (!path) return null;
|
||||
if (!path) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return fs.existsSync(path);
|
||||
} catch {
|
||||
@@ -61,17 +63,25 @@ function sha256HexPrefix(value: string, len = 8): string {
|
||||
|
||||
function formatTokenHint(token: string, opts: { showSecrets: boolean }): string {
|
||||
const t = token.trim();
|
||||
if (!t) return "empty";
|
||||
if (!opts.showSecrets) return `sha256:${sha256HexPrefix(t)} · len ${t.length}`;
|
||||
if (!t) {
|
||||
return "empty";
|
||||
}
|
||||
if (!opts.showSecrets) {
|
||||
return `sha256:${sha256HexPrefix(t)} · len ${t.length}`;
|
||||
}
|
||||
const head = t.slice(0, 4);
|
||||
const tail = t.slice(-4);
|
||||
if (t.length <= 10) return `${t} · len ${t.length}`;
|
||||
if (t.length <= 10) {
|
||||
return `${t} · len ${t.length}`;
|
||||
}
|
||||
return `${head}…${tail} · len ${t.length}`;
|
||||
}
|
||||
|
||||
const formatAccountLabel = (params: { accountId: string; name?: string }) => {
|
||||
const base = params.accountId || "default";
|
||||
if (params.name?.trim()) return `${base} (${params.name.trim()})`;
|
||||
if (params.name?.trim()) {
|
||||
return `${base} (${params.name.trim()})`;
|
||||
}
|
||||
return base;
|
||||
};
|
||||
|
||||
@@ -80,7 +90,9 @@ const resolveAccountEnabled = (
|
||||
account: unknown,
|
||||
cfg: OpenClawConfig,
|
||||
): boolean => {
|
||||
if (plugin.config.isEnabled) return plugin.config.isEnabled(account, cfg);
|
||||
if (plugin.config.isEnabled) {
|
||||
return plugin.config.isEnabled(account, cfg);
|
||||
}
|
||||
const enabled = asRecord(account).enabled;
|
||||
return enabled !== false;
|
||||
};
|
||||
@@ -138,8 +150,12 @@ const buildAccountNotes = (params: {
|
||||
const { plugin, cfg, entry } = params;
|
||||
const notes: string[] = [];
|
||||
const snapshot = entry.snapshot;
|
||||
if (snapshot.enabled === false) notes.push("disabled");
|
||||
if (snapshot.dmPolicy) notes.push(`dm:${snapshot.dmPolicy}`);
|
||||
if (snapshot.enabled === false) {
|
||||
notes.push("disabled");
|
||||
}
|
||||
if (snapshot.dmPolicy) {
|
||||
notes.push(`dm:${snapshot.dmPolicy}`);
|
||||
}
|
||||
if (snapshot.tokenSource && snapshot.tokenSource !== "none") {
|
||||
notes.push(`token:${snapshot.tokenSource}`);
|
||||
}
|
||||
@@ -149,10 +165,18 @@ const buildAccountNotes = (params: {
|
||||
if (snapshot.appTokenSource && snapshot.appTokenSource !== "none") {
|
||||
notes.push(`app:${snapshot.appTokenSource}`);
|
||||
}
|
||||
if (snapshot.baseUrl) notes.push(snapshot.baseUrl);
|
||||
if (snapshot.port != null) notes.push(`port:${snapshot.port}`);
|
||||
if (snapshot.cliPath) notes.push(`cli:${snapshot.cliPath}`);
|
||||
if (snapshot.dbPath) notes.push(`db:${snapshot.dbPath}`);
|
||||
if (snapshot.baseUrl) {
|
||||
notes.push(snapshot.baseUrl);
|
||||
}
|
||||
if (snapshot.port != null) {
|
||||
notes.push(`port:${snapshot.port}`);
|
||||
}
|
||||
if (snapshot.cliPath) {
|
||||
notes.push(`cli:${snapshot.cliPath}`);
|
||||
}
|
||||
if (snapshot.dbPath) {
|
||||
notes.push(`db:${snapshot.dbPath}`);
|
||||
}
|
||||
|
||||
const allowFrom =
|
||||
plugin.config.resolveAllowFrom?.({ cfg, accountId: snapshot.accountId }) ?? snapshot.allowFrom;
|
||||
@@ -163,7 +187,9 @@ const buildAccountNotes = (params: {
|
||||
accountId: snapshot.accountId,
|
||||
allowFrom,
|
||||
}).slice(0, 3);
|
||||
if (formatted.length > 0) notes.push(`allow:${formatted.join(",")}`);
|
||||
if (formatted.length > 0) {
|
||||
notes.push(`allow:${formatted.join(",")}`);
|
||||
}
|
||||
}
|
||||
|
||||
return notes;
|
||||
@@ -198,7 +224,9 @@ function collectMissingPaths(accounts: ChannelAccountRow[]): string[] {
|
||||
const raw =
|
||||
(accountRec[key] as string | undefined) ?? (snapshotRec[key] as string | undefined);
|
||||
const ok = existsSyncMaybe(raw);
|
||||
if (ok === false) missing.push(String(raw));
|
||||
if (ok === false) {
|
||||
missing.push(String(raw));
|
||||
}
|
||||
}
|
||||
}
|
||||
return missing;
|
||||
@@ -211,7 +239,9 @@ function summarizeTokenConfig(params: {
|
||||
showSecrets: boolean;
|
||||
}): { state: "ok" | "setup" | "warn" | null; detail: string | null } {
|
||||
const enabled = params.accounts.filter((a) => a.enabled);
|
||||
if (enabled.length === 0) return { state: null, detail: null };
|
||||
if (enabled.length === 0) {
|
||||
return { state: null, detail: null };
|
||||
}
|
||||
|
||||
const accountRecs = enabled.map((a) => asRecord(a.account));
|
||||
const hasBotOrAppTokenFields = accountRecs.some((r) => "botToken" in r || "appToken" in r);
|
||||
@@ -365,28 +395,50 @@ export async function buildChannelsTable(
|
||||
const label = plugin.meta.label ?? plugin.id;
|
||||
|
||||
const state = (() => {
|
||||
if (!anyEnabled) return "off";
|
||||
if (missingPaths.length > 0) return "warn";
|
||||
if (issues.length > 0) return "warn";
|
||||
if (link.linked === false) return "setup";
|
||||
if (tokenSummary.state) return tokenSummary.state;
|
||||
if (link.linked === true) return "ok";
|
||||
if (configuredAccounts.length > 0) return "ok";
|
||||
if (!anyEnabled) {
|
||||
return "off";
|
||||
}
|
||||
if (missingPaths.length > 0) {
|
||||
return "warn";
|
||||
}
|
||||
if (issues.length > 0) {
|
||||
return "warn";
|
||||
}
|
||||
if (link.linked === false) {
|
||||
return "setup";
|
||||
}
|
||||
if (tokenSummary.state) {
|
||||
return tokenSummary.state;
|
||||
}
|
||||
if (link.linked === true) {
|
||||
return "ok";
|
||||
}
|
||||
if (configuredAccounts.length > 0) {
|
||||
return "ok";
|
||||
}
|
||||
return "setup";
|
||||
})();
|
||||
|
||||
const detail = (() => {
|
||||
if (!anyEnabled) {
|
||||
if (!defaultEntry) return "disabled";
|
||||
if (!defaultEntry) {
|
||||
return "disabled";
|
||||
}
|
||||
return plugin.config.disabledReason?.(defaultEntry.account, cfg) ?? "disabled";
|
||||
}
|
||||
if (missingPaths.length > 0) return `missing file (${missingPaths[0]})`;
|
||||
if (issues.length > 0) return issues[0]?.message ?? "misconfigured";
|
||||
if (missingPaths.length > 0) {
|
||||
return `missing file (${missingPaths[0]})`;
|
||||
}
|
||||
if (issues.length > 0) {
|
||||
return issues[0]?.message ?? "misconfigured";
|
||||
}
|
||||
|
||||
if (link.linked !== null) {
|
||||
const base = link.linked ? "linked" : "not linked";
|
||||
const extra: string[] = [];
|
||||
if (link.linked && link.selfE164) extra.push(link.selfE164);
|
||||
if (link.linked && link.selfE164) {
|
||||
extra.push(link.selfE164);
|
||||
}
|
||||
if (link.linked && link.authAgeMs != null && link.authAgeMs >= 0) {
|
||||
extra.push(`auth ${formatAge(link.authAgeMs)}`);
|
||||
}
|
||||
@@ -396,11 +448,15 @@ export async function buildChannelsTable(
|
||||
return extra.length > 0 ? `${base} · ${extra.join(" · ")}` : base;
|
||||
}
|
||||
|
||||
if (tokenSummary.detail) return tokenSummary.detail;
|
||||
if (tokenSummary.detail) {
|
||||
return tokenSummary.detail;
|
||||
}
|
||||
|
||||
if (configuredAccounts.length > 0) {
|
||||
const head = "configured";
|
||||
if (accounts.length <= 1 && !plugin.meta.forceAccountBinding) return head;
|
||||
if (accounts.length <= 1 && !plugin.meta.forceAccountBinding) {
|
||||
return head;
|
||||
}
|
||||
return `${head} · accounts ${configuredAccounts.length}/${enabledAccounts.length || 1}`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user