-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
77 lines (66 loc) · 2.05 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
#!/usr/bin/env node
const inquirer = require("inquirer");
const chalk = require("chalk");
const figlet = require("figlet");
const path = require("path");
const fs = require("fs");
const Uploader = require("./uploader");
const Draftlog = require("draftlog").into(console);
// Fancy introduction message :)
const intro = () => {
console.log(
chalk.green(
figlet.textSync("ESAC album uploader", {
font: "Ogre",
horizontalLayout: "default",
verticalLayout: "default"
})
)
);
};
const askQuestions = () => {
const questions = [
{
name: "BASEFOLDER",
type: "input",
message: "What is the (relative or absolute) location of the folder containing the albums?"
},
{
name: "URL",
type: "input",
message: "What is the base URL of the photoalbums API endpoint?",
default: "https://esac.nl/api/photoalbums"
},
{
name: "API_KEY",
type: "input",
message: "What is the API_KEY to authenticate with the API, as configured in the .env?",
},
{
name: "BATCH_SIZE",
type: "number",
message: "What is the maximum batch size for the API requests, i.e. what is PHP's max post size? (in MB)",
default: 50
}
];
return inquirer.prompt(questions);
};
const run = async () => {
// Show introduction
intro();
// ask questions
const answers = await askQuestions();
const { BASEFOLDER, URL, API_KEY, BATCH_SIZE } = answers;
let uploader = new Uploader(URL, API_KEY, BATCH_SIZE);
fs.readdir(BASEFOLDER, (err, files) => {
if (!files) {
console.log(chalk.white.bgRed.bold("Base folder does not exist."));
return;
}
files.forEach(file => {
let progress = console.draft('Starting conversion...');
uploader.uploadAlbum(progress, path.join(BASEFOLDER, file));
});
});
};
run();