@lark-apaas/miaoda-cli 0.1.1-alpha.8e75930 → 0.1.1-alpha.ddba836

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.
@@ -351,11 +351,15 @@ async function uploadFile(opts) {
351
351
  // 这里复制到独立 ArrayBuffer 以满足 lib.dom.d.ts 的 BodyInit 约束
352
352
  const ab = body.buffer.slice(body.byteOffset, body.byteOffset + body.byteLength);
353
353
  const uploadStart = Date.now();
354
+ // Content-Disposition 用 attachment + filename 编码原始文件名。TOS 会把这个
355
+ // header 作为对象 metadata 存住,服务端 callback 阶段 HeadObject 读回并解析
356
+ // filename 写入 DB。我们要不传 header,服务端走兜底会把 storage key 当文件名。
354
357
  const res = await fetch(pre.uploadURL, {
355
358
  method: "PUT",
356
359
  headers: {
357
360
  "Content-Type": opts.contentType,
358
361
  "Content-Length": String(opts.fileSize),
362
+ "Content-Disposition": `attachment; filename="${sanitizeFileName(opts.fileName)}"`,
359
363
  },
360
364
  body: ab,
361
365
  });
@@ -388,6 +392,8 @@ async function uploadFile(opts) {
388
392
  ? (metadata.filePath.startsWith("/") ? metadata.filePath : "/" + metadata.filePath)
389
393
  : (opts.remotePath ?? "/" + opts.fileName);
390
394
  const result = {
395
+ // 优先取服务端 ObjectVO.name(来自 PUT 时带的 Content-Disposition),
396
+ // 与后续 file ls / file stat 返回的展示名保持一致;缺失时降级用本地 fileName。
391
397
  file_name: metadata.name ?? opts.fileName,
392
398
  path,
393
399
  size: metadata.metadata?.contentLength ?? opts.fileSize,
@@ -398,6 +404,17 @@ async function uploadFile(opts) {
398
404
  }
399
405
  return result;
400
406
  }
407
+ /**
408
+ * 把文件名清理成可安全放进 Content-Disposition `filename="..."` 的形态。
409
+ * 与 fullstack-plugin 的 sanitizeFileName 行为一致:
410
+ * 1. 去掉对 TOS / 文件系统不友好的字符 [: " \ / * ? < > | , ;]
411
+ * 2. encodeURIComponent 把非 ASCII(中文等)做百分号编码,保证 header 合法
412
+ * 3. 处理后为空时退回 "download_file" 兜底
413
+ */
414
+ function sanitizeFileName(fileName) {
415
+ const illegalChars = /[:"\\/*?<>|,;]/g;
416
+ return encodeURIComponent(fileName.replace(illegalChars, "")) || "download_file";
417
+ }
401
418
  // ── 预签下载 URL ──
402
419
  /**
403
420
  * 获取预签下载 URL。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/miaoda-cli",
3
- "version": "0.1.1-alpha.8e75930",
3
+ "version": "0.1.1-alpha.ddba836",
4
4
  "description": "Miaoda 平台命令行工具,面向 Agent 调用",
5
5
  "type": "commonjs",
6
6
  "bin": {