@mountra/mountra-sdk 0.1.0 → 0.2.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,19 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0 - 2026-08-19
4
+
5
+ ### Added
6
+
7
+ - Added streaming browser downloads using the File System Access API, including a save-location picker and incremental writes.
8
+ - Added IndexedDB-backed download checkpoints, automatic retry, Range-based resume, and resumable downloads after refresh or network interruption.
9
+ - Added multi-chunk export metadata with per-chunk signed URLs and sequential client-side assembly when File System Access is available.
10
+ - Added download progress callbacks with total size, downloaded bytes, one-second-window speed, elapsed time, retry count, and remaining-time estimation.
11
+ - Added the `MountraFile` resource API:
12
+ - `client.file({ wsid, path })`
13
+ - `client.file({ wsid, ino })`
14
+ - `file.export()`, `file.download()`, and `file.resume()`
15
+
16
+ ### Changed
17
+
18
+ - `exportFile` responses now include the complete file size and, for multi-chunk files, the ordered chunk export URLs.
19
+ - Existing parameter-based upload and download APIs remain available for compatibility.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @mountra/mountra-sdk
2
2
 
3
- 用于浏览器前端接入 Mountra 的 TypeScript SDK。当前提供统一的文件上传工具:普通 chunk 使用签名 PUT,jumbo chunk 使用 S3 Multipart。
3
+ 用于浏览器前端接入 Mountra 的 TypeScript SDK。提供文件上传、流式下载、断点续传和多 chunk 客户端组装。
4
4
 
5
5
  ## 使用
6
6
 
@@ -94,6 +94,65 @@ const result = await mountra.resumeUpload(file, prepared.context);
94
94
 
95
95
  `chunkCount > 1` 时请求使用 `chunk_method: "fix"`。云端会为每个 chunk 保存独立的 descriptor,并在 status 查询中根据对象存储重新确认上传状态。
96
96
 
97
+ ## 下载
98
+
99
+ 文件操作也可以使用资源对象风格。`path` 和 `ino` 必须二选一;`wsid` 是
100
+ `workspaceId` 的简写。未在对象中提供 workspace 时,会使用创建
101
+ `MountraClient` 时配置的 workspace:
102
+
103
+ ```ts
104
+ const file = mountra.file({
105
+ wsid: 17,
106
+ path: "/documents/report.pdf",
107
+ });
108
+
109
+ const exported = await file.export();
110
+ await file.download({
111
+ downloadFilename: "report.pdf",
112
+ onProgress: console.log,
113
+ });
114
+
115
+ // 页面刷新后,自动选择这个文件最新的可恢复下载 checkpoint
116
+ await file.resume();
117
+ ```
118
+
119
+ 也可以通过 inode 定位:
120
+
121
+ ```ts
122
+ const file = mountra.file({ ino: "12345" });
123
+ await file.download();
124
+ ```
125
+
126
+ `file.export()`、`file.download()` 和 `file.resume()` 会始终使用创建对象
127
+ 时确定的文件身份,行为参数只能通过各方法的 options 传入。
128
+
129
+ `exportFile` 返回完整文件大小 `size`。多 chunk 文件还会返回按顺序排列的 `chunks`,每个 chunk 都包含独立的签名 URL;`url` 始终是服务端顺序组装后的完整文件 URL。
130
+
131
+ ```ts
132
+ const result = await mountra.downloadFile({
133
+ path: "/documents/report.pdf",
134
+ downloadFilename: "report.pdf",
135
+ onProgress: ({ downloadedBytes, totalBytes, speedBytesPerSecond, estimatedRemainingSeconds }) => {
136
+ console.log({ downloadedBytes, totalBytes, speedBytesPerSecond, estimatedRemainingSeconds });
137
+ },
138
+ });
139
+ ```
140
+
141
+ 在支持 File System Access API 的 Chromium 浏览器中,SDK 会先调用 `showSaveFilePicker`,随后使用 `ReadableStream` 将数据直接写入用户选择的文件。多 chunk 文件优先逐个下载 chunk 并按顺序追加;其他浏览器使用服务端组装 URL 并返回 Blob。
142
+
143
+ 下载进度会从 streaming response 实际写入的字节数统计,速度使用最近 1 秒窗口计算。网络错误和常见临时 HTTP 错误默认重试 3 次,可通过 `maxRetries`、`retryDelayMs` 和 `AbortSignal` 调整。
144
+
145
+ FSA 下载的中间状态默认保存到本地 IndexedDB,包括 chunk 偏移、已写入字节数以及可持久化的文件句柄。刷新页面后可以列出并恢复任务:
146
+
147
+ ```ts
148
+ const pending = await mountra.listResumableDownloads();
149
+ if (pending[0]) {
150
+ await mountra.resumeDownload(pending[0].key, { onProgress: console.log });
151
+ }
152
+ ```
153
+
154
+ 可以通过 `downloadCheckpointStore` 注入自己的 `DownloadCheckpointStore`(测试时可使用 `InMemoryDownloadCheckpointStore`)。SDK 不会把短期签名 URL 写入 checkpoint;恢复时会重新请求 export URL。
155
+
97
156
  ## 开发
98
157
 
99
158
  ```bash
@@ -123,4 +182,5 @@ pnpm publish:sdk
123
182
  pnpm publish:sdk --dry-run
124
183
  ```
125
184
 
126
- 发布包只包含 `dist/` 和本 README,不包含源码与测试文件。
185
+ 发布脚本默认使用 `https://registry.npmjs.org/`,如需发布到其他 registry,设置
186
+ `NPM_REGISTRY` 环境变量。发布包包含 `dist/`、README 和 CHANGELOG,不包含源码与测试文件。