...
|
...
|
@@ -9,17 +9,48 @@ const Model = require('./model'); |
|
|
const utils = require('utility');
|
|
|
const rp = require('request-promise');
|
|
|
const ws = require('../../lib/ws');
|
|
|
const Capi = require('qcloudapi-sdk')
|
|
|
|
|
|
const capi = new Capi({
|
|
|
SecretId: 'AKID6dwpKadiQgbDpXDtyNhppIHPO5qPv5GK',
|
|
|
SecretKey: 'ACJkH9mg0DBA1PYpf0E7f3g534wBsQaW',
|
|
|
serviceType: 'cdn'
|
|
|
});
|
|
|
|
|
|
class CdnCache extends Model {
|
|
|
constructor() {
|
|
|
super('cdn_page');
|
|
|
}
|
|
|
async removeCache(queryUris, objectType) {
|
|
|
async removeCache(queryUris, objectType, cloud) {
|
|
|
let self = this;
|
|
|
self._requestApi({
|
|
|
Action: 'RefreshObjectCaches',
|
|
|
ObjectPath: queryUris,
|
|
|
ObjectType: objectType
|
|
|
|
|
|
if (cloud === 'qcloud') {
|
|
|
self._cleanQcloudCache({
|
|
|
ObjectPath: queryUris,
|
|
|
ObjectType: objectType
|
|
|
})
|
|
|
} else {
|
|
|
self._requestApi({
|
|
|
Action: 'RefreshObjectCaches',
|
|
|
ObjectPath: queryUris,
|
|
|
ObjectType: objectType
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
async _cleanQcloudCache(params) {
|
|
|
let self = this;
|
|
|
let qCloudParams = self._getQcloudParams(params);
|
|
|
|
|
|
if (!Object.keys(qCloudParams).length) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
capi.request(qCloudParams, function(err, res) {
|
|
|
if (err || res.code) {
|
|
|
return self._broadcast(`清理腾讯云失败:${res && res.message}`)
|
|
|
}
|
|
|
|
|
|
self._broadcast(`清理腾讯云提交成功,RefreshTaskId:${res.data.task_id}`)
|
|
|
})
|
|
|
}
|
|
|
async _requestApi(params) {
|
...
|
...
|
@@ -46,12 +77,28 @@ class CdnCache extends Model { |
|
|
json: true
|
|
|
})
|
|
|
.then(function (res) {
|
|
|
self._broadcast(`清理提交成功,RefreshTaskId:${res.RefreshTaskId}`)
|
|
|
self._broadcast(`清理阿里云提交成功,RefreshTaskId:${res.RefreshTaskId}`)
|
|
|
})
|
|
|
.catch(function (err) {
|
|
|
self._broadcast(`清理失败:${err.response.body}`)
|
|
|
self._broadcast(`清理阿里云失败:${err.response.body}`)
|
|
|
});
|
|
|
|
|
|
}
|
|
|
_getUrlList(str = '') {
|
|
|
return str.split('\n');
|
|
|
}
|
|
|
_getQcloudParams(params) {
|
|
|
let param = {};
|
|
|
let type = params.ObjectType === 'File' ? 'urls' : 'dirs';
|
|
|
let list = this._getUrlList(params.ObjectPath);
|
|
|
|
|
|
param.Action = params.ObjectType === 'File' ? 'RefreshCdnUrl' : 'RefreshCdnDir';
|
|
|
|
|
|
list.forEach((url, index) => {
|
|
|
param[`${type}.${index}`] = url;
|
|
|
});
|
|
|
|
|
|
return param;
|
|
|
}
|
|
|
_getUtcTime(date) {
|
|
|
let year = date.getUTCFullYear();
|
...
|
...
|
|