-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Addo.Zhang <[email protected]>
- Loading branch information
Showing
11 changed files
with
162 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export const TencentCloudRegionList: Record<string, string> = { | ||
"ap-beijing": "China (Beijing)", | ||
"ap-nanjing": "China (Nanjing)", | ||
"ap-shanghai": "China (Shanghai)", | ||
"ap-guangzhou": "China (Guangzhou)", | ||
"ap-chengdu": "China (Chengdu)", | ||
"ap-chongqing": "China (Chongqing)", | ||
"ap-hongkong": "China (Hong Kong)", | ||
"ap-singapore": "Singapore", | ||
"ap-mumbai": "Mumbai", | ||
"ap-jakarta": "Jakarta", | ||
"ap-seoul": "Seoul", | ||
"ap-bangkok": "Bangkok", | ||
"ap-tokyo": "Tokyo", | ||
"na-siliconvalley": "North America (Silicon Valley - West US)", | ||
"na-ashburn": "North America (Virginia - East US)", | ||
"sa-saopaulo": "South America (São Paulo)", | ||
"eu-frankfurt": "Europe (Frankfurt)", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import COS from "cos-nodejs-sdk-v5" | ||
import ImageUploader from "../imageUploader"; | ||
import {UploaderUtils} from "../uploaderUtils"; | ||
|
||
export default class CosUploader implements ImageUploader { | ||
|
||
private readonly client!: COS; | ||
private readonly pathTmpl: String; | ||
private readonly customDomainName: String; | ||
private readonly region: string; | ||
private readonly bucket: string; | ||
|
||
constructor(setting: CosSetting) { | ||
this.client = new COS({ | ||
SecretId: setting.secretId, | ||
SecretKey: setting.secretKey, | ||
}) | ||
this.pathTmpl = setting.path; | ||
this.customDomainName = setting.customDomainName; | ||
this.bucket = setting.bucket; | ||
this.region = setting.region; | ||
} | ||
|
||
async upload(image: File, fullPath: string): Promise<string> { | ||
const result = this.client.putObject({ | ||
Body: Buffer.from((await image.arrayBuffer())), | ||
Bucket: this.bucket, | ||
Region: this.region, | ||
Key: UploaderUtils.generateName(this.pathTmpl, image.name), | ||
}); | ||
var url = 'https://' + (await result).Location; | ||
return UploaderUtils.customizeDomainName(url, this.customDomainName); | ||
} | ||
|
||
} | ||
|
||
export interface CosSetting { | ||
region: string; | ||
bucket: string; | ||
secretId: string; | ||
secretKey: string; | ||
path: string; | ||
customDomainName: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters