oss 上传新增host 配置, 支持配置cdn

This commit is contained in:
cool_team 2023-05-11 11:43:18 +08:00
parent 63b290ba9f
commit c1d54feae0
7 changed files with 11 additions and 6 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@cool-midway/core", "name": "@cool-midway/core",
"version": "6.0.4", "version": "6.0.5",
"description": "", "description": "",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "index.d.ts", "typings": "index.d.ts",

View File

@ -147,6 +147,8 @@ export interface OSSConfig {
expAfter?: number; expAfter?: number;
/** 文件最大的 size */ /** 文件最大的 size */
maxSize?: number; maxSize?: number;
// host
host?: string;
} }
/** /**

View File

@ -1,6 +1,6 @@
{ {
"name": "@cool-midway/core", "name": "@cool-midway/core",
"version": "6.0.4", "version": "6.0.5",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"typings": "index.d.ts", "typings": "index.d.ts",

View File

@ -1,6 +1,6 @@
{ {
"name": "@cool-midway/file", "name": "@cool-midway/file",
"version": "6.0.1", "version": "6.0.2",
"description": "", "description": "",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "index.d.ts", "typings": "index.d.ts",

View File

@ -308,6 +308,7 @@ export class CoolFile {
endpoint, endpoint,
expAfter = 300000, expAfter = 300000,
maxSize = 200 * 1024 * 1024, maxSize = 200 * 1024 * 1024,
host,
} = this.config.oss; } = this.config.oss;
const oss = { const oss = {
bucket, bucket,
@ -317,7 +318,7 @@ export class CoolFile {
expAfter, // 签名失效时间,毫秒 expAfter, // 签名失效时间,毫秒
maxSize, // 文件最大的 size maxSize, // 文件最大的 size
}; };
const host = `https://${bucket}.${endpoint}`; const newHost = host ? host : `https://${bucket}.${endpoint}`;
const expireTime = new Date().getTime() + oss.expAfter; const expireTime = new Date().getTime() + oss.expAfter;
const expiration = new Date(expireTime).toISOString(); const expiration = new Date(expireTime).toISOString();
const policyString = JSON.stringify({ const policyString = JSON.stringify({
@ -336,7 +337,7 @@ export class CoolFile {
return { return {
signature, signature,
policy, policy,
host, host: newHost,
OSSAccessKeyId: accessKeyId, OSSAccessKeyId: accessKeyId,
success_action_status: 200, success_action_status: 200,
}; };

View File

@ -61,6 +61,8 @@ export interface OSSConfig {
expAfter?: number; expAfter?: number;
// 文件最大的 size // 文件最大的 size
maxSize?: number; maxSize?: number;
// host
host?: string;
} }
/** /**

View File

@ -1,6 +1,6 @@
{ {
"name": "@cool-midway/file", "name": "@cool-midway/file",
"version": "6.0.1", "version": "6.0.2",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"typings": "index.d.ts", "typings": "index.d.ts",