Use config files
This commit is contained in:
+11
-11
@@ -33,7 +33,7 @@ async function addMap(filename, meta, throttle, motor) {
|
||||
|
||||
try {
|
||||
await csv.writeToString(map).then(data => total += data);
|
||||
fs.writeFileSync(`app/storage/${filename}`, total);
|
||||
fs.writeFileSync(path.join(path.dirname(require.main.filename), map_conf.map_storage_path, filename), total);
|
||||
} catch (error) {
|
||||
throw new Error(error);
|
||||
}
|
||||
@@ -45,10 +45,10 @@ async function updateMap(filename, meta, throttle, motor) {
|
||||
|
||||
try {
|
||||
await csv.writeToString(map).then(data => total += data);
|
||||
fs.writeFileSync(`app/storage/${filename}`, total);
|
||||
fs.renameSync(`app/storage/${filename}`, `app/storage/map_${uuid.v4()}.csv`)
|
||||
if (fs.existsSync("app/storage/selected")) {
|
||||
fs.unlinkSync("app/storage/selected");
|
||||
fs.writeFileSync(path.join(path.dirname(require.main.filename), map_conf.map_storage_path, filename), total);
|
||||
fs.renameSync(path.join(path.dirname(require.main.filename), map_conf.map_storage_path, filename), path.join(path.dirname(require.main.filename), map_conf.map_storage_path, `${map_conf.prefix}_${uuid.v4()}.${map_conf.extension}`));
|
||||
if (fs.existsSync(path.join(path.dirname(require.main.filename), map_conf.map_storage_path, "selected"))) {
|
||||
fs.unlinkSync(path.join(path.dirname(require.main.filename), map_conf.map_storage_path, "selected"));
|
||||
}
|
||||
} catch (error) {
|
||||
throw new Error(error);
|
||||
@@ -109,7 +109,7 @@ function mapExists(filename) {
|
||||
if (path.extname(filename) != ".csv") {
|
||||
return false;
|
||||
}
|
||||
return fs.existsSync(`app/storage/${filename}`);
|
||||
return fs.existsSync(path.join(path.dirname(require.main.filename), map_conf.map_storage_path, filename));
|
||||
}
|
||||
|
||||
// mode: comments 1 or data 0
|
||||
@@ -118,12 +118,12 @@ function parseMap(filename, mode) {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
if (mode) {
|
||||
csv.parseFile(`app/storage/${filename}`)
|
||||
csv.parseFile(path.join(path.dirname(require.main.filename), map_conf.map_storage_path, filename))
|
||||
.on('error', error => reject(error))
|
||||
.on('data', row => row[0][0] === "#" ? result.push(row[0].slice(1)) : resolve(result))
|
||||
.on('end', () => resolve(result));
|
||||
} else {
|
||||
csv.parseFile(`app/storage/${filename}`, { comment: "#" })
|
||||
csv.parseFile(path.join(path.dirname(require.main.filename), map_conf.map_storage_path, filename), { comment: "#" })
|
||||
.on('error', error => reject(error))
|
||||
.on('data', row => result.push(row))
|
||||
.on('end', () => resolve(result));
|
||||
@@ -155,10 +155,10 @@ async function getAvailableMaps() {
|
||||
var available_maps = {};
|
||||
|
||||
try {
|
||||
var files = fs.readdirSync("app/storage");
|
||||
var files = fs.readdirSync(path.join(path.dirname(require.main.filename), map_conf.map_storage_path));
|
||||
|
||||
for (const file of files) {
|
||||
if (path.extname(file) == ".csv") {
|
||||
if (path.extname(file) == `.${map_conf.extension}`) {
|
||||
available_maps[file] = {};
|
||||
|
||||
try {
|
||||
@@ -177,7 +177,7 @@ async function getAvailableMaps() {
|
||||
} catch (error) {
|
||||
if (error.code === "ENOENT") {
|
||||
logger.info("No storage directory found. Creating directory.");
|
||||
fs.mkdirSync("app/storage");
|
||||
fs.mkdirSync(path.join(path.dirname(require.main.filename), map_conf.map_storage_path));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user