fixed a bug on the config & now backend does use config values
This commit is contained in:
@@ -7,8 +7,10 @@ import fs from 'fs';
|
||||
import path from 'path';
|
||||
import AdmZip from 'adm-zip';
|
||||
import { spawn } from 'child_process';
|
||||
const { values } = loadConfig();
|
||||
|
||||
const FFMPEG_PATH = 'D:\\ffmpeg\\bin\\ffmpeg.exe';
|
||||
const FFMPEG_PATH =
|
||||
values.paths?.ffmpeg || 'ffmpeg';
|
||||
|
||||
type AnimeDownloadParams = {
|
||||
anilistId: number;
|
||||
|
||||
@@ -55,18 +55,31 @@ export function getConfig() {
|
||||
};
|
||||
}
|
||||
|
||||
function sanitizeLoadedConfig(loaded) {
|
||||
return {
|
||||
library: loaded.library,
|
||||
paths: loaded.paths
|
||||
};
|
||||
}
|
||||
|
||||
export function setConfig(partialConfig) {
|
||||
ensureConfigFile();
|
||||
|
||||
const current = getConfig();
|
||||
const next = deepMerge(current, partialConfig);
|
||||
const raw = fs.readFileSync(CONFIG_PATH, 'utf8');
|
||||
const loadedRaw = yaml.load(raw) || {};
|
||||
const loaded = sanitizeLoadedConfig(loadedRaw);
|
||||
|
||||
fs.writeFileSync(
|
||||
CONFIG_PATH,
|
||||
yaml.dump(next),
|
||||
'utf8'
|
||||
const next = deepMerge(
|
||||
structuredClone(DEFAULT_CONFIG),
|
||||
deepMerge(loaded, partialConfig)
|
||||
);
|
||||
|
||||
const toSave = {
|
||||
library: next.library,
|
||||
paths: next.paths
|
||||
};
|
||||
|
||||
fs.writeFileSync(CONFIG_PATH, yaml.dump(toSave), 'utf8');
|
||||
return next;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user