forked from mbjorkegren/gulp-s3
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
41 lines (35 loc) · 1.21 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
'use strict';
var es = require('event-stream');
var fs = require('fs');
var knox = require('knox');
var gutil = require('gulp-util');
module.exports = function (aws, options) {
if (!options.delay) { options.delay = 0; }
var client = knox.createClient(aws);
var waitTime = 0;
var makeUploadPath = options.makeUploadPath ? options.makeUploadPath : function(file) {
return file.path.replace(file.base, '');
};
return es.mapSync(function (file, cb) {
var isFile = fs.lstatSync(file.path).isFile();
if (!isFile) { return false; }
var uploadPath = makeUploadPath(file);
var headers = { 'x-amz-acl': 'public-read' };
if (options.headers) {
for (var key in options.headers) {
headers[key] = options.headers[key];
}
}
setTimeout(function() {
client.putFile(file.path, uploadPath, headers, function(err, res) {
if (err || res.statusCode !== 200) {
gutil.log(gutil.colors.red('[FAILED]', file.path));
} else {
gutil.log(gutil.colors.green('[SUCCESS]', file.path));
res.resume();
}
});
}, waitTime);
waitTime += options.delay;
});
};