删除无效文件
This commit is contained in:
parent
d984fdd017
commit
455f17505c
@ -1,137 +0,0 @@
|
||||
const stringUtil = require('./stringUtil')
|
||||
const COS = require('cos-nodejs-sdk-v5')
|
||||
const request = require('request')
|
||||
|
||||
const generateNonce = function() {
|
||||
return stringUtil.randomNum(10000, 99999)
|
||||
}
|
||||
|
||||
const SecretId = 'AKIDvmW8mNvCQVt9GEnd3JNH5lHKI8oJnv46'
|
||||
const SecretKey = 'd6QZhgT7alnhR3VghWAg3FF4c2JMG1c2'
|
||||
|
||||
const cosCDN = new COS({
|
||||
SecretId,
|
||||
SecretKey
|
||||
})
|
||||
|
||||
const generateSign = function(method, data) {
|
||||
let str = `${method}cdn.api.qcloud.com/v2/index.php?`
|
||||
let i = 0
|
||||
for (const key in data) {
|
||||
if ({}.hasOwnProperty.call(data, key)) {
|
||||
if (i++ > 0) str += '&'
|
||||
str += `${key}=${data[key]}`
|
||||
}
|
||||
}
|
||||
return stringUtil.sha1keyBase64(str, SecretKey)
|
||||
}
|
||||
|
||||
const cdnTools = {
|
||||
refreshDir(url) {
|
||||
const now = Math.round(new Date() / 1000)
|
||||
const data = {
|
||||
Action: 'RefreshCdnDir',
|
||||
Nonce: generateNonce(),
|
||||
SecretId: SecretId,
|
||||
Timestamp: now,
|
||||
'dirs.0': url
|
||||
}
|
||||
data.Signature = generateSign('POST', data)
|
||||
return new Promise((resolve, reject) => {
|
||||
const link = 'https://cdn.api.qcloud.com/v2/index.php'
|
||||
const options = {
|
||||
method: 'POST',
|
||||
url: link,
|
||||
headers: {
|
||||
'Cache-Control': 'no-cache',
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
form: data
|
||||
}
|
||||
request(options, (err, response, body) => {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
resolve(JSON.parse(body))
|
||||
})
|
||||
})
|
||||
},
|
||||
refreshOneUrl(url) {
|
||||
const now = Math.round(new Date() / 1000)
|
||||
const data = {
|
||||
Action: 'RefreshCdnUrl',
|
||||
Nonce: generateNonce(),
|
||||
SecretId: SecretId,
|
||||
Timestamp: now,
|
||||
'urls.0': url
|
||||
}
|
||||
data.Signature = generateSign('POST', data)
|
||||
return new Promise((resolve, reject) => {
|
||||
const link = 'https://cdn.api.qcloud.com/v2/index.php'
|
||||
const options = {
|
||||
method: 'POST',
|
||||
url: link,
|
||||
headers: {
|
||||
'Cache-Control': 'no-cache',
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
form: data
|
||||
}
|
||||
request(options, (err, response, body) => {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
resolve(JSON.parse(body))
|
||||
})
|
||||
})
|
||||
},
|
||||
uploadToCDN(fileName, path) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
cosCDN.sliceUploadFile({
|
||||
Bucket: 'client-1256832210',
|
||||
Region: 'ap-beijing',
|
||||
Key: fileName,
|
||||
FilePath: path
|
||||
}, function(err, data) {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
resolve(data)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
deleteFromCDN(files) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
cosCDN.deleteMultipleObject({
|
||||
Bucket: 'client-1256832210',
|
||||
Region: 'ap-beijing',
|
||||
Objects: files
|
||||
}, function(err, data) {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
resolve(data)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
listCDN(subPath) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
cosCDN.getBucket({
|
||||
Bucket: 'client-1256832210',
|
||||
Region: 'ap-beijing',
|
||||
Prefix: subPath
|
||||
}, function(err, data) {
|
||||
// console.log(err || data.Contents)
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
resolve(data.Contents)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = cdnTools
|
@ -1,28 +0,0 @@
|
||||
var Client = require('ftp')
|
||||
|
||||
module.exports = {
|
||||
init() {
|
||||
if (!this._client) {
|
||||
this._client = new Client()
|
||||
this._client.on('ready', function() {
|
||||
console.log('[FTP client] ready')
|
||||
})
|
||||
this._client.connect({
|
||||
host: '140.143.198.31',
|
||||
user: 'dalmatian',
|
||||
password: 'kjlsahjds772SHJ'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
upload(filePath, destPath) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this._client.put(filePath, destPath, function(err) {
|
||||
if (err) {
|
||||
return reject && reject(err)
|
||||
}
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
const crypto = require('crypto')
|
||||
|
||||
module.exports = {
|
||||
sha1keyBase64(str, key) {
|
||||
return crypto.createHmac('sha1', key).update(str).digest('base64')
|
||||
},
|
||||
randomNum(minNum, maxNum) {
|
||||
return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user