-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload-image-to-qiniu.js
36 lines (28 loc) · 1.01 KB
/
upload-image-to-qiniu.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
#!/usr/bin/env node
const path = require("path");
const os = require("os");
const { execSync } = require("child_process");
const config = require("./config");
if (process.argv.length < 3) {
return;
}
if(config.qshellUserName) {
execSync(`${config.qshellPath} user cu ${config.qshellUserName}`);
}
const filePaths = process.argv.slice(2);
const resultUrls = [];
const uploadToQiniu = (filePath) => {
const fileName = path.basename(filePath);
const dirName = path.basename(path.dirname(filePath));
const command = `${config.qshellPath} fput ${config.qiniuBucket} ${config.qiniuPath}/${dirName}/${fileName} ${filePath}`;
try {
result = execSync(command);
} catch (e) {}
const uploadSuccess = result.toString().match(/Put file .* success!/gi);
if (uploadSuccess && uploadSuccess.length) {
resultUrls.push(`${config.host}/${config.qiniuPath}/${dirName}/${fileName}${config.qshellImageStyle}`);
}
};
filePaths.forEach(uploadToQiniu);
console.log("Upload Success:");
console.log(resultUrls.join(os.EOL));