@be-link/cos 1.12.0-beta.4 → 1.12.2

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
@@ -23,9 +23,37 @@ npm install @be-link/cos cos-js-sdk-v5 crypto-js
23
23
 
24
24
  ## 快速开始
25
25
 
26
- ### Vue 项目
26
+ > **💡 提示**:本包提供两种使用方式
27
+ >
28
+ > 1. **全局单例模式**(`beLinkCOS`):向后兼容,适合全局统一配置
29
+ > 2. **类实例模式**(`BeLinkCOS`):推荐方式,支持多实例
27
30
 
28
- **方式一:立即初始化**
31
+ ### 方式一:全局单例模式(向后兼容)
32
+
33
+ 适合全局统一配置的场景,在 `main.ts/main.tsx` 中初始化:
34
+
35
+ ```typescript
36
+ // main.ts
37
+ import { beLinkCOS } from '@be-link/cos';
38
+
39
+ // 初始化全局单例
40
+ beLinkCOS.init({
41
+ mode: 'production',
42
+ projectName: 'be-link-live-h5', // 可选,特定项目使用专用桶
43
+ });
44
+
45
+ // 之后在任何地方都可以直接使用
46
+ // 组件中:
47
+ const result = await beLinkCOS.uploadFile(file);
48
+ ```
49
+
50
+ ### 方式二:类实例模式(推荐)
51
+
52
+ 支持创建多个实例,适合需要不同配置的场景:
53
+
54
+ #### Vue 项目
55
+
56
+ **立即初始化**
29
57
 
30
58
  ```vue
31
59
  <template>
@@ -72,7 +100,7 @@ const handleUpload = async () => {
72
100
  </script>
73
101
  ```
74
102
 
75
- **方式二:延迟初始化(支持异步配置)**
103
+ **延迟初始化(支持异步配置)**
76
104
 
77
105
  ```vue
78
106
  <script setup>
@@ -94,7 +122,7 @@ const handleUpload = async () => {
94
122
  </script>
95
123
  ```
96
124
 
97
- ### React 项目
125
+ #### React 项目
98
126
 
99
127
  ```jsx
100
128
  import { useState } from 'react';
@@ -135,7 +163,7 @@ function FileUploader() {
135
163
  }
136
164
  ```
137
165
 
138
- ### 原生 JS
166
+ #### 原生 JS
139
167
 
