From edb040d31a5cf47d55f3f1da51bb6bde000b5f91 Mon Sep 17 00:00:00 2001 From: Codex Date: Sat, 13 Jun 2026 04:55:53 +0000 Subject: [PATCH] fix: compact wechat archive status output --- scripts/src/platform-infra-wechat-archive.ts | 102 ++++++++++++++++++- 1 file changed, 98 insertions(+), 4 deletions(-) diff --git a/scripts/src/platform-infra-wechat-archive.ts b/scripts/src/platform-infra-wechat-archive.ts index 2408e0eb..70428de6 100644 --- a/scripts/src/platform-infra-wechat-archive.ts +++ b/scripts/src/platform-infra-wechat-archive.ts @@ -8,7 +8,6 @@ import { asRecord, assertProxyOk, booleanField, - compactProxyResponse, compactUnknown, containerPathToHostPath, fetchJsonWithTimeout, @@ -241,9 +240,9 @@ async function status(options: OpsCommonOptions): Promise): Record): Record { + const body = typeof response.body === "object" && response.body !== null && !Array.isArray(response.body) + ? response.body as Record + : {}; + const storage = typeof body.storage === "object" && body.storage !== null && !Array.isArray(body.storage) ? body.storage as Record : {}; + const queue = typeof body.queue === "object" && body.queue !== null && !Array.isArray(body.queue) ? body.queue as Record : {}; + const transfers = typeof queue.transfers === "object" && queue.transfers !== null && !Array.isArray(queue.transfers) ? queue.transfers as Record : {}; + return { + ok: response.ok, + status: response.status, + service: body.service, + storage: { + postgres: storage.postgres, + stagingDir: storage.stagingDir, + }, + queue: { + transfers: { + succeeded: transfers.succeeded, + failed: transfers.failed, + }, + }, + }; +} + +function compactBaiduAuth(response: ReturnType): Record { + const body = typeof response.body === "object" && response.body !== null && !Array.isArray(response.body) + ? response.body as Record + : {}; + const auth = typeof body.auth === "object" && body.auth !== null && !Array.isArray(body.auth) ? body.auth as Record : {}; + const account = typeof auth.account === "object" && auth.account !== null && !Array.isArray(auth.account) ? auth.account as Record : {}; + return { + ok: response.ok, + status: response.status, + configured: auth.configured, + loggedIn: auth.loggedIn, + account: { + present: Object.keys(account).length > 0, + rootPath: account.rootPath, + quota: compactBaiduQuota(account.quota), + }, + valuesPrinted: false, + }; +} + +function compactBaiduQuota(value: unknown): Record | null { + if (typeof value !== "object" || value === null || Array.isArray(value)) return null; + const quota = value as Record; + return { + total: quota.total, + used: quota.used, + free: quota.free, + usedPercent: quota.usedPercent, + }; +} + +function compactBaiduTransfers(response: ReturnType): Record { + const body = typeof response.body === "object" && response.body !== null && !Array.isArray(response.body) + ? response.body as Record + : {}; + const counts = typeof body.counts === "object" && body.counts !== null && !Array.isArray(body.counts) ? body.counts as Record : {}; + const jobs = typeof body.jobs === "object" && body.jobs !== null && !Array.isArray(body.jobs) ? body.jobs as Record : {}; + const items = Array.isArray(jobs.items) + ? jobs.items + : Array.isArray(jobs.arrayPreview) + ? jobs.arrayPreview + : []; + return { + ok: response.ok, + status: response.status, + counts, + jobs: { + count: typeof jobs.count === "number" ? jobs.count : items.length, + items: items.slice(0, 10).map(compactBaiduTransferJob), + }, + }; +} + +function compactBaiduTransferJob(value: unknown): Record { + const job = typeof value === "object" && value !== null && !Array.isArray(value) ? value as Record : {}; + const result = typeof job.result === "object" && job.result !== null && !Array.isArray(job.result) ? job.result as Record : {}; + const baidu = typeof result.baidu === "object" && result.baidu !== null && !Array.isArray(result.baidu) ? result.baidu as Record : {}; + return { + id: job.id, + direction: job.direction, + status: job.status, + createdAt: job.createdAt, + updatedAt: job.updatedAt, + remotePath: job.remotePath ?? result.remotePath, + fsId: job.fsId || baidu.fs_id || result.fsId, + sizeBytes: job.sizeBytes ?? result.sizeBytes ?? baidu.size, + progressPercent: job.progressPercent, + error: job.error || undefined, + }; +} + function redactBaiduFileEntry(value: Record | null): Record | null { if (value === null) return null; const copy: Record = { ...value };