-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
83 lines (63 loc) · 2.26 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'use strict';
var path = require('path');
var fs = require('fs');
var Promise = require('bluebird');
var moment = require('moment');
var tencentyun = require('tencentyun');
var utils = require(path.join(process.cwd(),'core/server/utils'));
function tencentStore(config) {
this.options = config || {};
}
tencentStore.prototype.save = function(image) {
var _this = this;
var options = _this.options;
var fileid = 'sample' + parseInt(Date.now() / 1000);
return new Promise(function(resolve,reject){
tencentyun.conf.setAppInfo(options.appId,options.secretId,options.secretKey);
tencentyun.imagev2.upload(image.path,options.bucket,fileid,function(ret){
// console.log (ret) ;
if ( ret.code == 0) {
var fileid = ret.data.fileid;
//查询
// tencentyun.imagev2.stat(options.bucket,fileid,function(ret){
// console.log(ret);
// })
//复制
// tencentyun.imagev2.copy(options.bucket, fileid, function(ret) {
// console.log(ret);
// });
// 生成私密下载url
// var expired = parseInt(Date.now() / 1000) + 60;
// var sign = tencentyun.auth.getAppSignV2(options.bucket, fileid, expired);
// console.log('downloadUrl is : ' + ret.data.downloadUrl + '?sign=' + sign);
// 生成新的上传签名
// var expired = parseInt(Date.now() / 1000) + 60;
// var sign = tencentyun.auth.getAppSignV2(options.bucket, fileid, expired);
// console.log('sign is :'+sign);
//删除
// tencentyun.imagev2.delete(bucket, fileid, function(ret) {
// console.log(ret);
// });
var imageList = [];
imageList = imageList.push(ret);
console.log(imageList);
// console.log('images' + ret.data.downloadUrl);
resolve(ret.data.downloadUrl);
} else {
reject(ret.message) ;
}
})
})
}
tencentStore.prototype.serve = function() {
return function(req,res,next){
next();
}
}
tencentStore.prototype.getFileKey = function(image) {
var prefix = moment().format('YYYY/MM/').replace(/^\//, '');
var ext = path.extname(image.name);
var name = utils.safeString(path.basename(image.name, ext));
return prefix + name + '-' + Date.now() + ext.toLowerCase();
};
module.exports = tencentStore;