140
168
  ```html
141
169
  <!DOCTYPE html>
@@ -187,6 +215,49 @@ await Promise.all([devUploader.uploadFile(file), prodUploader.uploadFile(file)])
187
215
 
188
216
  ---
189
217
 
218
+ ## 特定项目桶配置
219
+
220
+ 某些项目需要使用专用的存储桶,通过 `projectName` 参数指定:
221
+
222
+ ### 浏览器端使用
223
+
224
+ ```typescript
225
+ import { BeLinkCOS } from '@be-link/cos';
226
+
227
+ // be-link-live-h5 项目使用专用桶
228
+ const uploader = new BeLinkCOS({
229
+ mode: 'production',
230
+ projectName: 'be-link-live-h5',
231
+ });
232
+
233
+ // 文件会自动上传到专用桶:
234
+ // - 桶名称: release-belink-1304510571
235
+ // - 桶地址: release-belink-1304510571.cos.ap-shanghai.myqcloud.com
236
+ // - 地域: ap-shanghai
237
+ await uploader.uploadFile(file);
238
+ ```
239
+
240
+ ### CLI 命令行使用
241
+
242
+ ```bash
243
+ # be-link-live-h5 项目上传
244
+ node_modules/.bin/cos production --project be-link-live-h5
245
+
246
+ # 或使用简写
247
+ node_modules/.bin/cos production -p be-link-live-h5
248
+
249
+ # 其他项目使用默认桶
250
+ node_modules/.bin/cos production
251
+ ```
252
+
253
+ ### 当前支持的特定项目配置
254
+
255
+ | 项目名称 | 环境 | 桶名称 | 地域 |
256
+ | ----------------- | ---------- | --------------------------- | ----------- |
257
+ | `be-link-live-h5` | production | `release-belink-1304510571` | ap-shanghai |
258
+
259
+ ---
260
+
190
261
  ## API 文档
191
262
 
192
263
  ### `new BeLinkCOS(config?)`
@@ -201,6 +272,7 @@ await Promise.all([devUploader.uploadFile(file), prodUploader.uploadFile(file)])
201
272
  **参数:**
202
273
 
203
274
  - `config.mode` - **必填** 环境模式:`'development'` | `'test'` | `'production'`
275
+ - `config.projectName` - 可选,项目标识,用于特定项目的专用桶配置(如 `'be-link-live-h5'`)
204
276
  - `config.headers` - 可选,自定义请求头
205
277
  - `config.ScopeLimit` - 可选,是否限制临时密钥范围(默认 `false`)
206
278
  - `config.debug` - 可选,是否开启调试模式(默认 `false`)
package/dist/index.cjs.js CHANGED
@@ -452,9 +452,13 @@ class BeLinkCOS {
452
452
  }
453
453
  }
454
454
 
455
+ // 导出主类
456
+ const beLinkCOS = new BeLinkCOS();
457
+
455
458
  exports.BUCKETS_CONFIG = BUCKETS_CONFIG;
456
459
  exports.BeLinkCOS = BeLinkCOS;
457
460
  exports.PROJECT_BUCKETS_CONFIG = PROJECT_BUCKETS_CONFIG;
458
461
  exports.REGION = REGION;
462
+ exports.beLinkCOS = beLinkCOS;
459
463
  exports.getBucketConfig = getBucketConfig;
460
464
  exports.getRegion = getRegion;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export { BeLinkCOS } from './beLinkCos';
2
+ import { BeLinkCOS } from './beLinkCos';
3
+ export declare const beLinkCOS: BeLinkCOS;
2
4
  export type { EnvMode, BucketConfig } from './config';
3
5
  export { BUCKETS_CONFIG, REGION, PROJECT_BUCKETS_CONFIG, getBucketConfig, getRegion } from './config';
4
6
  export type { InitConfig, UploadConfig, UploadResult } from './types';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,sBAAsB,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAGtG,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,eAAO,MAAM,SAAS,WAAkB,CAAC;AAGzC,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,sBAAsB,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAGtG,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.esm.js CHANGED
@@ -450,4 +450,7 @@ class BeLinkCOS {
450
450
  }
451
451
  }
452
452
 
453
- export { BUCKETS_CONFIG, BeLinkCOS, PROJECT_BUCKETS_CONFIG, REGION, getBucketConfig, getRegion };
453
+ // 导出主类
454
+ const beLinkCOS = new BeLinkCOS();
455
+
456
+ export { BUCKETS_CONFIG, BeLinkCOS, PROJECT_BUCKETS_CONFIG, REGION, beLinkCOS, getBucketConfig, getRegion };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@be-link/cos",
3
- "version": "1.12.0-beta.4",
3
+ "version": "1.12.2",
4
4
  "description": "前端项目产物上传cos",
5
5
  "homepage": "https://github.com/snowmountain-top/be-link#readme",
6
6
  "author": "zhuiyi",
@@ -22,6 +22,12 @@
22
22
  "bin": {
23
23
  "cos": "./bin/cos.js"
24
24
  },
25
+ "dependencies": {
26
+ "cos-nodejs-sdk-v5": "^2.14.3",
27
+ "@types/crypto-js": "^4.2.2",
28
+ "cos-js-sdk-v5": "^1.8.6",
29
+ "crypto-js": "^4.2.0"
30
+ },
25
31
  "peerDependencies": {
26
32
  "cos-js-sdk-v5": "^1.8.6",
27
33
  "crypto-js": "^4.2.0"