mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
fix: de-duplicate normalized account IDs and add case-insensitive config lookup to send/client
This commit is contained in:
committed by
Peter Steinberger
parent
a6dd50fede
commit
bf4e348440
@@ -18,10 +18,14 @@ function listConfiguredAccountIds(cfg: CoreConfig): string[] {
|
||||
if (!accounts || typeof accounts !== "object") {
|
||||
return [];
|
||||
}
|
||||
// Normalize keys so listing and resolution use the same semantics
|
||||
return Object.keys(accounts)
|
||||
.filter(Boolean)
|
||||
.map((id) => normalizeAccountId(id));
|
||||
// Normalize and de-duplicate keys so listing and resolution use the same semantics
|
||||
return [
|
||||
...new Set(
|
||||
Object.keys(accounts)
|
||||
.filter(Boolean)
|
||||
.map((id) => normalizeAccountId(id)),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
export function listMatrixAccountIds(cfg: CoreConfig): string[] {
|
||||
|
||||
@@ -18,13 +18,33 @@ export function ensureNodeRuntime() {
|
||||
}
|
||||
}
|
||||
|
||||
/** Look up account config with case-insensitive key fallback. */
|
||||
function findAccountConfig(
|
||||
accounts: Record<string, unknown> | undefined,
|
||||
accountId: string,
|
||||
): Record<string, unknown> | undefined {
|
||||
if (!accounts) return undefined;
|
||||
const normalized = normalizeAccountId(accountId);
|
||||
// Direct lookup first
|
||||
if (accounts[normalized]) return accounts[normalized] as Record<string, unknown>;
|
||||
// Case-insensitive fallback
|
||||
for (const key of Object.keys(accounts)) {
|
||||
if (normalizeAccountId(key) === normalized) {
|
||||
return accounts[key] as Record<string, unknown>;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function resolveMediaMaxBytes(accountId?: string): number | undefined {
|
||||
const cfg = getCore().config.loadConfig() as CoreConfig;
|
||||
// Check account-specific config first (normalize to ensure consistent keying)
|
||||
const normalized = normalizeAccountId(accountId);
|
||||
const accountConfig = cfg.channels?.matrix?.accounts?.[normalized];
|
||||
// Check account-specific config first (case-insensitive key matching)
|
||||
const accountConfig = findAccountConfig(
|
||||
cfg.channels?.matrix?.accounts as Record<string, unknown> | undefined,
|
||||
accountId ?? "",
|
||||
);
|
||||
if (typeof accountConfig?.mediaMaxMb === "number") {
|
||||
return accountConfig.mediaMaxMb * 1024 * 1024;
|
||||
return (accountConfig.mediaMaxMb as number) * 1024 * 1024;
|
||||
}
|
||||
// Fall back to top-level config
|
||||
if (typeof cfg.channels?.matrix?.mediaMaxMb === "number") {
|
||||
|
||||
Reference in New Issue
Block a user