mirror of
https://github.com/Terncode/pixel.horse.git
synced 2026-09-24 13:55:04 +02:00
Merge pull request #37 from BytewaveMLP/fix-enoent-directory
Create settings and stats directories ad-hoc
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { readFileAsync, writeFileAsync } from 'fs';
|
||||
import { readFileAsync, writeFileAsync, mkdirAsync } from 'fs';
|
||||
import { Settings } from '../common/adminInterfaces';
|
||||
import { cloneDeep } from '../common/utils';
|
||||
import * as paths from './paths';
|
||||
@@ -18,13 +18,17 @@ export async function loadSettings() {
|
||||
const json = await readFileAsync(settingsPath, 'utf8');
|
||||
return JSON.parse(json) as Settings;
|
||||
} catch (e) {
|
||||
if (e === 'ENOENT') {
|
||||
writeFileAsync(settingsPath, '{}', 'utf8');
|
||||
return {} as Settings;
|
||||
if (e.code === 'ENOENT') {
|
||||
try {
|
||||
await mkdirAsync(paths.pathTo('settings'));
|
||||
} catch (e2) {
|
||||
if (e2.code !== 'EEXIST') throw e;
|
||||
}
|
||||
} else {
|
||||
console.log("Error reading settings file: " + e);
|
||||
return {} as Settings;
|
||||
console.error('Error reading settings file: ' + e);
|
||||
}
|
||||
|
||||
return cloneDeep(defaultSettings);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as moment from 'moment';
|
||||
import { compact } from 'lodash';
|
||||
import { Request } from 'express';
|
||||
@@ -188,6 +189,11 @@ export class StatsTracker {
|
||||
}
|
||||
startStatTracking() {
|
||||
if (!fs.existsSync(this.statsPath)) {
|
||||
try {
|
||||
fs.mkdirSync(path.dirname(this.statsPath), { recursive: true });
|
||||
} catch (e) {
|
||||
if (e.code !== 'EEXIST') throw e;
|
||||
}
|
||||
fs.writeFileSync(this.statsPath, encodeCSV(statsHeaders), { encoding: 'utf8' });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user