@@ -36,7 +36,8 @@ const generateSignature = (options: ITcyunConfig, fileName: string): ISignature
36
36
const tomorrow = today + 86400
37
37
signTime = `${ today } ;${ tomorrow } `
38
38
const signKey = crypto . createHmac ( 'sha1' , secretKey ) . update ( signTime ) . digest ( 'hex' )
39
- const httpString = `put\n/${ options . path } ${ fileName } \n\nhost=${ options . bucket } .cos.${ options . area } .myqcloud.com\n`
39
+ const endpoint = options . endpoint ? options . endpoint : `cos.${ options . area } .myqcloud.com`
40
+ const httpString = `put\n/${ options . path } ${ fileName } \n\nhost=${ options . bucket } .${ endpoint } \n`
40
41
const sha1edHttpString = crypto . createHash ( 'sha1' ) . update ( httpString ) . digest ( 'hex' )
41
42
const stringToSign = `sha1\n${ signTime } \n${ sha1edHttpString } \n`
42
43
signature = crypto . createHmac ( 'sha1' , signKey ) . update ( stringToSign ) . digest ( 'hex' )
@@ -69,11 +70,14 @@ const postOptions = (options: ITcyunConfig, fileName: string, signature: ISignat
69
70
resolveWithFullResponse : true
70
71
}
71
72
} else {
73
+ // https://cloud.tencent.com/document/product/436/10976
74
+ const endpoint = options . endpoint ? options . endpoint : `cos.${ options . area } .myqcloud.com`
75
+
72
76
return {
73
77
method : 'PUT' ,
74
- url : `http://${ options . bucket } .cos. ${ options . area } .myqcloud.com /${ encodeURIComponent ( path ) } ${ encodeURIComponent ( fileName ) } ` ,
78
+ url : `http://${ options . bucket } .${ endpoint } /${ encodeURIComponent ( path ) } ${ encodeURIComponent ( fileName ) } ` ,
75
79
headers : {
76
- Host : `${ options . bucket } .cos. ${ options . area } .myqcloud.com ` ,
80
+ Host : `${ options . bucket } .${ endpoint } ` ,
77
81
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 } ` ,
78
82
contentType : mime . lookup ( fileName ) ,
79
83
'User-Agent' : `PicGo;${ version } ;null;null`
@@ -144,7 +148,8 @@ const handle = async (ctx: IPicGo): Promise<IPicGo | boolean> => {
144
148
if ( customUrl ) {
145
149
img . imgUrl = `${ customUrl } /${ encodeURI ( path ) } ${ encodeURIComponent ( img . fileName ) } ${ optionUrl } `
146
150
} else {
147
- img . imgUrl = `https://${ tcYunOptions . bucket } .cos.${ tcYunOptions . area } .myqcloud.com/${ encodeURI ( path ) } ${ encodeURIComponent ( img . fileName ) } ${ optionUrl } `
151
+ const endpoint = tcYunOptions . endpoint ? tcYunOptions . endpoint : `cos.${ tcYunOptions . area } .myqcloud.com`
152
+ img . imgUrl = `https://${ tcYunOptions . bucket } .${ endpoint } /${ encodeURI ( path ) } ${ encodeURIComponent ( img . fileName ) } ${ optionUrl } `
148
153
}
149
154
} else {
150
155
throw new Error ( res . body . msg )
@@ -219,6 +224,15 @@ const config = (ctx: IPicGo): IPluginConfig[] => {
219
224
get message ( ) { return ctx . i18n . translate < ILocalesKey > ( 'PICBED_TENCENTCLOUD_MESSAGE_AREA' ) } ,
220
225
required : true
221
226
} ,
227
+ {
228
+ name : 'endpoint' ,
229
+ type : 'input' ,
230
+ get prefix ( ) { return ctx . i18n . translate < ILocalesKey > ( 'PICBED_TENCENTCLOUD_ENDPOINT' ) } ,
231
+ get alias ( ) { return ctx . i18n . translate < ILocalesKey > ( 'PICBED_TENCENTCLOUD_ENDPOINT' ) } ,
232
+ default : userConfig . endpoint || '' ,
233
+ get message ( ) { return ctx . i18n . translate < ILocalesKey > ( 'PICBED_TENCENTCLOUD_MESSAGE_ENDPOINT' ) } ,
234
+ required : false
235
+ } ,
222
236
{
223
237
name : 'path' ,
224
238
type : 'input' ,
0 commit comments