fixed a bug on the config & now backend does use config values
This commit is contained in:
@@ -3,6 +3,7 @@ import * as animeService from './anime.service';
|
|||||||
import { setActivity } from '../rpc/rp.service';
|
import { setActivity } from '../rpc/rp.service';
|
||||||
import { upsertListEntry } from '../list/list.service';
|
import { upsertListEntry } from '../list/list.service';
|
||||||
import {getExtension} from '../../shared/extensions';
|
import {getExtension} from '../../shared/extensions';
|
||||||
|
import { getConfig as loadConfig } from '../../shared/config';
|
||||||
import {Anime, AnimeRequest, SearchRequest, WatchStreamRequest} from '../types';
|
import {Anime, AnimeRequest, SearchRequest, WatchStreamRequest} from '../types';
|
||||||
import {spawn} from "node:child_process";
|
import {spawn} from "node:child_process";
|
||||||
import net from 'net';
|
import net from 'net';
|
||||||
@@ -138,6 +139,10 @@ export async function openInMPV(req: any, reply: any) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const pipe = `\\\\.\\pipe\\mpv-${Date.now()}`;
|
const pipe = `\\\\.\\pipe\\mpv-${Date.now()}`;
|
||||||
|
const { values } = loadConfig();
|
||||||
|
|
||||||
|
const MPV_PATH =
|
||||||
|
values.paths?.mpv || 'mpv';
|
||||||
|
|
||||||
let chaptersArg: string[] = [];
|
let chaptersArg: string[] = [];
|
||||||
if (chapters.length) {
|
if (chapters.length) {
|
||||||
@@ -178,8 +183,12 @@ export async function openInMPV(req: any, reply: any) {
|
|||||||
chaptersArg = [`--chapters-file=${chaptersFile}`];
|
chaptersArg = [`--chapters-file=${chaptersFile}`];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!MPV_PATH) {
|
||||||
|
return { error: 'MPV_NOT_CONFIGURED' };
|
||||||
|
}
|
||||||
|
|
||||||
spawn(
|
spawn(
|
||||||
'D:\\mpv\\mpv.exe',
|
MPV_PATH,
|
||||||
[
|
[
|
||||||
'--force-window=yes',
|
'--force-window=yes',
|
||||||
'--idle=yes',
|
'--idle=yes',
|
||||||
|
|||||||
@@ -7,8 +7,10 @@ import fs from 'fs';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import AdmZip from 'adm-zip';
|
import AdmZip from 'adm-zip';
|
||||||
import { spawn } from 'child_process';
|
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 = {
|
type AnimeDownloadParams = {
|
||||||
anilistId: number;
|
anilistId: number;
|
||||||
|
|||||||
@@ -55,18 +55,31 @@ export function getConfig() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sanitizeLoadedConfig(loaded) {
|
||||||
|
return {
|
||||||
|
library: loaded.library,
|
||||||
|
paths: loaded.paths
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function setConfig(partialConfig) {
|
export function setConfig(partialConfig) {
|
||||||
ensureConfigFile();
|
ensureConfigFile();
|
||||||
|
|
||||||
const current = getConfig();
|
const raw = fs.readFileSync(CONFIG_PATH, 'utf8');
|
||||||
const next = deepMerge(current, partialConfig);
|
const loadedRaw = yaml.load(raw) || {};
|
||||||
|
const loaded = sanitizeLoadedConfig(loadedRaw);
|
||||||
|
|
||||||
fs.writeFileSync(
|
const next = deepMerge(
|
||||||
CONFIG_PATH,
|
structuredClone(DEFAULT_CONFIG),
|
||||||
yaml.dump(next),
|
deepMerge(loaded, partialConfig)
|
||||||
'utf8'
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const toSave = {
|
||||||
|
library: next.library,
|
||||||
|
paths: next.paths
|
||||||
|
};
|
||||||
|
|
||||||
|
fs.writeFileSync(CONFIG_PATH, yaml.dump(toSave), 'utf8');
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,10 @@ import fs from 'fs';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import AdmZip from 'adm-zip';
|
import AdmZip from 'adm-zip';
|
||||||
import { spawn } from 'child_process';
|
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 = {
|
type AnimeDownloadParams = {
|
||||||
anilistId: number;
|
anilistId: number;
|
||||||
|
|||||||
@@ -55,18 +55,31 @@ export function getConfig() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sanitizeLoadedConfig(loaded) {
|
||||||
|
return {
|
||||||
|
library: loaded.library,
|
||||||
|
paths: loaded.paths
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function setConfig(partialConfig) {
|
export function setConfig(partialConfig) {
|
||||||
ensureConfigFile();
|
ensureConfigFile();
|
||||||
|
|
||||||
const current = getConfig();
|
const raw = fs.readFileSync(CONFIG_PATH, 'utf8');
|
||||||
const next = deepMerge(current, partialConfig);
|
const loadedRaw = yaml.load(raw) || {};
|
||||||
|
const loaded = sanitizeLoadedConfig(loadedRaw);
|
||||||
|
|
||||||
fs.writeFileSync(
|
const next = deepMerge(
|
||||||
CONFIG_PATH,
|
structuredClone(DEFAULT_CONFIG),
|
||||||
yaml.dump(next),
|
deepMerge(loaded, partialConfig)
|
||||||
'utf8'
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const toSave = {
|
||||||
|
library: next.library,
|
||||||
|
paths: next.paths
|
||||||
|
};
|
||||||
|
|
||||||
|
fs.writeFileSync(CONFIG_PATH, yaml.dump(toSave), 'utf8');
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user