mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-28 17:01:53 +03: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") {
|
if (!accounts || typeof accounts !== "object") {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
// Normalize keys so listing and resolution use the same semantics
|
// Normalize and de-duplicate keys so listing and resolution use the same semantics
|
||||||
return Object.keys(accounts)
|
return [
|
||||||
.filter(Boolean)
|
...new Set(
|
||||||
.map((id) => normalizeAccountId(id));
|
Object.keys(accounts)
|
||||||
|
.filter(Boolean)
|
||||||
|
.map((id) => normalizeAccountId(id)),
|
||||||
|
),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function listMatrixAccountIds(cfg: CoreConfig): string[] {
|
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 {
|
export function resolveMediaMaxBytes(accountId?: string): number | undefined {
|
||||||
const cfg = getCore().config.loadConfig() as CoreConfig;
|
const cfg = getCore().config.loadConfig() as CoreConfig;
|
||||||
// Check account-specific config first (normalize to ensure consistent keying)
|
// Check account-specific config first (case-insensitive key matching)
|
||||||
const normalized = normalizeAccountId(accountId);
|
const accountConfig = findAccountConfig(
|
||||||
const accountConfig = cfg.channels?.matrix?.accounts?.[normalized];
|
cfg.channels?.matrix?.accounts as Record<string, unknown> | undefined,
|
||||||
|
accountId ?? "",
|
||||||
|
);
|
||||||
if (typeof accountConfig?.mediaMaxMb === "number") {
|
if (typeof accountConfig?.mediaMaxMb === "number") {
|
||||||
return accountConfig.mediaMaxMb * 1024 * 1024;
|
return (accountConfig.mediaMaxMb as number) * 1024 * 1024;
|
||||||
}
|
}
|
||||||
// Fall back to top-level config
|
// Fall back to top-level config
|
||||||
if (typeof cfg.channels?.matrix?.mediaMaxMb === "number") {
|
if (typeof cfg.channels?.matrix?.mediaMaxMb === "number") {
|
||||||
|
|||||||
Reference in New Issue
Block a user