fix(russian): fix ranobelib (#2418)

This commit is contained in:
Ahjie521
2026-08-16 12:42:25 +07:00
committed by GitHub
parent 4b84e48fcc
commit a5c01ce25d
+42 -60
View File
@@ -29,7 +29,7 @@ class RLIB implements Plugin.PluginBase {
name = 'RanobeLib'; name = 'RanobeLib';
site = 'https://ranobelib.me'; site = 'https://ranobelib.me';
apiSite = 'https://api.cdnlibs.org/api/manga/'; apiSite = 'https://api.cdnlibs.org/api/manga/';
version = '2.2.4'; version = '2.2.6';
icon = 'src/ru/ranobelib/icon.png'; icon = 'src/ru/ranobelib/icon.png';
webStorageUtilized = true; webStorageUtilized = true;
imageRequestInit = { imageRequestInit = {
@@ -161,46 +161,23 @@ class RLIB implements Plugin.PluginBase {
).then(res => res.json()); ).then(res => res.json());
if (chaptersJSON.data?.length) { if (chaptersJSON.data?.length) {
let chapters: Plugin.ChapterItem[] = chaptersJSON.data.flatMap(chapter => const chapters: Plugin.ChapterItem[] = chaptersJSON.data.flatMap(
chapter.branches.map(({ branch_id, created_at }) => { chapter =>
const bId = String(branch_id ?? '0'); chapter.branches.map(({ branch_id, created_at }) => {
return { const bId = String(branch_id ?? '0');
name: `Том ${chapter.volume} Глава ${chapter.number}${ return {
chapter.name ? ' ' + chapter.name.trim() : '' name: `Том ${chapter.volume} Глава ${chapter.number}${
}`, chapter.name ? ' ' + chapter.name.trim() : ''
path: `${novelPath}/${chapter.volume}/${chapter.number}/${bId}`, }`,
releaseTime: created_at ? dayjs(created_at).format('LLL') : null, path: `${novelPath}/${chapter.volume}/${chapter.number}/${bId}`,
chapterNumber: chapter.index, releaseTime: created_at ? dayjs(created_at).format('LLL') : null,
page: branch_name[bId] || 'Неизвестный', chapterNumber: chapter.index,
}; scanlator: branch_name[bId] || 'Неизвестный',
}), };
}),
); );
if (chapters.length) { if (chapters.length) {
const uniquePages = new Set(chapters.map(c => c.page));
if (uniquePages.size === 1) {
// If only one unique page value, set page to undefined for all chapters
// Need more investigation one app side for single page shenanigans
chapters = chapters.map(chapter => ({
...chapter,
page: undefined,
}));
} else if (data.teams?.length > 1) {
// Original sorting logic for multiple pages, for reasons chapters overlap with one another
chapters.sort((chapterA, chapterB) => {
if (
chapterA.page &&
chapterB.page &&
chapterA.page !== chapterB.page
) {
return chapterA.page.localeCompare(chapterB.page);
}
return (
(chapterA.chapterNumber || 0) - (chapterB.chapterNumber || 0)
);
});
}
novel.chapters = chapters; novel.chapters = chapters;
} }
} }
@@ -209,31 +186,37 @@ class RLIB implements Plugin.PluginBase {
async parseChapter(chapterPath: string): Promise<string> { async parseChapter(chapterPath: string): Promise<string> {
const [slug, volume, number, branch_id] = chapterPath.split('/'); const [slug, volume, number, branch_id] = chapterPath.split('/');
let chapterText = ''; if (!slug || !volume || !number) {
throw new Error(`Invalid chapter path: ${chapterPath}`);
if (slug && volume && number) { }
const result: { data: DataClass } = await fetchApi( const url =
this.apiSite + this.apiSite +
slug + slug +
'/chapter?' + '/chapter?' +
(branch_id ? 'branch_id=' + branch_id + '&' : '') + (branch_id ? 'branch_id=' + branch_id + '&' : '') +
'number=' + 'number=' +
number + number +
'&volume=' + '&volume=' +
volume, volume;
{ headers: this.getHeaders() }, const res = await fetchApi(url, { headers: this.getHeaders() });
).then(res => res.json()); if (!res.ok) {
const content = result?.data?.content; throw new Error(`Could not load chapter (HTTP ${res.status})`);
chapterText = }
typeof content === 'object' && content?.type === 'doc' const result: { data: DataClass } = await res.json();
? jsonToHtml(content.content, result.data.attachments || []) const content = result?.data?.content;
: (content as string) || ''; const chapterText =
typeof content === 'object' && content?.type === 'doc'
? jsonToHtml(content.content, result.data.attachments || [])
: (content as string) || '';
if (!chapterText) {
throw new Error('Could not load chapter');
} }
return chapterText; return chapterText;
} }
async searchNovels(searchTerm: string): Promise<Plugin.NovelItem[]> { async searchNovels(searchTerm: string): Promise<Plugin.NovelItem[]> {
const url = this.apiSite + '?site_id[0]=3&q=' + searchTerm; const url =
this.apiSite + '?site_id[0]=3&q=' + encodeURIComponent(searchTerm);
const result: TopLevel = await fetchApi(url, { const result: TopLevel = await fetchApi(url, {
headers: this.getHeaders(), headers: this.getHeaders(),
}).then(res => res.json()); }).then(res => res.json());
@@ -276,8 +259,7 @@ class RLIB implements Plugin.PluginBase {
getUser = () => { getUser = () => {
const user = storage.get('user') as const user = storage.get('user') as
| { token: string; id: number } { token: string; id: number } | undefined;
| undefined;
if (user) { if (user) {
return { token: { Authorization: 'Bearer ' + user.token }, ui: user.id }; return { token: { Authorization: 'Bearer ' + user.token }, ui: user.id };
} }