@lark-apaas/miaoda-cli 0.1.0-alpha.cab2450 → 0.1.0-alpha.d98ea14

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.
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseTimeFilterMs = parseTimeFilterMs;
3
4
  exports.listFiles = listFiles;
4
5
  exports.resolveInputs = resolveInputs;
5
6
  exports.statFile = statFile;
@@ -82,15 +83,56 @@ function buildFilterExpr(opts) {
82
83
  }
83
84
  if (opts.uploadedSince) {
84
85
  // 后端期望毫秒 timestamp(strconv.ParseInt → time.UnixMilli)
85
- const ms = Date.parse(opts.uploadedSince);
86
- if (!Number.isNaN(ms)) {
87
- conds.push({ field: "createdAt", operator: "gte", value: String(ms) });
88
- }
86
+ const ms = parseTimeFilterMs(opts.uploadedSince, "--uploaded-since");
87
+ conds.push({ field: "createdAt", operator: "gte", value: String(ms) });
88
+ }
89
+ if (opts.uploadedUntil) {
90
+ const ms = parseTimeFilterMs(opts.uploadedUntil, "--uploaded-until");
91
+ conds.push({ field: "createdAt", operator: "lte", value: String(ms) });
89
92
  }
90
93
  if (conds.length === 0)
91
94
  return undefined;
92
95
  return { logic: "and", groups: [{ conditions: conds }] };
93
96
  }
