@mingto/obs-server 1.0.34 → 1.0.37
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 +92 -47
- package/dist/index.js +46115 -44496
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,47 +1,92 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
1
|
+
# @mingto/obs-server
|
|
2
|
+
|
|
3
|
+
统一的 OBS 文件上传工具库,旨在简化并高效处理文件上传任务。该工具库会自动判断使用 `@mingto/huawei-obs-server`、`@mingto/aws-obs-server` 或 `@mingto/minio-v2-obs-server` 来完成上传操作。
|
|
4
|
+
|
|
5
|
+
## 特性
|
|
6
|
+
|
|
7
|
+
- 🔄 **自动适配**:自动识别 OBS 类型并选择对应上传方式
|
|
8
|
+
- 📦 **统一接口**:所有 OBS 类型使用相同的 API 接口
|
|
9
|
+
- 🚀 **支持大文件**:自动分片上传
|
|
10
|
+
- 📊 **进度监控**:实时上传进度回调
|
|
11
|
+
- ❌ **取消上传**:支持随时取消上传操作
|
|
12
|
+
|
|
13
|
+
## 安装
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add @mingto/obs-server
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 快速开始
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import obsServer from '@mingto/obs-server'
|
|
23
|
+
|
|
24
|
+
// 配置全局参数
|
|
25
|
+
obsServer.config({
|
|
26
|
+
getToken: () => '用户的token',
|
|
27
|
+
fileSplitThreshold: 1024 * 1024 * 5
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
// 创建要上传的文件对象
|
|
31
|
+
const sourceFile = new File(['hello world'], 'hello.txt', { type: 'text/plain' })
|
|
32
|
+
|
|
33
|
+
// 创建上传实例
|
|
34
|
+
const uploadContext = obsServer.create({
|
|
35
|
+
sourceFile,
|
|
36
|
+
onProgress: (event) => {
|
|
37
|
+
console.log(`上传进度: ${event.percent}%`)
|
|
38
|
+
},
|
|
39
|
+
onSuccess: (event) => {
|
|
40
|
+
console.log('上传成功:', event.fileInfo)
|
|
41
|
+
},
|
|
42
|
+
onError: (error) => {
|
|
43
|
+
console.error('上传失败:', error)
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
// 取消上传
|
|
48
|
+
// uploadContext.abort()
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## API
|
|
52
|
+
|
|
53
|
+
### obsServer.config(options)
|
|
54
|
+
|
|
55
|
+
全局配置方法。
|
|
56
|
+
|
|
57
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
58
|
+
|------|------|------|------|
|
|
59
|
+
| getToken | `() => string` | 是 | 获取上传所需的 token |
|
|
60
|
+
| fileSplitThreshold | `number` | 否 | 文件大小分隔线,默认 5MB |
|
|
61
|
+
|
|
62
|
+
### obsServer.create(options)
|
|
63
|
+
|
|
64
|
+
创建上传实例。
|
|
65
|
+
|
|
66
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
67
|
+
|------|------|------|------|
|
|
68
|
+
| sourceFile | `File` | 是 | 要上传的文件对象 |
|
|
69
|
+
| partSize | `number` | 否 | 分片大小,默认 5MB |
|
|
70
|
+
| onStart | `() => void` | 否 | 上传开始回调 |
|
|
71
|
+
| onProgress | `(event) => void` | 否 | 上传进度回调 |
|
|
72
|
+
| onSuccess | `(event) => void` | 否 | 上传成功回调 |
|
|
73
|
+
| onError | `(error) => void` | 否 | 上传失败回调 |
|
|
74
|
+
| onAbort | `() => void` | 否 | 取消上传回调 |
|
|
75
|
+
| onFinally | `() => void` | 否 | 上传结束回调 |
|
|
76
|
+
|
|
77
|
+
## 注意事项
|
|
78
|
+
|
|
79
|
+
1. **OBS 类型自动判断**:工具库会调用后端 `file/config` 接口获取 OBS 类型
|
|
80
|
+
- 返回 `aws` → 使用 `@mingto/aws-obs-server`
|
|
81
|
+
- 返回 `huawei` → 使用 `@mingto/huawei-obs-server`
|
|
82
|
+
- 返回 `minio` → 使用 `@mingto/minio-v2-obs-server`
|
|
83
|
+
|
|
84
|
+
2. **参数配置**:具体参数配置请参考对应工具库的文档
|
|
85
|
+
|
|
86
|
+
## 完整文档
|
|
87
|
+
|
|
88
|
+
更多详细用法请参考 [官方文档](https://mingto.github.io/mt-utils/npm/obs-server/)
|
|
89
|
+
|
|
90
|
+
## 许可证
|
|
91
|
+
|
|
92
|
+
MIT
|