




















@@ -232,7 +232,11 @@ function configureCliLogMode(verbose: boolean): void {
232232setMatrixSdkConsoleLogging(verbose);
233233}
234234235-function parseOptionalInt(value: string | undefined, fieldName: string): number | undefined {
235+function parseOptionalInt(
236+value: string | undefined,
237+fieldName: string,
238+opts: { min?: number } = {},
239+): number | undefined {
236240const trimmed = value?.trim();
237241if (!trimmed) {
238242return undefined;
@@ -244,6 +248,13 @@ function parseOptionalInt(value: string | undefined, fieldName: string): number
244248if (parsed === undefined) {
245249throw new Error(`${fieldName} must be an integer`);
246250}
251+if (opts.min !== undefined && parsed < opts.min) {
252+throw new Error(
253+opts.min === 1
254+ ? `${fieldName} must be a positive integer`
255+ : `${fieldName} must be a non-negative integer`,
256+);
257+}
247258return parsed;
248259}
249260@@ -289,6 +300,9 @@ async function addMatrixAccount(params: {
289300useEnv?: boolean;
290301enableEncryption?: boolean;
291302}): Promise<MatrixCliAccountAddResult> {
303+const initialSyncLimit = parseOptionalInt(params.initialSyncLimit, "--initial-sync-limit", {
304+min: 0,
305+});
292306const runtime = getMatrixRuntime();
293307const cfg = runtime.config.current() as CoreConfig;
294308if (!matrixSetupAdapter.applyAccountConfig) {
@@ -305,7 +319,7 @@ async function addMatrixAccount(params: {
305319accessToken: params.accessToken,
306320password: params.password,
307321deviceName: params.deviceName,
308-initialSyncLimit: parseOptionalInt(params.initialSyncLimit, "--initial-sync-limit"),
322+ initialSyncLimit,
309323useEnv: params.useEnv === true,
310324};
311325const accountId =
@@ -1159,15 +1173,18 @@ async function runMatrixCliVerificationSummaryCommand(params: {
11591173async function runMatrixCliSelfVerificationCommand(
11601174options: MatrixCliSelfVerificationCommandOptions,
11611175): Promise<void> {
1162-const { accountId, cfg } = resolveMatrixCliAccountContext(options.account);
1176+let resolvedAccountId: string | undefined;
11631177await runMatrixCliCommand({
11641178verbose: options.verbose === true,
11651179json: false,
1166-run: async () =>
1167-await runMatrixSelfVerification({
1180+run: async () => {
1181+const timeoutMs = parseOptionalInt(options.timeoutMs, "--timeout-ms", { min: 1 });
1182+const { accountId, cfg } = resolveMatrixCliAccountContext(options.account);
1183+resolvedAccountId = accountId;
1184+return await runMatrixSelfVerification({
11681185 accountId,
11691186 cfg,
1170-timeoutMs: parseOptionalInt(options.timeoutMs, "--timeout-ms"),
1187+ timeoutMs,
11711188onRequested: (summary) => {
11721189printAccountLabel(accountId);
11731190printMatrixVerificationSummary(summary);
@@ -1184,7 +1201,8 @@ async function runMatrixCliSelfVerificationCommand(
11841201console.log("Compare this SAS with the other Matrix client.");
11851202},
11861203confirmSas: async () => await promptMatrixVerificationSasMatch(),
1187-}),
1204+});
1205+},
11881206onText: (summary, verbose) => {
11891207printMatrixVerificationSummary(summary);
11901208console.log(`Device verified by owner: ${summary.deviceOwnerVerified ? "yes" : "no"}`);
@@ -1196,6 +1214,7 @@ async function runMatrixCliSelfVerificationCommand(
11961214console.log("Self-verification complete.");
11971215},
11981216onTextError: () => {
1217+const accountId = resolvedAccountId ?? options.account;
11991218printGuidance([
12001219`Run ${formatMatrixCliCommand("verify self", accountId)} again and accept the request in another verified Matrix client for this account.`,
12011220`Then run ${formatMatrixCliCommand("verify status --verbose", accountId)} to confirm Cross-signing verified: yes and Signed by owner: yes.`,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。