Skip to content

Commit

Permalink
EarlyManga: fix website
Browse files Browse the repository at this point in the history
Api changes breaks bookmarks 🤷 
Reload manga list !

Fixes #7266
  • Loading branch information
MikeZeDev authored Jul 17, 2024
1 parent 4f47803 commit 7e75d4f
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions src/web/mjs/connectors/EarlyManga.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Connector from '../engine/Connector.mjs';
import Manga from '../engine/Manga.mjs';

export default class EarlyManga extends Connector {

constructor() {
super();
super.id = 'earlymanga';
Expand All @@ -17,46 +19,61 @@ export default class EarlyManga extends Connector {
return mangaList;
}
async _getMangasFromPage(page) {
const uri = new URL('/api/search/advanced?page='+page, this.url);
const request = new Request(uri, this.requestOptions);
let data = await this.fetchJSON(request);
const uri = new URL('/api/search/advanced/post?page='+page, this.url);
const body = {
'list_order': 'desc'
};
const request = new Request(uri, {
method: 'POST', body: JSON.stringify(body), headers: {
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/json'
}
});

const data = await this.fetchJSON(request);
return data.data.map(item => {
const id = { id: item.id, slug: item.slug };
return {
id: '/manga/' + item.slug.trim(),
title: item.title.trim()
id : JSON.stringify(id),
title : item.title.trim()
};
});
}

async _getChapters(manga) {
const mangaid = manga.id.match(/\/manga\/(\S+)/)[1];
const uri = new URL('/api/manga/'+mangaid+'/chapterlist', this.url);
const mangaid = JSON.parse(manga.id);
const uri = new URL(`/api/manga/${mangaid.id}/${mangaid.slug}/chapterlist`, this.url);
const request = new Request(uri, this.requestOptions);
const data = await this.fetchJSON(request);
return data.map(item => {
const id = { id: item.id, slug: item.slug };
return {
id: '/manga/' + mangaid + '/chapter-'+item.slug,
title: 'Chapter '+item.chapter_number
id : JSON.stringify(id),
title : 'Chapter ' + item.chapter_number
};
});
}

async _getPages(chapter) {
const uri = new URL('/api'+chapter.id, this.url);
const mangaid = JSON.parse(chapter.manga.id);
const chapterid = JSON.parse(chapter.id);
const uri = new URL(`/api/manga/${mangaid.id}/${mangaid.slug}/${chapterid.id}/chapter-${chapterid.slug}`, this.url);

const request = new Request(uri, this.requestOptions);
let data = await this.fetchJSON(request);
let manga_id = data.chapter.manga_id;
return data.chapter.images.map(item => {
return this.url+'/storage/uploads/manga/manga_'+manga_id+'/chapter_'+data.chapter.slug+'/'+item;
const data = await this.fetchJSON(request);
return data.chapter.images.map(page => {
const path = !data.chapter.on_disk ? 'https://images.earlym.org/manga' : '/storage/uploads/manga';
return new URL(`${path}/manga_${data.chapter.manga_id}/chapter_${data.chapter.slug}/${page}`, this.url).href;
});
}

async _getMangaFromURI(uri) {
const mangaid = uri.href.match(/\/manga\/(\S+)/)[1];
const apicallurl = new URL('/api/manga/'+mangaid, this.url);
const request = new Request(apicallurl, this.requestOptions);
let data = await this.fetchJSON(request);
const id = uri.pathname;
const data = await this.fetchJSON(request);
const id = { id: data.main_manga.id, slug: data.main_manga.slug };
const title = data.main_manga.title.trim();
return new Manga(this, id, title);
return new Manga(this, JSON.stringify(id), title);
}
}

0 comments on commit 7e75d4f

Please sign in to comment.