fix: [Agitoon]: Update URL (#1083)

- updated url
- fix searching pageNo duplication
- fix cover image
- re-made the url works even if it is a redirect
This commit is contained in:
Justin COLLON
2024-07-22 15:43:30 +02:00
committed by GitHub
parent 660b5bbf01
commit 4bb772f207
+37 -11
View File
@@ -7,14 +7,24 @@ class Agitoon implements Plugin.PluginBase {
id = 'agit.xyz'; id = 'agit.xyz';
name = 'Agitoon'; name = 'Agitoon';
icon = 'src/kr/agitoon/icon.png'; icon = 'src/kr/agitoon/icon.png';
site = 'https://agit660.xyz'; site = 'https://agit664.xyz';
version = '3.0.3'; version = '3.1.0';
static url: string | undefined;
async checkUrl() {
if (!Agitoon.url) {
const res = await fetchApi(this.site);
if (!res.ok) Agitoon.url = this.site;
else Agitoon.url = res.url.replace(/\/$/, '');
}
}
async popularNovels( async popularNovels(
pageNo: number, pageNo: number,
{ showLatestNovels }: Plugin.PopularNovelsOptions, { showLatestNovels }: Plugin.PopularNovelsOptions,
): Promise<Plugin.NovelItem[]> { ): Promise<Plugin.NovelItem[]> {
const res = await fetchApi(this.site + '/novel/index.update.php', { await this.checkUrl();
const res = await fetchApi(Agitoon.url + '/novel/index.update.php', {
headers: { headers: {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8', 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
}, },
@@ -44,7 +54,7 @@ class Agitoon implements Plugin.PluginBase {
resJson?.list?.forEach(novel => resJson?.list?.forEach(novel =>
novels.push({ novels.push({
name: novel.wr_subject, name: novel.wr_subject,
cover: this.site + novel.np_dir + '/thumbnail/' + novel.np_thumbnail, cover: Agitoon.url + novel.np_dir + '/thumbnail/' + novel.np_thumbnail,
path: novel.wr_id, path: novel.wr_id,
}), }),
); );
@@ -53,6 +63,7 @@ class Agitoon implements Plugin.PluginBase {
} }
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> { async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
await this.checkUrl();
const result = await fetchApi(this.resolveUrl(novelPath, true)).then(res => const result = await fetchApi(this.resolveUrl(novelPath, true)).then(res =>
res.text(), res.text(),
); );
@@ -61,7 +72,7 @@ class Agitoon implements Plugin.PluginBase {
const novel: Plugin.SourceNovel = { const novel: Plugin.SourceNovel = {
path: novelPath, path: novelPath,
name: loadedCheerio('h5.pt-2').text(), name: loadedCheerio('h5.pt-2').text(),
cover: this.site + loadedCheerio('div.col-5.pr-0.pl-0 img').attr('src'), cover: loadedCheerio('div.col-5.pr-0.pl-0 img').attr('src'),
summary: loadedCheerio('.pt-1.mt-1.pb-1.mb-1').text(), summary: loadedCheerio('.pt-1.mt-1.pb-1.mb-1').text(),
}; };
@@ -79,7 +90,7 @@ class Agitoon implements Plugin.PluginBase {
} }
const chapters: Plugin.ChapterItem[] = []; const chapters: Plugin.ChapterItem[] = [];
const res = await fetchApi(this.site + '/novel/list.update.php', { const res = await fetchApi(Agitoon.url + '/novel/list.update.php', {
headers: { headers: {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8', 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
}, },
@@ -107,6 +118,7 @@ class Agitoon implements Plugin.PluginBase {
} }
async parseChapter(chapterPath: string): Promise<string> { async parseChapter(chapterPath: string): Promise<string> {
await this.checkUrl();
const result = await fetchApi(this.resolveUrl(chapterPath)).then(res => const result = await fetchApi(this.resolveUrl(chapterPath)).then(res =>
res.text(), res.text(),
); );
@@ -122,8 +134,13 @@ class Agitoon implements Plugin.PluginBase {
return content; return content;
} }
async searchNovels(searchTerm: string): Promise<Plugin.NovelItem[]> { async searchNovels(
const rawResults = await fetchApi(this.site + '/novel/search.php', { searchTerm: string,
pageNo: number,
): Promise<Plugin.NovelItem[]> {
if (pageNo !== 1) return [];
await this.checkUrl();
const rawResults = await fetchApi(Agitoon.url + '/novel/search.php', {
headers: { headers: {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8', 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
}, },
@@ -141,7 +158,7 @@ class Agitoon implements Plugin.PluginBase {
novels.push({ novels.push({
name: novel.wr_subject, name: novel.wr_subject,
cover: cover:
this.site + '/' + novel.np_dir + '/thumbnail/' + novel.np_thumbnail, Agitoon.url + '/' + novel.np_dir + '/thumbnail/' + novel.np_thumbnail,
path: novel.wr_id, path: novel.wr_id,
}), }),
); );
@@ -149,8 +166,17 @@ class Agitoon implements Plugin.PluginBase {
return novels; return novels;
} }
resolveUrl = (path: string, isNovel?: boolean) => resolveUrl(path: string, isNovel?: boolean) {
this.site + (isNovel ? '/novel/list/' : '/novel/view/') + path; if (!Agitoon.url)
fetchApi(this.site).then(
res => (Agitoon.url = res.url.replace(/\/$/, '')),
);
return (
(Agitoon.url ? Agitoon.url : this.site) +
(isNovel ? '/novel/list/' : '/novel/view/') +
path
);
}
} }
export default new Agitoon(); export default new Agitoon();