@be-link/cos 1.12.13 → 1.12.15
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.
|
@@ -12,7 +12,7 @@ export declare class BeLinkCOS {
|
|
|
12
12
|
/** COS SDK 实例 */
|
|
13
13
|
private cos;
|
|
14
14
|
/** COS 存储的基础路径 */
|
|
15
|
-
private
|
|
15
|
+
private basePath;
|
|
16
16
|
/** 自定义请求头 */
|
|
17
17
|
headers: Record<string, any>;
|
|
18
18
|
/** 当前环境模式 */
|
|
@@ -52,7 +52,7 @@ export declare class BeLinkCOS {
|
|
|
52
52
|
*/
|
|
53
53
|
createFileMd5(file: File, chunkSize?: number): Promise<string>;
|
|
54
54
|
private getFilePath;
|
|
55
|
-
getSourceUrl(file: File): Promise<string | null>;
|
|
55
|
+
getSourceUrl(file: File, basePath?: string): Promise<string | null>;
|
|
56
56
|
/**
|
|
57
57
|
* 上传文件到腾讯云 COS
|
|
58
58
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BeLinkCOS.d.ts","sourceRoot":"","sources":["../../src/browser/BeLinkCOS.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,OAAO,EAIZ,UAAU,EACV,YAAY,EACZ,YAAY,EACb,MAAM,WAAW,CAAC;AAEnB;;;;;;;;GAQG;AACH,qBAAa,SAAS;IACpB,iBAAiB;IACjB,OAAO,CAAC,GAAG,CAAyC;IACpD,kBAAkB;IAClB,OAAO,CAAC,QAAQ,
|
|
1
|
+
{"version":3,"file":"BeLinkCOS.d.ts","sourceRoot":"","sources":["../../src/browser/BeLinkCOS.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,OAAO,EAIZ,UAAU,EACV,YAAY,EACZ,YAAY,EACb,MAAM,WAAW,CAAC;AAEnB;;;;;;;;GAQG;AACH,qBAAa,SAAS;IACpB,iBAAiB;IACjB,OAAO,CAAC,GAAG,CAAyC;IACpD,kBAAkB;IAClB,O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Y,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAUhF;;OAEG;IACU,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAwCjF,OAAO,IAAI,IAAI;CAoBhB"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -19292,11 +19292,12 @@ class BeLinkCOS {
|
|
|
19292
19292
|
}
|
|
19293
19293
|
this.mode = config.mode;
|
|
19294
19294
|
this.projectName = config.projectName;
|
|
19295
|
+
this.basePath = config.basePath || '/beLinkAllSource/static/';
|
|
19295
19296
|
this.headers = config.headers || {};
|
|
19296
19297
|
this.scopeLimit = config.ScopeLimit || false;
|
|
19297
19298
|
this.debug = config.debug || false;
|
|
19298
19299
|
this.isInitialized = true;
|
|
19299
|
-
this.log('COS 实例初始化成功', { mode: this.mode, projectName: this.projectName });
|
|
19300
|
+
this.log('COS 实例初始化成功', { mode: this.mode, projectName: this.projectName, basePath: this.basePath });
|
|
19300
19301
|
}
|
|
19301
19302
|
/**
|
|
19302
19303
|
* 初始化 COS SDK 实例
|
|
@@ -19445,19 +19446,20 @@ class BeLinkCOS {
|
|
|
19445
19446
|
loadNext();
|
|
19446
19447
|
});
|
|
19447
19448
|
}
|
|
19448
|
-
getFilePath(file) {
|
|
19449
|
+
getFilePath(file, basePath) {
|
|
19450
|
+
const path = basePath || this.basePath;
|
|
19449
19451
|
const filename = file.name;
|
|
19450
19452
|
const fileType = file?.type ? file.type.split('/')[0] : 'other';
|
|
19451
19453
|
const fileExtension = filename.split('.').pop() || '';
|
|
19452
19454
|
const filenameDateNow = `${filename.split('.')[0]}_${Date.now()}`;
|
|
19453
19455
|
const newFileName = `${filenameDateNow}.${fileExtension}`;
|
|
19454
|
-
return `${
|
|
19456
|
+
return `${path}${fileType}/${newFileName}`;
|
|
19455
19457
|
}
|
|
19456
|
-
async getSourceUrl(file) {
|
|
19458
|
+
async getSourceUrl(file, basePath) {
|
|
19457
19459
|
if (!this.checkState('getSourceUrl')) {
|
|
19458
19460
|
return null;
|
|
19459
19461
|
}
|
|
19460
|
-
const path = this.getFilePath(file);
|
|
19462
|
+
const path = this.getFilePath(file, basePath);
|
|
19461
19463
|
const bucketConfig = this.getCurrentBucketConfig();
|
|
19462
19464
|
return `https://${bucketConfig.host}${path}`;
|
|
19463
19465
|
}
|
|
@@ -19471,7 +19473,8 @@ class BeLinkCOS {
|
|
|
19471
19473
|
if (!this.cos) {
|
|
19472
19474
|
await this.initCOS();
|
|
19473
19475
|
}
|
|
19474
|
-
const
|
|
19476
|
+
const { basePath, ...restConfig } = config || {};
|
|
19477
|
+
const key = this.getFilePath(file, basePath);
|
|
19475
19478
|
const bucketConfig = this.getCurrentBucketConfig();
|
|
19476
19479
|
const region = getRegion(bucketConfig);
|
|
19477
19480
|
this.log('开始上传文件:', { filename: file.name, key, bucket: bucketConfig.name, region });
|
|
@@ -19481,9 +19484,9 @@ class BeLinkCOS {
|
|
|
19481
19484
|
Region: region,
|
|
19482
19485
|
Key: key,
|
|
19483
19486
|
Body: file,
|
|
19484
|
-
onProgress:
|
|
19485
|
-
...
|
|
19486
|
-
Headers: { ...this.headers, ...(
|
|
19487
|
+
onProgress: restConfig?.onProgressCallback,
|
|
19488
|
+
...restConfig,
|
|
19489
|
+
Headers: { ...this.headers, ...(restConfig?.Headers || {}) },
|
|
19487
19490
|
}, (err, data) => {
|
|
19488
19491
|
if (err) {
|
|
19489
19492
|
this.error('上传失败:', err);
|
package/dist/index.esm.js
CHANGED
|
@@ -19290,11 +19290,12 @@ class BeLinkCOS {
|
|
|
19290
19290
|
}
|
|
19291
19291
|
this.mode = config.mode;
|
|
19292
19292
|
this.projectName = config.projectName;
|
|
19293
|
+
this.basePath = config.basePath || '/beLinkAllSource/static/';
|
|
19293
19294
|
this.headers = config.headers || {};
|
|
19294
19295
|
this.scopeLimit = config.ScopeLimit || false;
|
|
19295
19296
|
this.debug = config.debug || false;
|
|
19296
19297
|
this.isInitialized = true;
|
|
19297
|
-
this.log('COS 实例初始化成功', { mode: this.mode, projectName: this.projectName });
|
|
19298
|
+
this.log('COS 实例初始化成功', { mode: this.mode, projectName: this.projectName, basePath: this.basePath });
|
|
19298
19299
|
}
|
|
19299
19300
|
/**
|
|
19300
19301
|
* 初始化 COS SDK 实例
|
|
@@ -19443,19 +19444,20 @@ class BeLinkCOS {
|
|
|
19443
19444
|
loadNext();
|
|
19444
19445
|
});
|
|
19445
19446
|
}
|
|
19446
|
-
getFilePath(file) {
|
|
19447
|
+
getFilePath(file, basePath) {
|
|
19448
|
+
const path = basePath || this.basePath;
|
|
19447
19449
|
const filename = file.name;
|
|
19448
19450
|
const fileType = file?.type ? file.type.split('/')[0] : 'other';
|
|
19449
19451
|
const fileExtension = filename.split('.').pop() || '';
|
|
19450
19452
|
const filenameDateNow = `${filename.split('.')[0]}_${Date.now()}`;
|
|
19451
19453
|
const newFileName = `${filenameDateNow}.${fileExtension}`;
|
|
19452
|
-
return `${
|
|
19454
|
+
return `${path}${fileType}/${newFileName}`;
|
|
19453
19455
|
}
|
|
19454
|
-
async getSourceUrl(file) {
|
|
19456
|
+
async getSourceUrl(file, basePath) {
|
|
19455
19457
|
if (!this.checkState('getSourceUrl')) {
|
|
19456
19458
|
return null;
|
|
19457
19459
|
}
|
|
19458
|
-
const path = this.getFilePath(file);
|
|
19460
|
+
const path = this.getFilePath(file, basePath);
|
|
19459
19461
|
const bucketConfig = this.getCurrentBucketConfig();
|
|
19460
19462
|
return `https://${bucketConfig.host}${path}`;
|
|
19461
19463
|
}
|
|
@@ -19469,7 +19471,8 @@ class BeLinkCOS {
|
|
|
19469
19471
|
if (!this.cos) {
|
|
19470
19472
|
await this.initCOS();
|
|
19471
19473
|
}
|
|
19472
|
-
const
|
|
19474
|
+
const { basePath, ...restConfig } = config || {};
|
|
19475
|
+
const key = this.getFilePath(file, basePath);
|
|
19473
19476
|
const bucketConfig = this.getCurrentBucketConfig();
|
|
19474
19477
|
const region = getRegion(bucketConfig);
|
|
19475
19478
|
this.log('开始上传文件:', { filename: file.name, key, bucket: bucketConfig.name, region });
|
|
@@ -19479,9 +19482,9 @@ class BeLinkCOS {
|
|
|
19479
19482
|
Region: region,
|
|
19480
19483
|
Key: key,
|
|
19481
19484
|
Body: file,
|
|
19482
|
-
onProgress:
|
|
19483
|
-
...
|
|
19484
|
-
Headers: { ...this.headers, ...(
|
|
19485
|
+
onProgress: restConfig?.onProgressCallback,
|
|
19486
|
+
...restConfig,
|
|
19487
|
+
Headers: { ...this.headers, ...(restConfig?.Headers || {}) },
|
|
19485
19488
|
}, (err, data) => {
|
|
19486
19489
|
if (err) {
|
|
19487
19490
|
this.error('上传失败:', err);
|
package/dist/shared/types.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export interface InitConfig {
|
|
|
7
7
|
* 环境模式(必填)
|
|
8
8
|
*/
|
|
9
9
|
mode: EnvMode;
|
|
10
|
+
/** 基础路径(可选,默认 '/beLinkAllSource/static/')*/
|
|
11
|
+
basePath?: string;
|
|
10
12
|
/** 项目名称(可选),用于特定项目的桶配置 */
|
|
11
13
|
projectName?: string;
|
|
12
14
|
/** 自定义请求头(可选) */
|
|
@@ -20,6 +22,8 @@ export interface InitConfig {
|
|
|
20
22
|
* 文件上传配置
|
|
21
23
|
*/
|
|
22
24
|
export interface UploadConfig {
|
|
25
|
+
/** 基础路径(可选,如果不提供则使用初始化时的配置或默认值) */
|
|
26
|
+
basePath?: string;
|
|
23
27
|
/** 自定义请求头 */
|
|
24
28
|
Headers?: Record<string, any>;
|
|
25
29
|
/** 上传进度回调 */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAExC;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;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