mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-03-01 06:22:44 -08:00
Fix AniList URL guard
This commit is contained in:
@@ -17,6 +17,30 @@ test("loads defaults when config is missing", () => {
|
||||
const config = service.getConfig();
|
||||
assert.equal(config.websocket.port, DEFAULT_CONFIG.websocket.port);
|
||||
assert.equal(config.ankiConnect.behavior.autoUpdateNewCards, true);
|
||||
assert.equal(config.anilist.enabled, false);
|
||||
});
|
||||
|
||||
test("parses anilist.enabled and warns for invalid value", () => {
|
||||
const dir = makeTempDir();
|
||||
fs.writeFileSync(
|
||||
path.join(dir, "config.jsonc"),
|
||||
`{
|
||||
"anilist": {
|
||||
"enabled": "yes"
|
||||
}
|
||||
}`,
|
||||
"utf-8",
|
||||
);
|
||||
|
||||
const service = new ConfigService(dir);
|
||||
const config = service.getConfig();
|
||||
const warnings = service.getWarnings();
|
||||
|
||||
assert.equal(config.anilist.enabled, DEFAULT_CONFIG.anilist.enabled);
|
||||
assert.ok(warnings.some((warning) => warning.path === "anilist.enabled"));
|
||||
|
||||
service.patchRawConfig({ anilist: { enabled: true } });
|
||||
assert.equal(service.getConfig().anilist.enabled, true);
|
||||
});
|
||||
|
||||
test("parses jsonc and warns/falls back on invalid value", () => {
|
||||
|
||||
@@ -226,6 +226,10 @@ export const DEFAULT_CONFIG: ResolvedConfig = {
|
||||
languagePreference: "ja",
|
||||
maxEntryResults: 10,
|
||||
},
|
||||
anilist: {
|
||||
enabled: false,
|
||||
accessToken: "",
|
||||
},
|
||||
youtubeSubgen: {
|
||||
mode: "automatic",
|
||||
whisperBin: "",
|
||||
@@ -467,6 +471,18 @@ export const CONFIG_OPTION_REGISTRY: ConfigOptionRegistryEntry[] = [
|
||||
defaultValue: DEFAULT_CONFIG.jimaku.maxEntryResults,
|
||||
description: "Maximum Jimaku search results returned.",
|
||||
},
|
||||
{
|
||||
path: "anilist.enabled",
|
||||
kind: "boolean",
|
||||
defaultValue: DEFAULT_CONFIG.anilist.enabled,
|
||||
description: "Enable AniList post-watch progress updates.",
|
||||
},
|
||||
{
|
||||
path: "anilist.accessToken",
|
||||
kind: "string",
|
||||
defaultValue: DEFAULT_CONFIG.anilist.accessToken,
|
||||
description: "AniList access token used for post-watch updates.",
|
||||
},
|
||||
{
|
||||
path: "youtubeSubgen.mode",
|
||||
kind: "enum",
|
||||
@@ -600,6 +616,11 @@ export const CONFIG_TEMPLATE_SECTIONS: ConfigTemplateSection[] = [
|
||||
],
|
||||
key: "youtubeSubgen",
|
||||
},
|
||||
{
|
||||
title: "Anilist",
|
||||
description: ["Anilist API credentials and update behavior."],
|
||||
key: "anilist",
|
||||
},
|
||||
];
|
||||
|
||||
export function deepCloneConfig(config: ResolvedConfig): ResolvedConfig {
|
||||
|
||||
@@ -443,6 +443,32 @@ export class ConfigService {
|
||||
}
|
||||
}
|
||||
|
||||
if (isObject(src.anilist)) {
|
||||
const enabled = asBoolean(src.anilist.enabled);
|
||||
if (enabled !== undefined) {
|
||||
resolved.anilist.enabled = enabled;
|
||||
} else if (src.anilist.enabled !== undefined) {
|
||||
warn(
|
||||
"anilist.enabled",
|
||||
src.anilist.enabled,
|
||||
resolved.anilist.enabled,
|
||||
"Expected boolean.",
|
||||
);
|
||||
}
|
||||
|
||||
const accessToken = asString(src.anilist.accessToken);
|
||||
if (accessToken !== undefined) {
|
||||
resolved.anilist.accessToken = accessToken;
|
||||
} else if (src.anilist.accessToken !== undefined) {
|
||||
warn(
|
||||
"anilist.accessToken",
|
||||
src.anilist.accessToken,
|
||||
resolved.anilist.accessToken,
|
||||
"Expected string.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (asBoolean(src.auto_start_overlay) !== undefined) {
|
||||
resolved.auto_start_overlay = src.auto_start_overlay as boolean;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user