Skip to content

Commit 49c6523

Browse files
committed
fix(multisrc/novelfire): send one language and support several tags
Novel Phoenix's language control is a single-value select, so the checkbox list silently sent only its first entry. It is now a picker with an All option, and country_id is only sent when one is chosen. The tags field was free text with autocomplete: suggestions queried the whole field, so a second tag could never be suggested, and a suggestion replaced everything already typed. It is now a multi-text field, which also means a picked tag shows its name instead of its id. Tag lists are validated before being cached; an error body used to be stored as an empty list for a week, making every tag name unresolvable.
1 parent cc06968 commit 49c6523

2 files changed

Lines changed: 41 additions & 17 deletions

File tree

‎plugins/multisrc/novelfire/filters/novelphoenix.json‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,12 @@
7676
},
7777
"language": {
7878
"label": "Language",
79-
"value": [],
79+
"value": "-1",
8080
"options": [
81+
{
82+
"label": "All",
83+
"value": "-1"
84+
},
8185
{
8286
"label": "Chinese Novel",
8387
"value": "1"
@@ -95,7 +99,7 @@
9599
"value": "4"
96100
}
97101
],
98-
"type": "Checkbox"
102+
"type": "Picker"
99103
},
100104
"genre_operator": {
101105
"label": "Genres (And/Or/Exclude)",
@@ -444,10 +448,10 @@
444448
"type": "Picker"
445449
},
446450
"tags": {
447-
"label": "Tags (comma separated, e.g. Isekai, Weak to Strong)",
448-
"value": "",
451+
"label": "Tags",
452+
"value": [],
449453
"autocomplete": true,
450-
"type": "Text"
454+
"type": "MultiText"
451455
},
452456
"content_rating": {
453457
"label": "Content Rating",

‎plugins/multisrc/novelfire/template.ts‎

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,10 @@ export class NovelFirePlugin implements Plugin.PagePlugin {
227227
// Novel Phoenix ignores the repeated `country_id[]` array and expects a
228228
// single `country_id`, plus `chapter_min` / `chapter_max` instead of the
229229
// combined `totalchapter` range. Novel Fire still uses the old shape.
230-
const language = filters?.language?.value?.[0];
231-
if (language) params.append('country_id', language);
230+
const language = filters?.language?.value;
231+
if (typeof language === 'string' && language !== '-1') {
232+
params.append('country_id', language);
233+
}
232234

233235
const chapterRange = filters?.chapters?.value;
234236
if (chapterRange && chapterRange !== '0') {
@@ -323,12 +325,18 @@ export class NovelFirePlugin implements Plugin.PagePlugin {
323325

324326
this.tagIndexPromise = (async () => {
325327
const cacheKey = `${this.id}_tagIndex`;
328+
const unexpected = () =>
329+
createPluginError(PluginError.InvalidResponse, {
330+
message: 'Source returned an unexpected tag list.',
331+
});
332+
326333
try {
327334
const cached = JSON.parse(String(storage.get(cacheKey) || 'null'));
328335
if (
329336
cached &&
330337
Date.now() - Number(cached.at) < TAGS_CACHE_TTL_MS &&
331-
Array.isArray(cached.tags)
338+
Array.isArray(cached.tags) &&
339+
cached.tags.length > 0
332340
) {
333341
return this.buildTagIndex(cached.tags);
334342
}
@@ -339,18 +347,28 @@ export class NovelFirePlugin implements Plugin.PagePlugin {
339347
const response = await fetchApi(`${this.site}ajax/getTags`);
340348
checkResponse(response);
341349

342-
let payload: { data?: { id: number | string; name: string }[] };
350+
let payload: { data?: unknown };
343351
try {
344352
payload = JSON.parse(await response.text());
345353
} catch {
346-
throw createPluginError(PluginError.InvalidResponse, {
347-
message: 'Source returned an unexpected tag list.',
348-
});
354+
throw unexpected();
349355
}
350-
const tags = (payload.data || []).map(tag => ({
351-
id: String(tag.id),
352-
name: String(tag.name).trim(),
353-
}));
356+
357+
// An error body is still valid JSON, and caching one would leave every
358+
// tag name unresolvable until the cache expires.
359+
const rows = payload?.data;
360+
if (!Array.isArray(rows)) throw unexpected();
361+
362+
const tags = rows.flatMap(row => {
363+
const tag = row as { id?: unknown; name?: unknown } | null;
364+
const id = tag?.id;
365+
const name = typeof tag?.name === 'string' ? tag.name.trim() : '';
366+
const idText =
367+
typeof id === 'number' || typeof id === 'string' ? String(id) : '';
368+
return idText && name ? [{ id: idText, name }] : [];
369+
});
370+
371+
if (tags.length === 0) throw unexpected();
354372

355373
storage.set(cacheKey, JSON.stringify({ at: Date.now(), tags }));
356374
return this.buildTagIndex(tags);
@@ -417,9 +435,11 @@ export class NovelFirePlugin implements Plugin.PagePlugin {
417435
? index.tags.filter(tag => tag.name.toLowerCase().includes(needle))
418436
: index.tags;
419437

438+
// The name is the value so a picked tag reads as "Isekai" rather than its
439+
// id; resolveTagIds turns names back into ids when searching.
420440
return matches
421441
.slice(0, 20)
422-
.map(tag => ({ label: tag.name, value: tag.id }));
442+
.map(tag => ({ label: tag.name, value: tag.name }));
423443
}
424444

425445
// Both chapter sources (AJAX rows and the HTML fallback) end up here, so

0 commit comments

Comments
 (0)