@wszhoho/dsh-file-attachment 0.3.3 → 0.3.4

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/README.md CHANGED
@@ -21,17 +21,17 @@ DeepSeek Harness (dsh) web GUI 插件:在会话输入框中**拖入或 Ctrl+V
21
21
  | 操作 | 行为 |
22
22
  | --- | --- |
23
23
  | 点击**上传按钮(↑)**,在系统文件选择框中**多选**文档/图片 | 与拖入/粘贴同一管线:文档 → 落盘 + 光标插入全部 `@` 路径;图片 → 走既有草稿图片流程;`accept` 限定图片 + 常见文档扩展名,移动端自动弹出文件/拍照选择器 |
24
- | 拖入/粘贴 **文档/代码/配置文件**(非图片,默认 doc·code·config 三类扩展名,如 docx/xlsx/pdf/md/txt/js/json) | 浏览器读全文 → base64 → 宿主落盘 `<会话工作区>/.dsh-file-attachment/<时间戳>-<文件名>` → 光标插入 `@绝对路径`,成功不提示、失败简短 toast |
24
+ | 拖入/粘贴 **文档/代码/配置文件**(非图片,默认 doc·code·config 三类扩展名,如 docx/xlsx/pdf/md/txt/js/json) | 浏览器读全文 → base64 → 宿主落盘 `<会话工作区>/.dsh-file-attachment/<日期>/<文件名>` → 光标插入 `@绝对路径`,成功不提示、失败简短 toast |
25
25
  | 一次拖入/粘贴 **多个文件**(支持多文件) | 批量处理:逐个读取全文 → base64 → 落盘 → 在光标处一次性插入全部 `@` 引用;全部成功不提示,部分失败仅简短提示「N 个已跳过」 |
26
26
  | 拖入 **目录** | 拒绝,toast 提示「不支持拖入目录」,不插入引用 |
27
27
  | 拖入/粘贴 **图片** | 接管后走 dsh 既有草稿图片流程(`addImages`):不落盘、不进文件条、不缩放;输入框未就绪且纯图片时原样交原生 |
28
28
  | 粘贴 **纯文本**(含从地址栏复制的目录路径字符串) | 不改写,完全原生行为 |
29
- | 重复拖入同名文件(同一秒内) | 追加 `-1`、`-2` 序号,绝不覆盖 |
29
+ | 重复拖入同名文件(同一天内) | 追加 `-1`、`-2` 序号,绝不覆盖 |
30
30
  | 单文件 > 50MB | 跳过并提示 |
31
31
 
32
32
  ### 文件命名
33
33
 
34
- `<时间戳>-<清洗后文件名>`,例如 `2026-02-11T15-04-05-说明.docx`;时间戳为 `2026-02-11T15-04-05` 格式(去掉冒号/毫秒/Z,各平台文件名安全且可排序)。同名冲突在扩展名前追加 `-N`。
34
+ 日期作为**子目录名**,文件保留原始文件名:`.dsh-file-attachment/<日期>/<清洗后文件名>`,例如 `.dsh-file-attachment/2026-02-11/说明.docx`;日期格式 `YYYY-MM-DD`(ISO 日期前 10 位,各平台安全且可排序)。同一天内同名冲突在扩展名前追加 `-N`。
35
35
 
36
36
  ### 项目根解析
37
37
 
@@ -57,7 +57,7 @@ dsh plugin --profile web add @wszhoho/dsh-file-attachment
57
57
  ### 本地源码安装(开发用,边改边验)
58
58
 
59
59
  ```powershell
60
- # 在仓库父目录执行(<parent> 换成放置仓库的实际目录,如 E:\wszhoho)
60
+ # 在仓库父目录执行(<parent> 换成放置仓库的实际目录)
61
61
  cd <parent>
62
62
  dsh plugin --profile web add ./dsh-file-attachment
63
63
  # ./dsh-file-attachment 相对路径等价 pnpm link;改完 lib/*.js 后重启 dsh web 即生效
@@ -66,7 +66,7 @@ dsh plugin --profile web add ./dsh-file-attachment
66
66
  ### 从 GitHub 安装
67
67
 
68
68
  ```powershell
