69 lines
1.4 KiB
Go
69 lines
1.4 KiB
Go
package tencent
|
|
|
|
import (
|
|
_ "embed"
|
|
|
|
"apigo.cc/gojs"
|
|
"apigo.cc/gojs/goja"
|
|
"github.com/ssgo/config"
|
|
"github.com/ssgo/u"
|
|
)
|
|
|
|
var confAes = u.NewAes([]byte("?GQ$0K0GgLdO=f+~L68PLm$uhKr4'=tV"), []byte("VFs7@sK61cj^f?HZ"))
|
|
var keysIsSet = false
|
|
|
|
func SetSSKey(key, iv []byte) {
|
|
if !keysIsSet {
|
|
confAes = u.NewAes(key, iv)
|
|
keysIsSet = true
|
|
}
|
|
}
|
|
|
|
var conf = struct {
|
|
Common *struct {
|
|
SecretId string
|
|
SecretKey string
|
|
}
|
|
Cos map[string]*struct {
|
|
Region string
|
|
Bucket string
|
|
SecretId string
|
|
SecretKey string
|
|
}
|
|
}{}
|
|
|
|
func init() {
|
|
obj := gojs.Map{
|
|
"cos": GetCos,
|
|
}
|
|
|
|
gojs.Register("apigo.cc/cloud/tencent", gojs.Module{
|
|
ObjectMaker: func(vm *goja.Runtime) gojs.Map {
|
|
config.LoadConfig("tencent", &conf)
|
|
conf.Common.SecretId = confAes.DecryptUrlBase64ToString(conf.Common.SecretId)
|
|
conf.Common.SecretKey = confAes.DecryptUrlBase64ToString(conf.Common.SecretKey)
|
|
for _, v := range conf.Cos {
|
|
v.SecretId, v.SecretKey = makeSecretIdAndKey(v.SecretId, v.SecretKey)
|
|
}
|
|
|
|
return gojs.ToMap(obj)
|
|
},
|
|
TsCode: gojs.MakeTSCode(obj),
|
|
SetSSKey: SetSSKey,
|
|
})
|
|
}
|
|
|
|
func makeSecretIdAndKey(secretId, SecretKey string) (string, string) {
|
|
if secretId != "" {
|
|
secretId = confAes.DecryptUrlBase64ToString(secretId)
|
|
} else {
|
|
secretId = conf.Common.SecretId
|
|
}
|
|
if SecretKey != "" {
|
|
SecretKey = confAes.DecryptUrlBase64ToString(SecretKey)
|
|
} else {
|
|
SecretKey = conf.Common.SecretKey
|
|
}
|
|
return secretId, SecretKey
|
|
}
|