-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_levels.js
More file actions
28 lines (25 loc) · 883 Bytes
/
load_levels.js
File metadata and controls
28 lines (25 loc) · 883 Bytes
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
const axios = require('axios').default;
const path = require('path');
const fs = require('fs');
const directoryPath = path.join(__dirname, 'levels');
axios.defaults.headers.common.Authorization = 'mocksecrettokenadmin';
const loadLevels = () => {
fs.readdir(directoryPath, (err, files) => {
if (err) {
console.error(`Unable to scan directory: ${err}`);
}
files.forEach((file) => {
fs.readFile(`${directoryPath}/${file}`, (err, data) => {
if (err) throw err;
const level = JSON.parse(data);
axios.put(`${process.env.BACKEND_HOST}/levels/${path.parse(file).name}`, level).then((response) => {
console.log(response.statusText);
}).catch((error) => {
console.error('Error running level loading');
console.error(error.toJSON());
});
});
});
});
};
module.exports = loadLevels;