Skip to content

Commit acac59a

Browse files
committed
✨ Feature: add userAgent for tencent cloud COS
1 parent 02cbe5e commit acac59a

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/plugins/uploader/tcyun.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const generateSignature = (options: ITcyunConfig, fileName: string): ISignature
5050
}
5151
}
5252

53-
const postOptions = (options: ITcyunConfig, fileName: string, signature: ISignature, image: Buffer): Options => {
53+
const postOptions = (options: ITcyunConfig, fileName: string, signature: ISignature, image: Buffer, version: string): Options => {
5454
const area = options.area
5555
const path = options.path
5656
if (!options.version || options.version === 'v4') {
@@ -60,7 +60,8 @@ const postOptions = (options: ITcyunConfig, fileName: string, signature: ISignat
6060
headers: {
6161
Host: `${area}.file.myqcloud.com`,
6262
Authorization: signature.signature,
63-
contentType: 'multipart/form-data'
63+
contentType: 'multipart/form-data',
64+
userAgent: `PicGo;${version};null;null`
6465
},
6566
formData: {
6667
op: 'upload',
@@ -74,7 +75,8 @@ const postOptions = (options: ITcyunConfig, fileName: string, signature: ISignat
7475
headers: {
7576
Host: `${options.bucket}.cos.${options.area}.myqcloud.com`,
7677
Authorization: `q-sign-algorithm=sha1&q-ak=${options.secretId}&q-sign-time=${signature.signTime}&q-key-time=${signature.signTime}&q-header-list=host&q-url-param-list=&q-signature=${signature.signature}`,
77-
contentType: mime.lookup(fileName)
78+
contentType: mime.lookup(fileName),
79+
userAgent: `PicGo;${version};null;null`
7880
},
7981
body: image,
8082
resolveWithFullResponse: true
@@ -102,8 +104,8 @@ const handle = async (ctx: IPicGo): Promise<IPicGo | boolean> => {
102104
if (!image && img.base64Image) {
103105
image = Buffer.from(img.base64Image, 'base64')
104106
}
105-
const options = postOptions(tcYunOptions, img.fileName, signature, image)
106-
const res = await ctx.Request.request(options)
107+
const options = postOptions(tcYunOptions, img.fileName, signature, image, ctx.GUI_VERSION || ctx.VERSION)
108+
const res = await ctx.request(options)
107109
.then((res: any) => res)
108110
.catch((err: Error) => {
109111
ctx.log.error(err)

0 commit comments

Comments
 (0)