-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
49 lines (44 loc) · 1.53 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
(function(module) {
'use strict';
var winston = module.parent.require('winston'),
async = module.parent.require('async'),
file = module.parent.require('./file'),
user = module.parent.require('./user'),
fs = require('fs'),
path = require('path'),
nconf = require('nconf');
var plugin = {};
plugin.init = function(params, callback) {
callback();
};
plugin.upload = function (data, callback) {
var settings;
var image = data.image;
var uid = data.uid;
var folder = 'files';
async.waterfall([
function (next) {
winston.log('image '+image.path);
var fileName = new Date().getTime()+image.name;
var uploadPath = path.join(nconf.get('upload_path'), folder, ''+uid);
if (!fs.existsSync(uploadPath)) {
fs.mkdirSync(uploadPath);
} else {
winston.log('Folder exists');
}
file.saveFileToLocal(fileName, 'files/'+uid, image.path, function(err, data){
if (err) {
winston.error(err);
} else {
winston.log(data);
}
return next(null, {
name: image.name,
url: data.url
});
});
}
], callback);
};
module.exports=plugin;
}(module));