-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (37 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
42
require('dotenv').config();
const Minio = require('minio');
const minioClient = new Minio.Client({
endPoint: process.env.ENDPOINT,
port: Number.parseInt(process.env.PORT),
useSSL: process.env.USE_SSL === 'true',
accessKey: process.env.ACCESS_KEY,
secretKey: process.env.SECRET_KEY
});
const walk = require('walk');
const minioBucket = process.env.BUCKET;
const walker = walk.walk('files');
const errors = [];
walker.on('file', (root, fileStats, next) => {
if (fileStats.name === '.gitignore') {
next();
} else {
const filePath = `${process.cwd()}/${root}/${fileStats.name}`;
const minioPath = `${root}/${fileStats.name}`.replace(`files/`, '');
console.log('Upload', filePath, minioPath)
minioClient.fPutObject(minioBucket, minioPath, filePath, err => {
console.log(filePath, ' uploaded');
if (err) {
console.error(err);
errors.push(filePath);
}
next()
})
}
})
walker.on('end', function () {
console.log('End upload');
if (errors.length > 0) {
console.log('There where errors uploading these files:');
errors.forEach(error => console.log(error));
}
})