97
+ /**
98
+ * 解析时间过滤参数(--uploaded-since / --uploaded-until)的三种输入格式
99
+ * (→ ms timestamp):
100
+ * 1. 相对时间:"30s" / "10m" / "1h" / "2d" / "1w" → 当前时间往前推 N 单位
101
+ * 2. 日期: "2026-04-01" → 按当日 00:00:00 UTC
102
+ * 3. ISO 8601:"2026-04-01T10:00:00Z" → 严格解析(推荐用 Z 结尾标识 UTC)
103
+ *
104
+ * 三种格式都不命中时抛 AppError("ARGS_INVALID"),避免之前 Date.parse=NaN
105
+ * 时静默跳过过滤、用户却以为筛选生效的悄然失败问题。
106
+ *
107
+ * flagName 用于错误信息,调用方传 "--uploaded-since" 或 "--uploaded-until"。
108
+ */
109
+ function parseTimeFilterMs(input, flagName) {
110
+ // 相对时间:<positive int><unit>,单位 s/m/h/d/w
111
+ const RELATIVE = /^(\d+)([smhdw])$/;
112
+ const rel = RELATIVE.exec(input);
113
+ if (rel) {
114
+ const n = parseInt(rel[1], 10);
115
+ if (n <= 0) {
116
+ throw new error_1.AppError("ARGS_INVALID", `${flagName} "${input}" 必须是正整数 + 单位(s / m / h / d / w)`);
117
+ }
118
+ const UNIT_MS = {
119
+ s: 1_000,
120
+ m: 60_000,
121
+ h: 3_600_000,
122
+ d: 86_400_000,
123
+ w: 604_800_000,
124
+ };
125
+ return Date.now() - n * UNIT_MS[rel[2]];
126
+ }
127
+ // 绝对时间:date / ISO 8601。Date.parse 对 "YYYY-MM-DD" 按 UTC 00:00:00 解析,
128
+ // 对带 Z 的 ISO 8601 也直接出 UTC ms。
129
+ const ms = Date.parse(input);
130
+ if (Number.isNaN(ms)) {
131
+ throw new error_1.AppError("ARGS_INVALID", `${flagName} "${input}" 格式无法识别。支持:` +
132
+ `相对时间(如 1h / 2d / 1w)、日期(YYYY-MM-DD)、ISO 8601(如 2026-04-01T10:00:00Z)`);
133
+ }
134
+ return ms;
135
+ }
94
136
  /**
95
137
  * 列出文件:所有过滤下推到后端 FilterExpression,纯精确匹配,无 glob。
96
138
  *
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toAbsolutePath = exports.looksLikePath = exports.resetBucketCache = exports.getDefaultBucketId = exports.resolveInputs = exports.deleteFiles = exports.downloadFile = exports.signDownload = exports.uploadFile = exports.statFile = exports.listFiles = void 0;
3
+ exports.toAbsolutePath = exports.looksLikePath = exports.resetBucketCache = exports.getDefaultBucketId = exports.parseTimeFilterMs = exports.resolveInputs = exports.deleteFiles = exports.downloadFile = exports.signDownload = exports.uploadFile = exports.statFile = exports.listFiles = void 0;
4
4
  var api_1 = require("./api");
5
5
  Object.defineProperty(exports, "listFiles", { enumerable: true, get: function () { return api_1.listFiles; } });
6
6
  Object.defineProperty(exports, "statFile", { enumerable: true, get: function () { return api_1.statFile; } });
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "signDownload", { enumerable: true, get: function
9
9
  Object.defineProperty(exports, "downloadFile", { enumerable: true, get: function () { return api_1.downloadFile; } });
10
10
  Object.defineProperty(exports, "deleteFiles", { enumerable: true, get: function () { return api_1.deleteFiles; } });
11
11
  Object.defineProperty(exports, "resolveInputs", { enumerable: true, get: function () { return api_1.resolveInputs; } });
12
+ Object.defineProperty(exports, "parseTimeFilterMs", { enumerable: true, get: function () { return api_1.parseTimeFilterMs; } });
12
13
  var client_1 = require("./client");
13
14
  Object.defineProperty(exports, "getDefaultBucketId", { enumerable: true, get: function () { return client_1.getDefaultBucketId; } });
14
15
  Object.defineProperty(exports, "resetBucketCache", { enumerable: true, get: function () { return client_1.resetBucketCache; } });
@@ -43,7 +43,8 @@ Examples:
43
43
  .option("--type <mime>", "按 MIME 类型筛选(如 image/png)")
44
44
  .option("--size-gt <size>", "文件大小下限(支持 B / KB / MB / GB)")
45
45
  .option("--size-lt <size>", "文件大小上限(支持 B / KB / MB / GB)")
46
- .option("--uploaded-since <time>", "上传时间下限(ISO 8601 格式)")
46
+ .option("--uploaded-since <time>", "上传时间下限(晚于该时间),支持:相对时间 1h / 2d / 1w;日期 YYYY-MM-DD;ISO 8601 如 2026-04-01T10:00:00Z")
47
+ .option("--uploaded-until <time>", "上传时间上限(早于该时间),支持:相对时间 1h / 2d / 1w;日期 YYYY-MM-DD;ISO 8601 如 2026-04-01T10:00:00Z")
47
48
  .option("--limit <n>", "单次返回上限(正整数,默认 50)", parsePositiveInt, 50)
48
49
  .option("--cursor <token>", "分页游标,从上次响应的 next_cursor 取值")
49
50
  .option("--all", "自动翻页返回全部结果")
@@ -63,7 +64,8 @@ Examples:
63
64
 
64
65
  $ miaoda file ls report.pdf
65
66
  $ miaoda file ls --type image/png --size-gt 1MB
66
- $ miaoda file ls --uploaded-since 2026-04-01
67
+ $ miaoda file ls --uploaded-since 1d # 24 小时内上传
68
+ $ miaoda file ls --uploaded-since 2026-04-01 --uploaded-until 2026-04-30 # 4 月内上传
67
69
  `);
68
70
  fileCmd
69
71
  .command("stat")
@@ -82,6 +82,7 @@ async function handleFileLs(opts) {
82
82
  sizeGt,
83
83
  sizeLt,
84
84
  uploadedSince: opts.uploadedSince,
85
+ uploadedUntil: opts.uploadedUntil,
85
86
  });
86
87
  if ((0, output_1.isJsonMode)()) {
87
88
  (0, output_1.emitPaged)(result.items, result.next_cursor, result.has_more);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/miaoda-cli",
3
- "version": "0.1.0-alpha.cab2450",
3
+ "version": "0.1.0-alpha.d98ea14",
4
4
  "description": "Miaoda 平台命令行工具,面向 Agent 调用",
5
5
  "type": "commonjs",
6
6
  "bin": {