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