Skip to content

Commit 8edcd95

Browse files
committed
feat: upgrade cdn api to v3
1 parent d29229b commit 8edcd95

File tree

4 files changed

+354
-216
lines changed

4 files changed

+354
-216
lines changed

src/baas/cdn/apis.js

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
function HttpError(code, message) {
1+
function HttpError(code, message, reqId) {
22
this.code = code || 0
3-
this.message = message || ''
3+
this.message = reqId ? `${reqId}, ${message || ''}` : message || ''
44
}
55

66
HttpError.prototype = Error.prototype
@@ -25,37 +25,41 @@ function apiFactory(actions) {
2525
actions.forEach((action) => {
2626
apis[action] = async (capi, inputs) => {
2727
inputs = cleanEmptyValue(inputs)
28-
const res = await capi.request(
29-
{
30-
Action: action,
31-
RequestClient: 'ServerlessComponent',
32-
Token: capi.options.Token || null,
33-
...inputs
34-
},
35-
{
36-
Version: '2017-03-12',
37-
ServiceType: 'cdn',
38-
bashHost: 'api.qcloud.com',
39-
path: '/v2/index.php'
28+
try {
29+
const { Response } = await capi.request(
30+
{
31+
Action: action,
32+
Version: '2018-06-06',
33+
RequestClient: 'ServerlessComponent',
34+
Token: capi.options.Token || null,
35+
...inputs
36+
},
37+
{
38+
debug: false,
39+
ServiceType: 'cdn',
40+
host: 'cdn.tencentcloudapi.com'
41+
}
42+
)
43+
if (Response && Response.Error && Response.Error.Code) {
44+
throw new HttpError(Response.Error.Code, Response.Error.Message, Response.RequestId)
4045
}
41-
)
42-
if (res.code !== 0) {
43-
throw new HttpError(res.code, res.message)
46+
return Response
47+
} catch (e) {
48+
throw new HttpError(500, e.message)
4449
}
45-
return res
4650
}
4751
})
4852

4953
return apis
5054
}
5155

5256
const ACTIONS = [
53-
'AddCdnHost',
54-
'SetHttpsInfo',
55-
'GetHostInfoByHost',
56-
'DeleteCdnHost',
57-
'OfflineHost',
58-
'UpdateCdnConfig'
57+
'AddCdnDomain',
58+
'DescribeDomains',
59+
'UpdateDomainConfig',
60+
'StopCdnDomain',
61+
'DeleteCdnDomain',
62+
'PurgeUrlsCache'
5963
]
6064
const APIS = apiFactory(ACTIONS)
6165

0 commit comments

Comments
 (0)