siluzan-cso-cli 1.1.45 → 1.1.47-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -231,9 +231,9 @@ var require_semver = __commonJS({
231
231
  } else {
232
232
  this.prerelease = m[4].split(".").map((id) => {
233
233
  if (/^[0-9]+$/.test(id)) {
234
- const num = +id;
235
- if (num >= 0 && num < MAX_SAFE_INTEGER) {
236
- return num;
234
+ const num2 = +id;
235
+ if (num2 >= 0 && num2 < MAX_SAFE_INTEGER) {
236
+ return num2;
237
237
  }
238
238
  }
239
239
  return id;
@@ -1936,11 +1936,11 @@ var require_semver2 = __commonJS({
1936
1936
  });
1937
1937
 
1938
1938
  // ../common/dist/index.js
1939
- var import_semver = __toESM(require_semver2(), 1);
1940
1939
  import * as fs from "fs";
1941
1940
  import * as path from "path";
1942
1941
  import * as os from "os";
1943
1942
  import lockfile from "proper-lockfile";
1943
+ var import_semver = __toESM(require_semver2(), 1);
1944
1944
  import * as https from "https";
1945
1945
  import * as http from "http";
1946
1946
  import * as zlib from "zlib";
@@ -2317,7 +2317,6 @@ function buildSiluzanClientIdentityHeaders() {
2317
2317
  return headers;
2318
2318
  }
2319
2319
  var DEFAULT_TIMEOUT_MS = 10 * 60 * 1e3;
2320
- var MAX_RESPONSE_BYTES = 50 * 1024 * 1024;
2321
2320
  var httpsAgent = new https.Agent({
2322
2321
  keepAlive: true,
2323
2322
  keepAliveMsecs: 3e4,
@@ -2344,15 +2343,43 @@ function emitPerf(record) {
2344
2343
  } catch {
2345
2344
  }
2346
2345
  }
2346
+ var RequestAbortedError = class extends Error {
2347
+ code = "SILUZAN_REQUEST_CANCELLED";
2348
+ constructor(method, url) {
2349
+ super(`\u8BF7\u6C42\u5DF2\u53D6\u6D88\uFF1A${method} ${url}`);
2350
+ this.name = "RequestAbortedError";
2351
+ }
2352
+ };
2347
2353
  function rawRequest(url, options) {
2348
2354
  const perfOn = isPerfEnabled();
2349
2355
  const t0 = perfOn ? performance.now() : 0;
2350
2356
  const method = options.method ?? "GET";
2351
- return new Promise((resolve52, reject) => {
2357
+ return new Promise((resolvePromise, rejectPromise) => {
2358
+ const signal = options.signal;
2359
+ if (signal?.aborted) {
2360
+ rejectPromise(new RequestAbortedError(method, url));
2361
+ return;
2362
+ }
2363
+ let settled = false;
2364
+ let onAbort;
2365
+ const settle = () => {
2366
+ settled = true;
2367
+ if (onAbort) signal?.removeEventListener("abort", onAbort);
2368
+ };
2369
+ const resolve52 = (value) => {
2370
+ if (settled) return;
2371
+ settle();
2372
+ resolvePromise(value);
2373
+ };
2374
+ const reject = (err) => {
2375
+ if (settled) return;
2376
+ settle();
2377
+ rejectPromise(err);
2378
+ };
2352
2379
  const parsed = new URL(url);
2353
2380
  const transport = parsed.protocol === "https:" ? https : http;
2354
2381
  const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
2355
- const maxBytes = options.maxResponseBytes ?? MAX_RESPONSE_BYTES;
2382
+ const maxBytes = options.maxResponseBytes ?? 0;
2356
2383
  const isHttps = parsed.protocol === "https:";
2357
2384
  const headers = {
2358
2385
  ...buildSiluzanClientIdentityHeaders(),
@@ -2390,8 +2417,12 @@ function rawRequest(url, options) {
2390
2417
  } else if (encoding === "br") {
2391
2418
  stream = res.pipe(zlib.createBrotliDecompress());
2392
2419
  }
2393
- const handleStreamError = (err) => {
2420
+ let failed = false;
2421
+ const fail = (err) => {
2422
+ if (failed) return;
2423
+ failed = true;
2394
2424
  res.destroy();
2425
+ if (settled) return;
2395
2426
  if (perfOn) {
2396
2427
  emitPerf({
2397
2428
  method,
@@ -2400,43 +2431,37 @@ function rawRequest(url, options) {
2400
2431
  elapsedMs: performance.now() - t0,
2401
2432
  bytes: 0,
2402
2433
  ok: false,
2403
- error: `decompress error: ${err.message}`
2434
+ error: err.message
2404
2435
  });
2405
2436
  }
2406
- reject(new Error(`\u54CD\u5E94\u89E3\u538B\u5931\u8D25\uFF08${encoding || "identity"}\uFF09\uFF1A${err.message}`));
2437
+ reject(err);
2407
2438
  };
2408
- if (stream !== res) stream.on("error", handleStreamError);
2409
- res.on("error", handleStreamError);
2410
- let data = "";
2439
+ const onStreamError = (err) => {
2440
+ fail(new Error(`\u54CD\u5E94\u89E3\u538B\u5931\u8D25\uFF08${encoding || "identity"}\uFF09\uFF1A${err.message}`));
2441
+ };
2442
+ if (stream !== res) stream.on("error", onStreamError);
2443
+ res.on("error", onStreamError);
2444
+ const chunks = [];
2411
2445
  let byteLen = 0;
2412
- stream.setEncoding("utf8");
2413
2446
  stream.on("data", (chunk) => {
2414
- byteLen += Buffer.byteLength(chunk, "utf8");
2415
- if (maxBytes && byteLen > maxBytes) {
2416
- res.destroy();
2417
- if (perfOn) {
2418
- emitPerf({
2419
- method,
2420
- url,
2421
- status: res.statusCode ?? 0,
2422
- elapsedMs: performance.now() - t0,
2423
- bytes: byteLen,
2424
- ok: false,
2425
- error: "response body exceeded limit"
2426
- });
2427
- }
2428
- reject(
2447
+ if (failed) return;
2448
+ const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
2449
+ byteLen += buf.length;
2450
+ if (maxBytes > 0 && byteLen > maxBytes) {
2451
+ fail(
2429
2452
  new Error(`\u54CD\u5E94\u4F53\u8D85\u8FC7\u4E0A\u9650\uFF08${(maxBytes / 1024 / 1024).toFixed(0)} MB\uFF09\uFF0C\u5DF2\u4E2D\u65AD\u8FDE\u63A5`)
2430
2453
  );
2431
2454
  return;
2432
2455
  }
2433
- data += chunk;
2456
+ chunks.push(buf);
2434
2457
  });
2435
2458
  stream.on("end", () => {
2436
- const headers2 = {};
2459
+ if (failed) return;
2460
+ const text = Buffer.concat(chunks).toString("utf8");
2461
+ const responseHeaders = {};
2437
2462
  for (const [key, val] of Object.entries(res.headers)) {
2438
2463
  if (val !== void 0) {
2439
- headers2[key.toLowerCase()] = Array.isArray(val) ? val[0] : val;
2464
+ responseHeaders[key.toLowerCase()] = Array.isArray(val) ? val[0] : val;
2440
2465
  }
2441
2466
  }
2442
2467
  const status = res.statusCode ?? 0;
@@ -2450,7 +2475,7 @@ function rawRequest(url, options) {
2450
2475
  ok: status >= 200 && status < 300
2451
2476
  });
2452
2477
  }
2453
- resolve52({ status, text: data, headers: headers2 });
2478
+ resolve52({ status, text, headers: responseHeaders });
2454
2479
  });
2455
2480
  });
2456
2481
  req.on("timeout", () => {
@@ -2469,6 +2494,7 @@ function rawRequest(url, options) {
2469
2494
  reject(new Error(`\u8BF7\u6C42\u8D85\u65F6\uFF08${(timeoutMs / 1e3).toFixed(0)} \u79D2\uFF09\uFF1A${method} ${url}`));
2470
2495
  });
2471
2496
  req.on("error", (err) => {
2497
+ if (settled) return;
2472
2498
  if (perfOn) {
2473
2499
  emitPerf({
2474
2500
  method,
@@ -2482,7 +2508,32 @@ function rawRequest(url, options) {
2482
2508
  }
2483
2509
  reject(err);
2484
2510
  });
2485
- if (options.body) req.write(options.body);
2511
+ if (signal) {
2512
+ onAbort = () => {
2513
+ if (settled) return;
2514
+ if (perfOn) {
2515
+ emitPerf({
2516
+ method,
2517
+ url,
2518
+ status: 0,
2519
+ elapsedMs: performance.now() - t0,
2520
+ bytes: 0,
2521
+ ok: false,
2522
+ error: "cancelled"
2523
+ });
2524
+ }
2525
+ reject(new RequestAbortedError(method, url));
2526
+ req.destroy();
2527
+ };
2528
+ signal.addEventListener("abort", onAbort, { once: true });
2529
+ }
2530
+ if (options.body !== void 0) {
2531
+ const payload = typeof options.body === "string" ? Buffer.from(options.body) : options.body;
2532
+ if (!headers["Content-Length"] && !headers["content-length"]) {
2533
+ req.setHeader("Content-Length", payload.length);
2534
+ }
2535
+ req.write(payload);
2536
+ }
2486
2537
  req.end();
2487
2538
  });
2488
2539
  }
@@ -2579,7 +2630,46 @@ function formatHttpError(status, rawBody, opts) {
2579
2630
  function buildAuthHeaders(config) {
2580
2631
  return buildSiluzanAuthHeaders(config);
2581
2632
  }
2582
- async function apiFetch(url, config, options = {}, verbose = false) {
2633
+ async function parseApiResponse(status, text, verbose) {
2634
+ if (status < 200 || status >= 300) {
2635
+ const err = new Error(formatHttpError(status, text, { verbose }));
2636
+ Object.assign(err, { status, rawBody: text });
2637
+ throw err;
2638
+ }
2639
+ if (!text.trim()) return null;
2640
+ try {
2641
+ return parseJsonWithStringIds(text);
2642
+ } catch {
2643
+ if (verbose) {
2644
+ console.error(` \u26A0\uFE0F \u54CD\u5E94\u975E JSON\uFF0C\u539F\u59CB\u5185\u5BB9\uFF1A${redactSensitive(text).slice(0, 200)}`);
2645
+ }
2646
+ return text;
2647
+ }
2648
+ }
2649
+ function isTransientNetworkError(err) {
2650
+ if (err instanceof RequestAbortedError) return false;
2651
+ const msg = err instanceof Error ? err.message : String(err);
2652
+ const code = err?.code;
2653
+ if (typeof code === "string" && ["ECONNRESET", "EPIPE", "ETIMEDOUT", "ECONNABORTED"].includes(code)) {
2654
+ return true;
2655
+ }
2656
+ return /响应解压失败|aborted|socket hang up|ECONNRESET|unexpected end of file/i.test(msg);
2657
+ }
2658
+ var GET_RETRY_DELAYS_MS = [1e3, 3e3];
2659
+ async function requestWithReadRetry(url, options) {
2660
+ const method = (options.method ?? "GET").toUpperCase();
2661
+ for (let attempt = 0; ; attempt++) {
2662
+ try {
2663
+ return await rawRequest(url, options);
2664
+ } catch (err) {
2665
+ if (method !== "GET" || options.signal?.aborted || attempt >= GET_RETRY_DELAYS_MS.length || !isTransientNetworkError(err)) {
2666
+ throw err;
2667
+ }
2668
+ await new Promise((r) => setTimeout(r, GET_RETRY_DELAYS_MS[attempt]));
2669
+ }
2670
+ }
2671
+ }
2672
+ async function apiFetch(url, config, options = {}, verbose = false, timeoutMs) {
2583
2673
  const method = options.method ?? "GET";
2584
2674
  const reqHeaders = {
2585
2675
  "Content-Type": "application/json",
@@ -2592,24 +2682,14 @@ async function apiFetch(url, config, options = {}, verbose = false) {
2592
2682
  ...options.headers ?? {}
2593
2683
  };
2594
2684
  const body = typeof options.body === "string" ? options.body : void 0;
2595
- const res = await rawRequest(url, {
2685
+ const res = await requestWithReadRetry(url, {
2596
2686
  method,
2597
2687
  headers: reqHeaders,
2598
- body
2688
+ body,
2689
+ signal: options.signal ?? void 0,
2690
+ ...timeoutMs !== void 0 ? { timeoutMs } : {}
2599
2691
  });
2600
- const text = res.text;
2601
- if (res.status < 200 || res.status >= 300) {
2602
- throw new Error(formatHttpError(res.status, text, { verbose }));
2603
- }
2604
- if (!text.trim()) return null;
2605
- try {
2606
- return parseJsonWithStringIds(text);
2607
- } catch {
2608
- if (verbose) {
2609
- console.error(` \u26A0\uFE0F \u54CD\u5E94\u975E JSON\uFF0C\u539F\u59CB\u5185\u5BB9\uFF1A${redactSensitive(text).slice(0, 200)}`);
2610
- }
2611
- return text;
2612
- }
2692
+ return parseApiResponse(res.status, res.text, verbose);
2613
2693
  }
2614
2694
  function decodeJwtClaims(token) {
2615
2695
  try {
@@ -3097,7 +3177,8 @@ async function emitCliJsonOrSnapshot(opts, params) {
3097
3177
  commandHint: params.commandHint,
3098
3178
  idSuffix: params.idSuffix
3099
3179
  });
3100
- console.log(JSON.stringify(summary));
3180
+ const line = params.summaryExtras ? { ...summary, ...params.summaryExtras } : summary;
3181
+ console.log(JSON.stringify(line));
3101
3182
  return true;
3102
3183
  }
3103
3184
  return false;
@@ -3530,11 +3611,11 @@ import { Command } from "commander";
3530
3611
  import { Option } from "commander";
3531
3612
 
3532
3613
  // src/config/defaults.ts
3533
- var BUILD_ENV = "production";
3534
- var DEFAULT_API_BASE = "https://api.siluzan.com";
3535
- var DEFAULT_CSO_BASE = "https://cso.siluzan.com";
3536
- var DEFAULT_WEB_BASE = "https://www.siluzan.com";
3537
- var DEFAULT_AGENT_BASE = "https://agent.mysiluzan.com";
3614
+ var BUILD_ENV = "test";
3615
+ var DEFAULT_API_BASE = "https://api-ci.siluzan.com";
3616
+ var DEFAULT_CSO_BASE = "https://cso-ci.siluzan.com";
3617
+ var DEFAULT_WEB_BASE = "https://www-ci.siluzan.com";
3618
+ var DEFAULT_AGENT_BASE = "https://agent-ci.mysiluzan.com";
3538
3619
 
3539
3620
  // src/commands/init.ts
3540
3621
  import * as fs6 from "fs/promises";
@@ -4812,9 +4893,8 @@ function buildCoverPayload(cover, videoId, currentUserId) {
4812
4893
  imageSourceType: cover.imageSourceType,
4813
4894
  sourceImageId: cover.sourceImageId ?? videoId,
4814
4895
  imageCreateUserId: cover.imageCreateUserId ?? currentUserId ?? void 0,
4815
- // belongTo / belongToId:CLI 无法获取组织信息,统一与前端素材库视频行为保持一致
4816
- belongTo: -1,
4817
- belongToId: null,
4896
+ belongTo: cover.belongTo ?? -1,
4897
+ belongToId: cover.belongToId ?? null,
4818
4898
  replica: false,
4819
4899
  coverTsp: 0,
4820
4900
  compositeCover: false,
@@ -5041,6 +5121,20 @@ function buildImageChannels(posts, currentUserId) {
5041
5121
  }
5042
5122
 
5043
5123
  // src/commands/publish/preview.ts
5124
+ function previewCoverUrl(value, verbose) {
5125
+ if (!value) return "\u26A0\uFE0F \u672A\u8BBE\u7F6E";
5126
+ if (verbose) return value;
5127
+ try {
5128
+ const url = new URL(value);
5129
+ url.username = "";
5130
+ url.password = "";
5131
+ url.search = "";
5132
+ url.hash = "";
5133
+ return url.href;
5134
+ } catch {
5135
+ return "\uFF08\u5C01\u9762\u5730\u5740\u5DF2\u9690\u85CF\uFF09";
5136
+ }
5137
+ }
5044
5138
  function formatTopics(topics) {
5045
5139
  if (!topics?.length) return "";
5046
5140
  return topics.map((t) => `#${t}`).join(" ");
@@ -5076,7 +5170,7 @@ ${SEP}`);
5076
5170
  console.log(` \u6807\u7B7E \uFF1A${topicsStr}`);
5077
5171
  }
5078
5172
  console.log(` \u53D1\u5E03\u6A21\u5F0F \uFF1A${formatPublishMode(item.publishMode, item.publishAt)}`);
5079
- console.log(` \u5C01\u9762 URL \uFF1A${item.cover?.imageUrl || "\u26A0\uFE0F \u672A\u8BBE\u7F6E"}`);
5173
+ console.log(` \u5C01\u9762 URL \uFF1A${previewCoverUrl(item.cover?.imageUrl, verbose)}`);
5080
5174
  if (item.cover?.sourceImageId) {
5081
5175
  console.log(` \u5C01\u9762 ID \uFF1A${item.cover.sourceImageId}`);
5082
5176
  }
@@ -5107,7 +5201,7 @@ ${SEP}`);
5107
5201
  }
5108
5202
  if (override.cover) {
5109
5203
  const cover = resolveVideoCover(item, override);
5110
- console.log(` \u5C01\u9762\u8986\u76D6 \uFF1A${cover.imageUrl || "\u26A0\uFE0F \u672A\u8BBE\u7F6E"}`);
5204
+ console.log(` \u5C01\u9762\u8986\u76D6 \uFF1A${previewCoverUrl(cover.imageUrl, verbose)}`);
5111
5205
  if (cover.sourceImageId) console.log(` \u5C01\u9762 ID \uFF1A${cover.sourceImageId}`);
5112
5206
  }
5113
5207
  }
@@ -5183,6 +5277,195 @@ ${SEP}`);
5183
5277
  // src/commands/publish/commands.ts
5184
5278
  import * as fs8 from "fs";
5185
5279
  import * as path8 from "path";
5280
+
5281
+ // src/utils/cover-validation.ts
5282
+ import * as http2 from "http";
5283
+ import * as https2 from "https";
5284
+ import { imageSize } from "image-size";
5285
+
5286
+ // src/utils/material-info.ts
5287
+ async function fetchMaterialInfo(config, id, verbose = false) {
5288
+ try {
5289
+ const url = new URL(`${config.csoBaseUrl}/cutapi/v1/material/get`);
5290
+ url.searchParams.set("id", id);
5291
+ const response = await apiFetch2(url.href, config, {}, verbose);
5292
+ if (response.code !== 1 || !response.data || typeof response.data.type !== "number") {
5293
+ throw new Error("Invalid material response");
5294
+ }
5295
+ return response.data;
5296
+ } catch {
5297
+ throw new Error("\u83B7\u53D6\u7D20\u6750\u4FE1\u606F\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u7D20\u6750 ID\u3001\u8BBF\u95EE\u6743\u9650\u53CA\u670D\u52A1\u72B6\u6001");
5298
+ }
5299
+ }
5300
+ function materialAccessUrl(resourceUrl, previewSas = "") {
5301
+ const url = new URL(resourceUrl);
5302
+ if (!url.searchParams.has("sig")) {
5303
+ const sas = new URLSearchParams(previewSas.replace(/^[?&]/, ""));
5304
+ for (const [key, value] of sas) url.searchParams.set(key, value);
5305
+ }
5306
+ return url.href;
5307
+ }
5308
+
5309
+ // src/utils/cover-validation.ts
5310
+ var MAX_BYTES = 10 * 1024 * 1024;
5311
+ var TIMEOUT_MS = 15e3;
5312
+ var MAX_REDIRECTS = 3;
5313
+ var GUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
5314
+ function imageUrl(value) {
5315
+ let url;
5316
+ try {
5317
+ url = new URL(value);
5318
+ } catch {
5319
+ throw new Error("\u5C01\u9762\u5730\u5740\u4E0D\u662F\u6709\u6548\u7684 HTTP(S) URL");
5320
+ }
5321
+ if (!["http:", "https:"].includes(url.protocol) || url.username || url.password) {
5322
+ throw new Error("\u5C01\u9762\u5730\u5740\u5FC5\u987B\u662F\u65E0\u7528\u6237\u540D\u5BC6\u7801\u7684 HTTP(S) URL");
5323
+ }
5324
+ return url;
5325
+ }
5326
+ function readImageResponse(url, maxBytes, deadline) {
5327
+ return new Promise((resolve10, reject) => {
5328
+ const transport = url.protocol === "https:" ? https2 : http2;
5329
+ const request = transport.get(url, { headers: { Accept: "image/*" } }, (response) => {
5330
+ const status = response.statusCode ?? 0;
5331
+ const contentType = (response.headers["content-type"] ?? "").split(";", 1)[0].trim().toLowerCase();
5332
+ const location = response.headers.location;
5333
+ if (status < 200 || status >= 300) {
5334
+ clearTimeout(timer);
5335
+ response.destroy();
5336
+ resolve10({ status, contentType, location, body: Buffer.alloc(0) });
5337
+ return;
5338
+ }
5339
+ if (!contentType.startsWith("image/")) {
5340
+ clearTimeout(timer);
5341
+ response.destroy();
5342
+ reject(new Error("\u5C01\u9762\u8FD4\u56DE\u7684\u5185\u5BB9\u4E0D\u662F\u56FE\u7247\uFF08\u53EF\u80FD\u662F JSON \u9519\u8BEF\u6216\u767B\u5F55\u9875\u9762\uFF09"));
5343
+ return;
5344
+ }
5345
+ if (Number(response.headers["content-length"]) > maxBytes) {
5346
+ clearTimeout(timer);
5347
+ response.destroy();
5348
+ reject(new Error("\u5C01\u9762\u56FE\u7247\u8D85\u8FC7\u5927\u5C0F\u4E0A\u9650"));
5349
+ return;
5350
+ }
5351
+ const chunks = [];
5352
+ let size = 0;
5353
+ response.on("data", (chunk) => {
5354
+ size += chunk.length;
5355
+ if (size > maxBytes) {
5356
+ clearTimeout(timer);
5357
+ reject(new Error("\u5C01\u9762\u56FE\u7247\u8D85\u8FC7\u5927\u5C0F\u4E0A\u9650"));
5358
+ response.destroy();
5359
+ return;
5360
+ }
5361
+ chunks.push(chunk);
5362
+ });
5363
+ response.on("error", () => {
5364
+ clearTimeout(timer);
5365
+ reject(new Error("\u5C01\u9762\u56FE\u7247\u8BFB\u53D6\u5931\u8D25"));
5366
+ });
5367
+ response.on("aborted", () => {
5368
+ clearTimeout(timer);
5369
+ reject(new Error("\u5C01\u9762\u56FE\u7247\u8BFB\u53D6\u4E2D\u65AD"));
5370
+ });
5371
+ response.on("end", () => {
5372
+ clearTimeout(timer);
5373
+ resolve10({ status, contentType, body: Buffer.concat(chunks) });
5374
+ });
5375
+ });
5376
+ const timer = setTimeout(
5377
+ () => {
5378
+ reject(new Error("\u5C01\u9762\u56FE\u7247\u8BFB\u53D6\u8D85\u65F6"));
5379
+ request.destroy();
5380
+ },
5381
+ Math.max(1, deadline - Date.now())
5382
+ );
5383
+ request.on("error", () => {
5384
+ clearTimeout(timer);
5385
+ reject(new Error("\u5C01\u9762\u56FE\u7247\u8BF7\u6C42\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u5730\u5740\u548C\u7F51\u7EDC"));
5386
+ });
5387
+ });
5388
+ }
5389
+ async function validateCoverImageUrl(value, limits = {}) {
5390
+ let url = imageUrl(value);
5391
+ const deadline = Date.now() + (limits.timeoutMs ?? TIMEOUT_MS);
5392
+ for (let redirects = 0; ; redirects++) {
5393
+ const response = await readImageResponse(url, limits.maxBytes ?? MAX_BYTES, deadline);
5394
+ if ([301, 302, 303, 307, 308].includes(response.status)) {
5395
+ if (!response.location || redirects >= MAX_REDIRECTS) {
5396
+ throw new Error("\u5C01\u9762\u5730\u5740\u91CD\u5B9A\u5411\u8FC7\u591A\u6216\u65E0\u6709\u6548\u76EE\u6807");
5397
+ }
5398
+ url = imageUrl(new URL(response.location, url).href);
5399
+ continue;
5400
+ }
5401
+ if (response.status < 200 || response.status >= 300) {
5402
+ throw new Error(`\u5C01\u9762\u56FE\u7247\u8BF7\u6C42\u5931\u8D25\uFF08HTTP ${response.status}\uFF09`);
5403
+ }
5404
+ try {
5405
+ const { width, height } = imageSize(response.body);
5406
+ if (!Number.isFinite(width) || !Number.isFinite(height) || width <= 0 || height <= 0) {
5407
+ throw new Error("Invalid dimensions");
5408
+ }
5409
+ return { width, height, size: response.body.length };
5410
+ } catch {
5411
+ throw new Error("\u5C01\u9762\u5185\u5BB9\u65E0\u6CD5\u8BC6\u522B\u4E3A\u6709\u6548\u56FE\u7247\uFF0C\u6216\u56FE\u7247\u5C3A\u5BF8\u65E0\u6548");
5412
+ }
5413
+ }
5414
+ }
5415
+ async function resolveCover(cover, videoId, config) {
5416
+ if (cover.imageSourceType === 0) {
5417
+ const dimensions2 = await validateCoverImageUrl(cover.imageUrl);
5418
+ return { imageUrl: cover.imageUrl, ...dimensions2 };
5419
+ }
5420
+ if (cover.imageSourceType !== 1 && cover.imageSourceType !== 2) {
5421
+ throw new Error("\u5C01\u9762 imageSourceType \u5FC5\u987B\u662F 0\u30011 \u6216 2");
5422
+ }
5423
+ const id = cover.sourceImageId ?? (cover.imageSourceType === 1 ? videoId : "");
5424
+ if (!GUID.test(id))
5425
+ throw new Error("\u7D20\u6750\u5C01\u9762\u9700\u8981\u6B63\u786E\u7684 sourceImageId\uFF08\u56FE\u7247\u7C7B\u578B 2 \u4E0D\u80FD\u56DE\u843D\u5230\u89C6\u9891 ID\uFF09");
5426
+ const material = await fetchMaterialInfo(config, id);
5427
+ const expectedType = cover.imageSourceType === 2 ? 1 : 3;
5428
+ if (material.type !== expectedType) {
5429
+ throw new Error(
5430
+ cover.imageSourceType === 1 && material.type === 1 ? "\u5C01\u9762\u7D20\u6750\u662F\u56FE\u7247\uFF0C\u8BF7\u5C06 imageSourceType \u8BBE\u7F6E\u4E3A 2\uFF0C\u4E0D\u80FD\u6309\u89C6\u9891\u622A\u5E27\u5904\u7406" : "\u5C01\u9762\u6765\u6E90\u7C7B\u578B\u4E0E\u7D20\u6750\u7C7B\u578B\u4E0D\u4E00\u81F4\uFF0C\u8BF7\u6838\u5BF9 sourceImageId"
5431
+ );
5432
+ }
5433
+ const resource = cover.imageSourceType === 2 ? material.url : material.thumbUrl || cover.imageUrl;
5434
+ if (!resource) throw new Error("\u5C01\u9762\u7D20\u6750\u6CA1\u6709\u53EF\u7528\u7684\u56FE\u7247\u5730\u5740");
5435
+ const resolvedUrl = cover.imageSourceType === 1 && !material.thumbUrl ? resource : materialAccessUrl(resource, material.previewSas);
5436
+ const dimensions = await validateCoverImageUrl(resolvedUrl);
5437
+ return {
5438
+ imageUrl: resolvedUrl,
5439
+ sourceImageId: id,
5440
+ imageCreateUserId: material.userId ?? cover.imageCreateUserId,
5441
+ belongTo: material.belongTo ?? cover.belongTo,
5442
+ belongToId: material.belongToId ?? cover.belongToId,
5443
+ ...dimensions
5444
+ };
5445
+ }
5446
+ async function prepareVideoCovers(videos, config) {
5447
+ const checks = /* @__PURE__ */ new Map();
5448
+ for (const video of videos) {
5449
+ const covers = /* @__PURE__ */ new Set([video.cover]);
5450
+ for (const account of video.accounts) {
5451
+ const override = video.platformOverrides?.[account.mediaAccountType]?.cover;
5452
+ if (override) covers.add(override);
5453
+ }
5454
+ for (const cover of covers) {
5455
+ const source = cover.imageSourceType === 0 ? cover.imageUrl : cover.sourceImageId ?? (cover.imageSourceType === 1 ? video.videoId : "");
5456
+ const key = `${cover.imageSourceType}:${source}`;
5457
+ let check = checks.get(key);
5458
+ if (!check) {
5459
+ check = resolveCover(cover, video.videoId, config);
5460
+ checks.set(key, check);
5461
+ }
5462
+ Object.assign(cover, await check);
5463
+ }
5464
+ }
5465
+ return checks.size;
5466
+ }
5467
+
5468
+ // src/commands/publish/commands.ts
5186
5469
  async function runPublish(options) {
5187
5470
  const configPath = path8.resolve(options.config);
5188
5471
  if (!fs8.existsSync(configPath)) {
@@ -5241,6 +5524,21 @@ async function runPublish(options) {
5241
5524
  errorList.forEach((e) => console.error(` \xB7 ${e}`));
5242
5525
  process.exit(1);
5243
5526
  }
5527
+ if (input.contentType === 1 && input.videos) {
5528
+ try {
5529
+ await prepareVideoCovers(input.videos, config);
5530
+ } catch (error) {
5531
+ console.error(
5532
+ `
5533
+ \u274C \u5C01\u9762\u6821\u9A8C\u5931\u8D25\uFF1A${error instanceof Error ? error.message : "\u65E0\u6CD5\u8BFB\u53D6\u6709\u6548\u56FE\u7247"}`
5534
+ );
5535
+ process.exit(1);
5536
+ }
5537
+ ({ channels, videoType, contents } = buildVideoChannels(
5538
+ input.videos,
5539
+ currentUserId
5540
+ ));
5541
+ }
5244
5542
  const body = {
5245
5543
  contents: JSON.stringify(contents),
5246
5544
  channels: Object.values(channels),
@@ -5295,7 +5593,7 @@ async function runPublish(options) {
5295
5593
  import * as fs9 from "fs";
5296
5594
  import * as os5 from "os";
5297
5595
  import * as path9 from "path";
5298
- import { imageSize } from "image-size";
5596
+ import { imageSize as imageSize2 } from "image-size";
5299
5597
  import { ContainerClient } from "@azure/storage-blob";
5300
5598
  var SENSITIVE_PATH_PREFIXES = [
5301
5599
  path9.join(os5.homedir(), ".siluzan"),
@@ -5429,15 +5727,6 @@ async function notifyUploaded(config, body, verbose = false) {
5429
5727
  }
5430
5728
  return res.data.id;
5431
5729
  }
5432
- async function fetchMaterialInfo(config, id, verbose = false) {
5433
- try {
5434
- const url = `${config.csoBaseUrl}/cutapi/v1/material/${id}`;
5435
- const res = await apiFetch2(url, config, {}, verbose);
5436
- return res.data ?? {};
5437
- } catch {
5438
- return {};
5439
- }
5440
- }
5441
5730
  function readMp4Duration(filePath) {
5442
5731
  try {
5443
5732
  const fileSize = fs9.statSync(filePath).size;
@@ -5484,7 +5773,7 @@ function parseMvhdFromBuffer(buf) {
5484
5773
  function readImageDimensions(filePath) {
5485
5774
  try {
5486
5775
  const buf = fs9.readFileSync(filePath);
5487
- const dim = imageSize(buf);
5776
+ const dim = imageSize2(buf);
5488
5777
  return { width: dim.width, height: dim.height, format: (dim.type ?? "").toUpperCase() };
5489
5778
  } catch {
5490
5779
  return { width: 0, height: 0 };
@@ -5494,9 +5783,10 @@ async function uploadImageFile(filePath, config, verbose = false) {
5494
5783
  const fileName = path9.basename(filePath);
5495
5784
  const fileSize = fs9.statSync(filePath).size;
5496
5785
  const format = path9.extname(filePath).replace(".", "").toUpperCase();
5786
+ const dim = readImageDimensions(filePath);
5787
+ if (!dim.width || !dim.height) throw new Error("\u5C01\u9762\u6587\u4EF6\u4E0D\u662F\u6709\u6548\u56FE\u7247\uFF0C\u65E0\u6CD5\u8BFB\u53D6\u56FE\u7247\u5C3A\u5BF8");
5497
5788
  const sas = await generateSas(config, verbose);
5498
5789
  const { resourceUrl } = await uploadToAzure(filePath, sas, void 0);
5499
- const dim = readImageDimensions(filePath);
5500
5790
  const materialId = await notifyUploaded(
5501
5791
  config,
5502
5792
  {
@@ -5514,8 +5804,15 @@ async function uploadImageFile(filePath, config, verbose = false) {
5514
5804
  verbose
5515
5805
  );
5516
5806
  const matInfo = await fetchMaterialInfo(config, materialId, verbose);
5807
+ if (matInfo.type !== 1) throw new Error("\u4E0A\u4F20\u540E\u7684\u5C01\u9762\u7D20\u6750\u7C7B\u578B\u4E0D\u662F\u56FE\u7247");
5808
+ const accessUrl = materialAccessUrl(
5809
+ matInfo.url || resourceUrl,
5810
+ matInfo.previewSas || sas.sasToken
5811
+ );
5812
+ await validateCoverImageUrl(accessUrl);
5517
5813
  return {
5518
5814
  resourceUrl,
5815
+ accessUrl,
5519
5816
  materialId,
5520
5817
  belongToId: matInfo?.belongToId,
5521
5818
  belongTo: matInfo?.belongTo,
@@ -5552,6 +5849,7 @@ async function runUpload(options) {
5552
5849
  \u{1F4C1} \u51C6\u5907\u4E0A\u4F20${kind === "video" ? "\u89C6\u9891" : "\u56FE\u7247"}\uFF1A${fileName}`);
5553
5850
  console.log(` \u5927\u5C0F\uFF1A${(fileSize / 1024 / 1024).toFixed(2)} MB`);
5554
5851
  let thumbUrl = "";
5852
+ let coverAccessUrl = "";
5555
5853
  let coverMaterialId = "";
5556
5854
  let coverBelongToId;
5557
5855
  let coverBelongTo;
@@ -5575,6 +5873,7 @@ async function runUpload(options) {
5575
5873
  try {
5576
5874
  const coverResult = await uploadImageFile(coverPath, config, verbose);
5577
5875
  thumbUrl = coverResult.resourceUrl;
5876
+ coverAccessUrl = coverResult.accessUrl;
5578
5877
  coverMaterialId = coverResult.materialId;
5579
5878
  coverBelongToId = coverResult.belongToId;
5580
5879
  coverBelongTo = coverResult.belongTo;
@@ -5659,7 +5958,7 @@ async function runUpload(options) {
5659
5958
  console.log("4\uFE0F\u20E3 \u83B7\u53D6\u7D20\u6750\u4FE1\u606F \u2026");
5660
5959
  const matInfo = await fetchMaterialInfo(config, materialId, verbose);
5661
5960
  const previewSas = matInfo?.previewSas ?? "";
5662
- const coverUrl = matInfo?.thumbUrl && previewSas ? `${matInfo.thumbUrl}?${previewSas}` : thumbUrl;
5961
+ const coverUrl = coverAccessUrl;
5663
5962
  const accessUrl = previewSas ? `${resourceUrl}?${previewSas}` : `${resourceUrl}?${sas.sasToken}`;
5664
5963
  console.log(`
5665
5964
  \u2705 \u4E0A\u4F20\u6210\u529F\uFF01`);
@@ -5676,7 +5975,7 @@ async function runUpload(options) {
5676
5975
  cover: {
5677
5976
  imageUrl: verbose ? coverUrl || "\uFF08\u8BF7\u624B\u52A8\u586B\u5199\u5C01\u9762\u56FE\u7247 URL\uFF09" : thumbUrl,
5678
5977
  imageName: options.cover ? path10.basename(options.cover) : "cover.jpg",
5679
- imageSourceType: 1,
5978
+ imageSourceType: 2,
5680
5979
  sourceImageId: coverMaterialId || void 0,
5681
5980
  imageCreateUserId: coverUserId || void 0,
5682
5981
  belongTo: coverBelongTo !== void 0 ? coverBelongTo : -1,
@@ -6568,11 +6867,11 @@ async function runReportFetch(options) {
6568
6867
  }
6569
6868
  function parsePositiveInt(value, optionName, defaultValue) {
6570
6869
  if (!value) return defaultValue;
6571
- const num = Number(value);
6572
- if (!Number.isInteger(num) || num <= 0) {
6870
+ const num2 = Number(value);
6871
+ if (!Number.isInteger(num2) || num2 <= 0) {
6573
6872
  exitWithError(`${optionName} \u5FC5\u987B\u662F\u6B63\u6574\u6570\uFF0C\u6536\u5230\uFF1A${value}`);
6574
6873
  }
6575
- return num;
6874
+ return num2;
6576
6875
  }
6577
6876
  function renderRecordTable(list, unicode = false) {
6578
6877
  if (list.length === 0) {
@@ -6676,6 +6975,247 @@ async function runReportDownload(options) {
6676
6975
  `);
6677
6976
  }
6678
6977
 
6978
+ // src/commands/report/period.ts
6979
+ var DOMESTIC_MEDIA = {
6980
+ Douyin: "Douyin",
6981
+ Kuaishou: "Kuaishou",
6982
+ Kwai: "Kuaishou",
6983
+ Wechat: "WeChatChannel",
6984
+ WeChat: "WeChatChannel",
6985
+ WeChatChannel: "WeChatChannel"
6986
+ };
6987
+ var FOREIGN_MEDIA = /* @__PURE__ */ new Set([
6988
+ "TikTokBusinessAccount",
6989
+ "YouTube",
6990
+ "Facebook",
6991
+ "Instagram",
6992
+ "Linkedin"
6993
+ ]);
6994
+ var MEDIA_HINT = "\u5916\u8D38\uFF1AYouTube\u3001TikTokBusinessAccount\u3001Facebook\u3001Instagram\u3001Linkedin\u3002\u5185\u8D38\uFF1ADouyin\u3001Kuaishou\u3001Wechat\u3002\u4E0D\u4F20 --media \u65F6\u9ED8\u8BA4\u5916\u8D38\u5168\u90E8\u8D26\u53F7\uFF0C\u52A0 --domestic \u5219\u67E5\u5185\u8D38\u5168\u90E8\u8D26\u53F7\u3002";
6995
+ function resolvePeriodScope(media, domestic) {
6996
+ const name = media?.trim();
6997
+ if (!name) {
6998
+ return { csoPlatformType: domestic ? 1 : 2 };
6999
+ }
7000
+ const domesticType = DOMESTIC_MEDIA[name];
7001
+ if (domesticType) {
7002
+ return { csoPlatformType: 1, mediaType: domesticType };
7003
+ }
7004
+ if (FOREIGN_MEDIA.has(name)) {
7005
+ if (domestic) {
7006
+ return {
7007
+ csoPlatformType: 2,
7008
+ error: `${name} \u5C5E\u4E8E\u5916\u8D38\u8D26\u53F7\u6570\u636E\uFF0C\u4E0D\u8981\u52A0 --domestic\u3002`
7009
+ };
7010
+ }
7011
+ return { csoPlatformType: 2, mediaType: name };
7012
+ }
7013
+ if (name === "Twitter") {
7014
+ return {
7015
+ csoPlatformType: 2,
7016
+ error: `\u8D26\u53F7\u6570\u636E\u672C\u671F\u4E0D\u542B Twitter\u3002${MEDIA_HINT}`
7017
+ };
7018
+ }
7019
+ return { csoPlatformType: 2, error: `\u4E0D\u652F\u6301\u7684\u5A92\u4F53\uFF1A${name}\u3002${MEDIA_HINT}` };
7020
+ }
7021
+ function periodUnixRange(input) {
7022
+ if (input.start || input.end) {
7023
+ if (!input.start || !input.end) {
7024
+ return { error: "--start \u548C --end \u9700\u8981\u4E00\u8D77\u4F20\uFF0C\u683C\u5F0F YYYY-MM-DD\u3002" };
7025
+ }
7026
+ const start2 = utcDay(input.start, "start");
7027
+ const end2 = utcDay(input.end, "end");
7028
+ if ("error" in start2) return start2;
7029
+ if ("error" in end2) return end2;
7030
+ if (start2.sec > end2.sec) return { error: "--start \u4E0D\u80FD\u665A\u4E8E --end" };
7031
+ return { start: start2.sec, end: end2.sec };
7032
+ }
7033
+ const days = input.days && input.days > 0 ? input.days : 7;
7034
+ const now = input.now ?? /* @__PURE__ */ new Date();
7035
+ const end = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() - 1, 23, 59, 59);
7036
+ const start = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() - days);
7037
+ return { start: Math.floor(start / 1e3), end: Math.floor(end / 1e3) };
7038
+ }
7039
+ function utcDay(value, kind) {
7040
+ const matched = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value.trim());
7041
+ if (!matched) return { error: `\u65E5\u671F\u683C\u5F0F\u4E0D\u5408\u6CD5\uFF1A${value}\u3002\u8BF7\u4F7F\u7528 YYYY-MM-DD\u3002` };
7042
+ const year = Number(matched[1]);
7043
+ const month = Number(matched[2]);
7044
+ const day = Number(matched[3]);
7045
+ const sec = kind === "start" ? Math.floor(Date.UTC(year, month - 1, day) / 1e3) : Math.floor(Date.UTC(year, month - 1, day, 23, 59, 59) / 1e3);
7046
+ if (!Number.isFinite(sec)) return { error: `\u65E5\u671F\u683C\u5F0F\u4E0D\u5408\u6CD5\uFF1A${value}\u3002\u8BF7\u4F7F\u7528 YYYY-MM-DD\u3002` };
7047
+ return { sec };
7048
+ }
7049
+ function num(value) {
7050
+ return value ?? 0;
7051
+ }
7052
+ function viewsHidden(mediaType) {
7053
+ return mediaType === "Instagram";
7054
+ }
7055
+ function periodCards(summary, content, mediaType) {
7056
+ const row = summary ?? {};
7057
+ const hidden = viewsHidden(mediaType);
7058
+ const fans = { name: "\u672C\u671F\u7C89\u4E1D\u6570", value: num(row.newFans) };
7059
+ const post = [
7060
+ { name: "\u672C\u671F\u5E16\u6587\u6570", value: num(row.newPost) },
7061
+ fans,
7062
+ { name: "\u672C\u671F\u9605\u8BFB\u6570", value: hidden ? null : num(row.newPostViews) },
7063
+ { name: "\u672C\u671F\u83B7\u8D5E\u6570", value: num(row.newPostLike) },
7064
+ { name: "\u672C\u671F\u8BC4\u8BBA\u6570", value: num(row.newPostComment) },
7065
+ { name: "\u672C\u671F\u5206\u4EAB\u6570", value: num(row.newPostShare) }
7066
+ ];
7067
+ const video = [
7068
+ { name: "\u672C\u671F\u89C6\u9891\u6570", value: num(row.newVideo) },
7069
+ fans,
7070
+ { name: "\u672C\u671F\u64AD\u653E\u91CF", value: hidden ? null : num(row.newPlay) },
7071
+ { name: "\u672C\u671F\u83B7\u8D5E\u6570", value: num(row.newLike) },
7072
+ { name: "\u672C\u671F\u8BC4\u8BBA\u6570", value: num(row.newComment) },
7073
+ { name: "\u672C\u671F\u5206\u4EAB\u6570", value: num(row.newShare) }
7074
+ ];
7075
+ if (content === "post") return post;
7076
+ if (content === "video") return video;
7077
+ return [
7078
+ { name: "\u8D26\u53F7\u6570", value: num(row.accountNum) },
7079
+ { name: "\u672C\u671F\u7C89\u4E1D\u6570", value: num(row.newFans) },
7080
+ { name: "\u672C\u671F\u5E16\u6587\u6570", value: num(row.newPost) },
7081
+ { name: "\u672C\u671F\u9605\u8BFB\u6570", value: hidden ? null : num(row.newPostViews) },
7082
+ { name: "\u672C\u671F\u5E16\u6587\u83B7\u8D5E\u6570", value: num(row.newPostLike) },
7083
+ { name: "\u672C\u671F\u5E16\u6587\u8BC4\u8BBA\u6570", value: num(row.newPostComment) },
7084
+ { name: "\u672C\u671F\u5E16\u6587\u5206\u4EAB\u6570", value: num(row.newPostShare) },
7085
+ { name: "\u672C\u671F\u89C6\u9891\u6570", value: num(row.newVideo) },
7086
+ { name: "\u672C\u671F\u64AD\u653E\u91CF", value: hidden ? null : num(row.newPlay) },
7087
+ { name: "\u672C\u671F\u89C6\u9891\u83B7\u8D5E\u6570", value: num(row.newLike) },
7088
+ { name: "\u672C\u671F\u89C6\u9891\u8BC4\u8BBA\u6570", value: num(row.newComment) },
7089
+ { name: "\u672C\u671F\u89C6\u9891\u5206\u4EAB\u6570", value: num(row.newShare) }
7090
+ ];
7091
+ }
7092
+ function ensurePeriodContent(value) {
7093
+ if (!value || value === "both") return "both";
7094
+ if (value === "post" || value === "video") return value;
7095
+ exitWithError("--content \u4EC5\u652F\u6301 post / video / both\uFF0C\u6536\u5230\uFF1A" + value);
7096
+ }
7097
+ function showValue(value) {
7098
+ return value == null ? "\u2014" : String(value);
7099
+ }
7100
+ async function runReportPeriod(options) {
7101
+ const scope = resolvePeriodScope(options.media, Boolean(options.domestic));
7102
+ if (scope.error) exitWithError(scope.error);
7103
+ const range = periodUnixRange(options);
7104
+ if ("error" in range) exitWithError(range.error);
7105
+ const content = ensurePeriodContent(options.content);
7106
+ const maids = parseMediaCustomerIds(options.maids);
7107
+ const config = loadConfig(options.token);
7108
+ const query = {
7109
+ csoPlatformType: scope.csoPlatformType,
7110
+ start: range.start,
7111
+ end: range.end
7112
+ };
7113
+ if (maids.length > 0) query.maids = maids.join(",");
7114
+ if (scope.mediaType) query.mediaType = scope.mediaType;
7115
+ let data;
7116
+ try {
7117
+ const url = `${config.csoBaseUrl}/cso/v1/accountData/GetIncrementalData?${createQueryString(query)}`;
7118
+ const res = await apiFetch2(url, config, {}, Boolean(options.verbose));
7119
+ if (res.code !== 1) throw new Error(res.message || "\u670D\u52A1\u7AEF\u8FD4\u56DE\u5F02\u5E38");
7120
+ data = res.data;
7121
+ } catch (error) {
7122
+ exitWithError(`\u67E5\u8BE2\u672C\u671F\u8D26\u53F7\u6570\u636E\u5931\u8D25\uFF1A${error.message}`);
7123
+ }
7124
+ const cards = periodCards(data?.summary, content, scope.mediaType);
7125
+ const accounts = data?.accounts ?? [];
7126
+ const payload = {
7127
+ kind: "account-period",
7128
+ note: "\u6240\u9009\u65E5\u671F\u5185\u7684\u589E\u91CF\u3002\u4E0D\u662F list-accounts overview \u91CC\u7684\u7D2F\u8BA1\u603B\u6570\u3002",
7129
+ content,
7130
+ query,
7131
+ cards,
7132
+ summary: data?.summary ?? null,
7133
+ accounts,
7134
+ items: data?.items ?? []
7135
+ };
7136
+ if (options.jsonOut) {
7137
+ await emitCliJsonOrSnapshot(
7138
+ { jsonOut: options.jsonOut },
7139
+ {
7140
+ section: "report-period",
7141
+ commandLabel: "report period",
7142
+ payload,
7143
+ commandHint: scope.mediaType,
7144
+ idSuffix: scope.mediaType
7145
+ }
7146
+ );
7147
+ return;
7148
+ }
7149
+ console.log("\n\u672C\u671F\u8868\u73B0\uFF08\u65E5\u671F\u5185\u589E\u91CF\uFF0C\u4E0D\u662F\u8D26\u53F7\u7D2F\u8BA1\u603B\u6570\uFF09");
7150
+ if (viewsHidden(scope.mediaType)) {
7151
+ console.log("Instagram \u7684\u9605\u8BFB\u6570\u548C\u64AD\u653E\u91CF\u63A5\u53E3\u4E0D\u8FD4\u56DE\uFF0C\u8FD9\u4E24\u9879\u663E\u793A\u4E3A \u2014\u3002");
7152
+ }
7153
+ printCliTable(
7154
+ cards.map((card) => ({ name: card.name, value: showValue(card.value) })),
7155
+ [
7156
+ { key: "name", header: "\u6307\u6807" },
7157
+ { key: "value", header: "\u672C\u671F" }
7158
+ ],
7159
+ options.unicode ? { plain: false } : void 0
7160
+ );
7161
+ if (accounts.length === 0) {
7162
+ console.log("\u8FD9\u6BB5\u65E5\u671F\u6CA1\u6709\u6309\u8D26\u53F7\u62C6\u5F00\u7684\u589E\u91CF\u8BB0\u5F55\u3002\n");
7163
+ return;
7164
+ }
7165
+ const columns = accountColumns(content);
7166
+ printCliTable(
7167
+ accounts.map((account) => accountRow(account, content, scope.mediaType)),
7168
+ columns,
7169
+ options.unicode ? { plain: false } : void 0
7170
+ );
7171
+ const noted = accounts.filter((account) => account.syncNote);
7172
+ for (const account of noted) {
7173
+ console.log(`${account.mediaCustomerId}\uFF1A${account.syncNote}`);
7174
+ }
7175
+ console.log();
7176
+ }
7177
+ function accountColumns(content) {
7178
+ const base = [{ key: "mediaCustomerId", header: "\u8D26\u53F7ID" }];
7179
+ if (content !== "video") {
7180
+ base.push(
7181
+ { key: "newPost", header: "\u672C\u671F\u5E16\u6587\u6570" },
7182
+ { key: "newPostViews", header: "\u672C\u671F\u9605\u8BFB\u6570" },
7183
+ { key: "newPostLike", header: content === "both" ? "\u672C\u671F\u5E16\u6587\u83B7\u8D5E\u6570" : "\u672C\u671F\u83B7\u8D5E\u6570" },
7184
+ { key: "newPostComment", header: content === "both" ? "\u672C\u671F\u5E16\u6587\u8BC4\u8BBA\u6570" : "\u672C\u671F\u8BC4\u8BBA\u6570" }
7185
+ );
7186
+ }
7187
+ if (content !== "post") {
7188
+ base.push(
7189
+ { key: "newVideo", header: "\u672C\u671F\u89C6\u9891\u6570" },
7190
+ { key: "newPlay", header: "\u672C\u671F\u64AD\u653E\u91CF" },
7191
+ { key: "newLike", header: content === "both" ? "\u672C\u671F\u89C6\u9891\u83B7\u8D5E\u6570" : "\u672C\u671F\u83B7\u8D5E\u6570" },
7192
+ { key: "newComment", header: content === "both" ? "\u672C\u671F\u89C6\u9891\u8BC4\u8BBA\u6570" : "\u672C\u671F\u8BC4\u8BBA\u6570" }
7193
+ );
7194
+ }
7195
+ base.push({ key: "newFans", header: "\u672C\u671F\u7C89\u4E1D\u6570" });
7196
+ return base;
7197
+ }
7198
+ function accountRow(account, content, mediaType) {
7199
+ const hidden = viewsHidden(mediaType);
7200
+ const row = {
7201
+ mediaCustomerId: account.mediaCustomerId || "-",
7202
+ newFans: String(num(account.newFans))
7203
+ };
7204
+ if (content !== "video") {
7205
+ row.newPost = String(num(account.newPost));
7206
+ row.newPostViews = hidden ? "\u2014" : String(num(account.newPostViews));
7207
+ row.newPostLike = String(num(account.newPostLike));
7208
+ row.newPostComment = String(num(account.newPostComment));
7209
+ }
7210
+ if (content !== "post") {
7211
+ row.newVideo = String(num(account.newVideo));
7212
+ row.newPlay = hidden ? "\u2014" : String(num(account.newPlay));
7213
+ row.newLike = String(num(account.newLike));
7214
+ row.newComment = String(num(account.newComment));
7215
+ }
7216
+ return row;
7217
+ }
7218
+
6679
7219
  // src/commands/planning/_shared.ts
6680
7220
  var TOPIC_FOLDER_ID = "88888888-8888-8888-0000-888888888888";
6681
7221
  var DEFAULT_CONTENT_TYPES = [
@@ -6726,11 +7266,11 @@ function createQueryString2(query) {
6726
7266
  }
6727
7267
  function parsePositiveInt2(value, optionName, defaultValue) {
6728
7268
  if (!value) return defaultValue;
6729
- const num = Number(value);
6730
- if (!Number.isInteger(num) || num <= 0) {
7269
+ const num2 = Number(value);
7270
+ if (!Number.isInteger(num2) || num2 <= 0) {
6731
7271
  exitWithError2(`${optionName} \u5FC5\u987B\u662F\u6B63\u6574\u6570\uFF0C\u6536\u5230\uFF1A${value}`);
6732
7272
  }
6733
- return num;
7273
+ return num2;
6734
7274
  }
6735
7275
  function parseTimeoutMs(value, defaultValueMs) {
6736
7276
  if (!value) return defaultValueMs;
@@ -6776,11 +7316,11 @@ function ensureTargetMarkets(input) {
6776
7316
  return uniq;
6777
7317
  }
6778
7318
  function ensurePartnershipTotalMonths(value) {
6779
- const num = value ? Number(value) : 12;
6780
- if (num !== 6 && num !== 12 && num !== 24) {
7319
+ const num2 = value ? Number(value) : 12;
7320
+ if (num2 !== 6 && num2 !== 12 && num2 !== 24) {
6781
7321
  exitWithError2(`--partnership-total-months \u4EC5\u652F\u6301 6 / 12 / 24\uFF0C\u6536\u5230\uFF1A${value}`);
6782
7322
  }
6783
- return num;
7323
+ return num2;
6784
7324
  }
6785
7325
  function ensureFrequency(freqUnit, freqCountRaw) {
6786
7326
  if (!freqUnit && !freqCountRaw) return void 0;
@@ -9260,6 +9800,23 @@ function registerCsoCommands(program2) {
9260
9800
  });
9261
9801
  }
9262
9802
  );
9803
+ reportCmd.command("period").description("\u8D26\u53F7\u6570\u636E\u672C\u671F\u589E\u91CF\uFF08\u5BF9\u5E94 accountdata \u7684\u672C\u671F\u8868\u73B0\uFF0C\u4E0D\u662F\u7D2F\u8BA1\u603B\u6570\uFF09").option(
9804
+ "--media <mediaType>",
9805
+ "\u5A92\u4F53\u7C7B\u578B\u3002\u5916\u8D38 YouTube / TikTokBusinessAccount / Facebook / Instagram / Linkedin\uFF1B\u5185\u8D38 Douyin / Kuaishou / Wechat\u3002\u4E0D\u4F20\u5219\u67E5\u8BE5\u4E1A\u52A1\u7EBF\u5168\u90E8\u8D26\u53F7"
9806
+ ).option("--domestic", "\u4E0D\u4F20 --media \u65F6\u67E5\u5185\u8D38\u5168\u90E8\u8D26\u53F7\u3002\u9ED8\u8BA4\u67E5\u5916\u8D38", false).option(
9807
+ "--maids <ids...>",
9808
+ "mediaCustomerId\uFF0C\u652F\u6301\u7A7A\u683C\u6216\u9017\u53F7\u5206\u9694\u3002\u4E0D\u4F20\u8868\u793A\u8BE5\u8303\u56F4\u5185\u5168\u90E8\u8D26\u53F7"
9809
+ ).option("--days <n>", "\u8FD1 N \u5929\uFF0C\u4ECE\u6628\u5929\u5F80\u56DE\u7B97\uFF0C\u9ED8\u8BA4 7\u3002\u4F18\u5148\u7EA7\u4F4E\u4E8E --start/--end").option("--start <date>", "\u5F00\u59CB\u65E5\u671F YYYY-MM-DD\uFF08UTC \u65E5\uFF09").option("--end <date>", "\u7ED3\u675F\u65E5\u671F YYYY-MM-DD\uFF08UTC \u65E5\uFF09").option("--content <post|video|both>", "\u5E16\u6587\u3001\u89C6\u9891\u6216\u4E24\u8FB9\u90FD\u51FA\u3002\u9ED8\u8BA4 both", "both").option("-t, --token <token>", "Token\uFF08\u53EF\u9009\uFF1B\u4F18\u5148\u4E8E ~/.siluzan/config.json\uFF09").option(
9810
+ "--json-out <path>",
9811
+ "\u5C06\u672C\u671F\u589E\u91CF\u843D\u76D8\u5230\u76EE\u5F55\u6216 *.json \u6587\u4EF6\uFF0Cstdout \u4EC5\u4E00\u884C\u6458\u8981"
9812
+ ).option("--unicode", "\u4F7F\u7528 Unicode \u7EBF\u6846\u8868\u683C\uFF08\u9ED8\u8BA4 ASCII\uFF09", false).option("--verbose", "\u663E\u793A\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(
9813
+ async (opts) => {
9814
+ await runReportPeriod({
9815
+ ...opts,
9816
+ days: opts.days ? parseInt(opts.days, 10) : void 0
9817
+ });
9818
+ }
9819
+ );
9263
9820
  reportCmd.command("records").description("\u67E5\u8BE2\u8FD0\u8425\u62A5\u8868\u5BFC\u51FA\u8BB0\u5F55\uFF08\u5BF9\u5E94 table \u5BFC\u51FA\u8BB0\u5F55\u5F39\u7A97\uFF09").option("--page <number>", "\u9875\u7801\uFF08\u9ED8\u8BA4 1\uFF09").option("--page-size <number>", "\u6BCF\u9875\u6761\u6570\uFF08\u9ED8\u8BA4 20\uFF09").option("-t, --token <token>", "Token\uFF08\u53EF\u9009\uFF1B\u4F18\u5148\u4E8E ~/.siluzan/config.json\uFF09").option(
9264
9821
  "--json-out <path>",
9265
9822
  "\u5C06\u5B8C\u6574\u5BFC\u51FA\u8BB0\u5F55\u843D\u76D8\u5230\u76EE\u5F55\u6216 *.json \u6587\u4EF6\uFF0Cstdout \u4EC5\u4E00\u884C\u6458\u8981\uFF08\u9632\u5DE5\u5177\u6B7B\u5FAA\u73AF\uFF09"