69
- dsh plugin --profile web add github:<你的账号>/dsh-file-attachment
69
+ dsh plugin --profile web add github:wszhoho/dsh-file-attachment
70
70
  ```
71
71
 
72
72
  - 无论哪种来源,安装后都自动进入 `dsh.profile.bundles`,无需手改 profile `package.json`;
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // @wszhoho/dsh-file-attachment Host 半:webServer HTTP 路由方案(参考 dsh-upload-file 同架构)。
2
2
  // Client 半读取文件全文(base64)后 POST /dsh-file-attachment/save 到这里,
3
- // 写入 <会话工作区根>/.dsh-file-attachment/<时间戳>-<文件名> 并返回 { path, dir, name, size }。
3
+ // 写入 <会话工作区根>/.dsh-file-attachment/<日期>/<文件名>(日期作子目录,文件名保留原始名)并返回 { path, dir, name, size }。
4
4
  // 项目根解析:Client 传 sessionId → sessions.get(sessionId).header.cwd →
5
5
  // sandboxPolicy.workspaceRoot → process.cwd()(三平台绝对路径,Node path.join 自适应分隔符)。
6
6
  // 纯 ESM 无构建:不依赖 TypertRemoteService/装饰器,原生 Node 可直接加载。
@@ -31,9 +31,9 @@ const DEFAULT_TYPES = {
31
31
  config: ['json', 'yml', 'yaml', 'toml', 'ini', 'conf', 'cfg', 'env', 'properties', 'xml', 'html', 'css'],
32
32
  }
33
33
 
34
- /** 时间戳前缀:2026-02-11T15-04-05(去冒号/毫秒/Z,各平台文件名安全且可排序)。 */
34
+ /** 日期前缀:2026-02-11(ISO 日期前 10 位,各平台文件名安全且可排序)。 */
35
35
  function stamp() {
36
- return new Date().toISOString().slice(0, 19).replace(/[:.]/gu, '-')
36
+ return new Date().toISOString().slice(0, 10) // 仅日期 YYYY-MM-DD
37
37
  }
38
38
 
39
39
  async function fileExists(target) {
@@ -178,19 +178,21 @@ async function handleSave(root, body) {
178
178
  if (bytes.length > MAX_BYTES) throw new Error('文件超过 ' + Math.round(MAX_BYTES / 1024 / 1024) + 'MB 上限')
179
179
 
180
180
  const dir = join(root, ATTACHMENT_DIR)
181
- await mkdir(dir, { recursive: true })
182
181
  const safe = cleanName(name)
183
182
  const t = stamp()
183
+ // 时间戳作子目录名,文件保留原始文件名 → 芯片 basename 即原始名,不带时间戳前缀
184
+ const subDir = join(dir, t)
185
+ await mkdir(subDir, { recursive: true })
184
186
  const dot = safe.lastIndexOf('.')
185
187
  const stem = dot > 0 ? safe.slice(0, dot) : safe
186
188
  const ext = dot > 0 ? safe.slice(dot) : ''
187
- // 同一秒内重复保存同名文件时追加序号,避免覆盖
188
- let target = join(dir, t + '-' + safe)
189
+ // 同一天内重复保存同名文件时追加序号,避免覆盖
190
+ let target = join(subDir, safe)
189
191
  for (let i = 1; await fileExists(target); i += 1) {
190
- target = join(dir, t + '-' + stem + '-' + i + ext)
192
+ target = join(subDir, stem + '-' + i + ext)
191
193
  }
192
194
  await writeFile(target, bytes)
193
- return { path: target, dir, name: t + '-' + safe, size: bytes.length }
195
+ return { path: target, dir, name: safe, size: bytes.length }
194
196
  }
195
197
 
196
198
  /** 注册 /dsh-file-attachment 前缀路由(save POST)。 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wszhoho/dsh-file-attachment",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "文件附件:输入框上传按钮 + 拖拽/粘贴文件(支持多文件);图片走 dsh 原生图片草稿机制(addImages,不缩放/不落盘),文档落盘到 .dsh-file-attachment 并以芯片 @短名 引用(发送时还原 @绝对路径);文档/代码/配置文件可上传类型可在设置页配置;支持 PC 与移动端浏览器",
5
5
  "keywords": [
6
6
  "dsh",