summaryrefslogtreecommitdiffhomepage
path: root/frontend
diff options
context:
space:
mode:
Diffstat (limited to 'frontend')
-rw-r--r--frontend/.env.development2
-rw-r--r--frontend/config/configReader.ts36
-rw-r--r--frontend/package-lock.json20
-rw-r--r--frontend/package.json5
4 files changed, 30 insertions, 33 deletions
diff --git a/frontend/.env.development b/frontend/.env.development
index e4f4ff67d..f2294ccb6 100644
--- a/frontend/.env.development
+++ b/frontend/.env.development
@@ -9,7 +9,7 @@
# Bazarr configuration path, must be absolute path
# Vite will use this variable to find your bazarr's configuration file
-VITE_BAZARR_CONFIG_FILE="../data/config/config.ini"
+VITE_BAZARR_CONFIG_FILE="../data/config/config.yaml"
# Display update section in settings
VITE_CAN_UPDATE=true
diff --git a/frontend/config/configReader.ts b/frontend/config/configReader.ts
index a3d1597f5..78d682b51 100644
--- a/frontend/config/configReader.ts
+++ b/frontend/config/configReader.ts
@@ -2,48 +2,34 @@
/// <reference types="node" />
import { readFile } from "fs/promises";
+import { get } from "lodash";
+import YAML from "yaml";
class ConfigReader {
- config?: string;
+ config: object;
constructor() {
- this.config = undefined;
+ this.config = {};
}
async open(path: string) {
try {
- this.config = await readFile(path, "utf8");
+ const rawConfig = await readFile(path, "utf8");
+ this.config = YAML.parse(rawConfig);
} catch (err) {
// We don't want to catch the error here, handle it on getValue method
}
}
getValue(sectionName: string, fieldName: string) {
- if (!this.config) {
- throw new Error("Cannot find config to read");
- }
- const targetSection = this.config
- .split("\n\n")
- .filter((section) => section.includes(`[${sectionName}]`));
-
- if (targetSection.length === 0) {
- throw new Error(`Cannot find [${sectionName}] section in config`);
- }
+ const path = `${sectionName}.${fieldName}`;
+ const result = get(this.config, path);
- const section = targetSection[0];
-
- for (const line of section.split("\n")) {
- const matched = line.startsWith(fieldName);
- if (matched) {
- const results = line.split("=");
- if (results.length === 2) {
- const key = results[1].trim();
- return key;
- }
- }
+ if (result === undefined) {
+ throw new Error(`Failed to find ${path} in the local config file`);
}
- throw new Error(`Cannot find ${fieldName} in config`);
+ return result;
}
}
diff --git a/frontend/package-lock.json b/frontend/package-lock.json
index f4fd62275..4de17a101 100644
--- a/frontend/package-lock.json
+++ b/frontend/package-lock.json
@@ -58,7 +58,8 @@
"typescript": "^5",
"vite": "^4.3.0",
"vite-plugin-checker": "^0.5.5",
- "vitest": "^0.30.1"
+ "vitest": "^0.30.1",
+ "yaml": "^2.3.1"
}
},
"node_modules/@adobe/css-tools": {
@@ -4818,6 +4819,14 @@
"node": ">=10"
}
},
+ "node_modules/cosmiconfig/node_modules/yaml": {
+ "version": "1.10.2",
+ "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.2.tgz",
+ "integrity": "sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==",
+ "engines": {
+ "node": ">= 6"
+ }
+ },
"node_modules/cross-spawn": {
"version": "7.0.3",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
@@ -10439,11 +10448,12 @@
"dev": true
},
"node_modules/yaml": {
- "version": "1.10.2",
- "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.2.tgz",
- "integrity": "sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==",
+ "version": "2.3.1",
+ "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.3.1.tgz",
+ "integrity": "sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ==",
+ "dev": true,
"engines": {
- "node": ">= 6"
+ "node": ">= 14"
}
},
"node_modules/yargs": {
diff --git a/frontend/package.json b/frontend/package.json
index 8b0c7c6df..2f5089f01 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -42,7 +42,6 @@
"@types/react-dom": "^18.2.0",
"@types/react-table": "^7.7.0",
"@vitejs/plugin-react": "^4.0.0",
- "vitest": "^0.30.1",
"@vitest/coverage-c8": "^0.30.0",
"@vitest/ui": "^0.30.0",
"clsx": "^1.2.0",
@@ -62,7 +61,9 @@
"sass": "^1.62.0",
"typescript": "^5",
"vite": "^4.3.0",
- "vite-plugin-checker": "^0.5.5"
+ "vite-plugin-checker": "^0.5.5",
+ "vitest": "^0.30.1",
+ "yaml": "^2.3.1"
},
"scripts": {
"start": "vite",