-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog-downloader.js
50 lines (38 loc) · 1.14 KB
/
log-downloader.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
const _ = require('lodash');
const bootmod3 = require('./BootmodHelpers.class');
const jsonPath = './bm3-logs.json';
const mapPath = './mapFiles.json';
const run = async () => {
const mapFiles = {};
const logs = await bootmod3.readJsonFromFile(jsonPath);
const mapNames = await bootmod3.readJsonFromFile(mapPath);
mapNames.forEach(({id, name}) => {
mapFiles[id] = {id, name};
});
const determineLogPath = (id, name, mapId) => {
const mapName = _.get(mapFiles, `${mapId}.name`, null);
if (!mapName || mapName === null) {
return (name) ? `${name}.csv` : `${id}.csv`;
}
return (name) ? `${mapName}/${name}.csv` : `${mapName}/${id}.csv`
};
const processLogs = logs.map(({id, name, mapId}) => {
if(!id && !name) {
throw new Error(`Invalid Log: ${id}`)
}
const logPath = `logs/${determineLogPath(id, name, mapId)}`;
if(!logPath) {
return false;
}
return bootmod3.downloadAndSaveLog(id, logPath);
});
return Promise.all(processLogs)
.then(() => {
return 'SUCCESS';
});
};
run().then((status) => {
console.log(status);
}).catch((err) => {
console.log(err);
});