fix(russian): fix ranobelib (#2418)
This commit is contained in:
@@ -29,7 +29,7 @@ class RLIB implements Plugin.PluginBase {
|
||||
name = 'RanobeLib';
|
||||
site = 'https://ranobelib.me';
|
||||
apiSite = 'https://api.cdnlibs.org/api/manga/';
|
||||
version = '2.2.4';
|
||||
version = '2.2.6';
|
||||
icon = 'src/ru/ranobelib/icon.png';
|
||||
webStorageUtilized = true;
|
||||
imageRequestInit = {
|
||||
@@ -161,7 +161,8 @@ class RLIB implements Plugin.PluginBase {
|
||||
).then(res => res.json());
|
||||
|
||||
if (chaptersJSON.data?.length) {
|
||||
let chapters: Plugin.ChapterItem[] = chaptersJSON.data.flatMap(chapter =>
|
||||
const chapters: Plugin.ChapterItem[] = chaptersJSON.data.flatMap(
|
||||
chapter =>
|
||||
chapter.branches.map(({ branch_id, created_at }) => {
|
||||
const bId = String(branch_id ?? '0');
|
||||
return {
|
||||
@@ -171,36 +172,12 @@ class RLIB implements Plugin.PluginBase {
|
||||
path: `${novelPath}/${chapter.volume}/${chapter.number}/${bId}`,
|
||||
releaseTime: created_at ? dayjs(created_at).format('LLL') : null,
|
||||
chapterNumber: chapter.index,
|
||||
page: branch_name[bId] || 'Неизвестный',
|
||||
scanlator: branch_name[bId] || 'Неизвестный',
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -209,10 +186,10 @@ class RLIB implements Plugin.PluginBase {
|
||||
|
||||
async parseChapter(chapterPath: string): Promise<string> {
|
||||
const [slug, volume, number, branch_id] = chapterPath.split('/');
|
||||
let chapterText = '';
|
||||
|
||||
if (slug && volume && number) {
|
||||
const result: { data: DataClass } = await fetchApi(
|
||||
if (!slug || !volume || !number) {
|
||||
throw new Error(`Invalid chapter path: ${chapterPath}`);
|
||||
}
|
||||
const url =
|
||||
this.apiSite +
|
||||
slug +
|
||||
'/chapter?' +
|
||||
@@ -220,20 +197,26 @@ class RLIB implements Plugin.PluginBase {
|
||||
'number=' +
|
||||
number +
|
||||
'&volume=' +
|
||||
volume,
|
||||
{ headers: this.getHeaders() },
|
||||
).then(res => res.json());
|
||||
volume;
|
||||
const res = await fetchApi(url, { headers: this.getHeaders() });
|
||||
if (!res.ok) {
|
||||
throw new Error(`Could not load chapter (HTTP ${res.status})`);
|
||||
}
|
||||
const result: { data: DataClass } = await res.json();
|
||||
const content = result?.data?.content;
|
||||
chapterText =
|
||||
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;
|
||||
}
|
||||
|
||||
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, {
|
||||
headers: this.getHeaders(),
|
||||
}).then(res => res.json());
|
||||
@@ -276,8 +259,7 @@ class RLIB implements Plugin.PluginBase {
|
||||
|
||||
getUser = () => {
|
||||
const user = storage.get('user') as
|
||||
| { token: string; id: number }
|
||||
| undefined;
|
||||
{ token: string; id: number } | undefined;
|
||||
if (user) {
|
||||
return { token: { Authorization: 'Bearer ' + user.token }, ui: user.id };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user