mirror of
https://github.com/gethomepage/homepage.git
synced 2025-12-06 21:57:48 +01:00
try to detect invalid settings load
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable no-console */
|
||||
import { join } from "path";
|
||||
import { existsSync, copyFile, readFileSync } from "fs";
|
||||
import { existsSync, copyFile, readFileSync, statSync } from "fs";
|
||||
|
||||
import yaml from "js-yaml";
|
||||
|
||||
@@ -32,5 +32,18 @@ export function getSettings() {
|
||||
|
||||
const settingsYaml = join(process.cwd(), "config", "settings.yaml");
|
||||
const fileContents = readFileSync(settingsYaml, "utf8");
|
||||
return yaml.load(fileContents) ?? {};
|
||||
|
||||
let stats;
|
||||
try {
|
||||
stats = statSync(settingsYaml);
|
||||
} catch (e) {
|
||||
stats = {};
|
||||
}
|
||||
|
||||
const yamlLoaded = yaml.load(fileContents) ?? {};
|
||||
|
||||
return {
|
||||
...yamlLoaded,
|
||||
isValid: fileContents !== "-\n" && stats.size !== 2 // see https://github.com/benphelps/homepage/pull/609
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user