Skip to content

Commit

Permalink
Merge pull request #7 from hyuse202/feat/mangadex
Browse files Browse the repository at this point in the history
Complete Mangadex
  • Loading branch information
zcrossoverz committed Jul 25, 2023
2 parents ed87804 + 235f6d9 commit 0b49d80
Show file tree
Hide file tree
Showing 3 changed files with 303 additions and 14 deletions.
11 changes: 11 additions & 0 deletions dist/src/lib/mangadex.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { AbstractMangaFactory, chapter, genre, responseChapter, responseDetailManga, responseListManga } from '../types/type';
export declare class Mangadex implements AbstractMangaFactory {
baseUrl: string;
all_genres: genre[];
constructor(baseUrl: string);
getListByGenre(genre: genre, page?: number | undefined, status?: any, sort?: any): Promise<responseListManga>;
getListLatestUpdate(page?: number | undefined): Promise<responseListManga>;
getDetailManga(url: string): Promise<responseDetailManga>;
getDataChapter(url_chapter: string, url?: string | undefined, path?: string | undefined, prev_chapter?: chapter | undefined, next_chapter?: chapter | undefined): Promise<responseChapter>;
search(keyword: string, page?: number | undefined): Promise<responseListManga>;
}
201 changes: 201 additions & 0 deletions dist/src/lib/mangadex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Mangadex = void 0;
const axios_1 = __importDefault(require("axios"));
class Mangadex {
constructor(baseUrl) {
this.baseUrl = baseUrl;
this.all_genres = [];
}
getListByGenre(genre, page, status, sort) {
return __awaiter(this, void 0, void 0, function* () {
throw new Error('Method not implemented.');
});
}
getListLatestUpdate(page) {
return __awaiter(this, void 0, void 0, function* () {
let totalData = 0;
let data = [];
let offset = 0;
if (page != undefined)
if (page >= 0 && page <= 9983)
offset = page;
else
throw new Error('Offset is out of bound');
yield axios_1.default
.get(`https://api.mangadex.org/manga?limit=16&offset=${offset}&contentRating[]=safe&contentRating[]=suggestive&contentRating[]=erotica&contentRating[]=pornographic`)
.then(function (response) {
const listLatestUpdate = response.data.data;
totalData = response.data.total;
data = listLatestUpdate.map((e, i) => {
return {
_id: offset + i,
title: e.attributes.title.en,
href: `/${e.id}`,
image_thumbnail: 'not implemented',
};
});
})
.catch(function (error) {
console.log(error);
});
return {
totalData,
canNext: offset <= 9967 ? true : false,
canPrev: offset === 0 ? false : true,
totalPage: 9983,
currentPage: offset,
data,
};
});
}
getDetailManga(url) {
return __awaiter(this, void 0, void 0, function* () {
const sourceId = url;
let author = 'null';
let title = 'null';
let status = 'null';
const genres = [];
yield axios_1.default
.get(`https://api.mangadex.org/manga/${sourceId}?includes[]=artist&includes[]=author&includes[]=cover_art`)
.then(function (response) {
const infoData = response.data.data;
author = infoData.relationships[0].attributes.name;
title = infoData.attributes.title.en;
status = infoData.attributes.status;
infoData.attributes.tags.map((e) => {
genres.push({
url: `https://mangadex.org/tag/` + e.id,
name: e.attributes.name.en,
path: '/tag/' + e.id,
});
});
})
.catch(function (error) {
console.log(error);
});
const chapters = [];
yield axios_1.default
.get(`https://api.mangadex.org/manga/${sourceId}/feed?translatedLanguage[]=en&includes[]=scanlation_group&&includes[]=user&order[volume]=desc&order[chapter]=desc&offset=0&contentRating[]=safe&contentRating[]=suggestive&contentRating[]=erotica&contentRating[]=pornographic`)
.then(function (response) {
const chapterData = response.data.data;
chapterData.map((e) => {
chapters.push({
path: '/' + e.id,
url: `https://mangadex.org/chapter/${e.id}`,
parent_href: '/chapter/' + e.id,
title: e.attributes.title,
});
});
})
.catch(function (error) {
console.log(error);
});
return {
path: this.baseUrl + `/title/${sourceId}`,
url,
author,
genres,
title,
status,
chapters,
};
});
}
getDataChapter(url_chapter, url, path, prev_chapter, next_chapter) {
return __awaiter(this, void 0, void 0, function* () {
const sourceId = url_chapter;
const chapter_data = [];
let title = 'null';
yield axios_1.default
.get(`https://api.mangadex.org/chapter/${sourceId}?includes[]=scanlation_group&includes[]=manga&includes[]=user`)
.then(function (response) {
const infoData = response.data.data;
let mangaId = 0;
for (let i = 0; i < infoData.relationships.length; i++)
if (infoData.relationships[i].type == 'manga') {
mangaId = i;
break;
}
title = `${infoData.relationships[mangaId].attributes.title.en} chap ${infoData.attributes.chapter} [${infoData.attributes.title}]`;
})
.catch(function (error) {
console.log(error);
});
yield axios_1.default
.get(`https://api.mangadex.org/at-home/server/${sourceId}?forcePort443=false`)
.then(function (response) {
const hash = response.data.chapter.hash;
response.data.chapter.data.map((e, i) => {
chapter_data.push({
_id: i,
src_origin: `https://uploads.mangadex.org/data/${hash}/${response.data.chapter.data[i]}`,
alt: title + ' id: ' + i,
});
});
})
.catch(function (error) {
console.log(error);
});
return {
url: `${this.baseUrl}/chapter/${sourceId}`,
path: `/chapter/${sourceId}`,
title,
chapter_data,
prev_chapter: null,
next_chapter: null,
};
});
}
search(keyword, page) {
return __awaiter(this, void 0, void 0, function* () {
let totalData = 0;
let data = [];
let offset = 0;
if (page != undefined)
if (page >= 0 && page <= 9983)
offset = page;
else
throw new Error('Offset is out of bound');
yield axios_1.default
.get(`https://api.mangadex.org/manga?limit=10&offset=${offset}&includes[]=cover_art&includes[]=artist&includes[]=author&contentRating[]=safe&contentRating[]=suggestive&contentRating[]=erotica&title=${keyword}&order[relevance]=desc`)
.then(function (response) {
totalData = response.data.total;
const listLatestUpdate = response.data.data;
totalData = response.data.total;
data = listLatestUpdate.map((e, i) => {
return {
_id: i,
title: e.attributes.title.en,
href: e.id,
image_thumbnail: 'not implemented',
};
});
})
.catch(function (error) {
console.log(error);
});
return {
totalData,
canNext: offset <= 9967 ? true : false,
canPrev: offset >= 16 ? true : false,
totalPage: 9983,
currentPage: offset,
data,
};
});
}
}
exports.Mangadex = Mangadex;
105 changes: 91 additions & 14 deletions src/lib/mangadex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,44 @@ export class Mangadex implements AbstractMangaFactory {
async getListLatestUpdate(
page?: number | undefined
): Promise<responseListManga> {
throw new Error('Method not implemented');
let totalData = 0;
let data: {
_id: number;
image_thumbnail: string;
title: string;
href: string;
}[] = [];
let offset = 0;
if (page != undefined)
if (page >= 0 && page <= 9983) offset = page;
else throw new Error('Offset is out of bound');
await axios
.get(
`https://api.mangadex.org/manga?limit=16&offset=${offset}&contentRating[]=safe&contentRating[]=suggestive&contentRating[]=erotica&contentRating[]=pornographic`
)
.then(function (response) {
const listLatestUpdate = response.data.data;
totalData = response.data.total;
data = listLatestUpdate.map((e: any, i: any) => {
return {
_id: offset + i,
title: e.attributes.title.en,
href: `/${e.id}`,
image_thumbnail: 'not implemented',
};
});
})
.catch(function (error) {
console.log(error);
});
return {
totalData,
canNext: offset <= 9967 ? true: false,
canPrev: offset === 0 ? false : true,
totalPage: 9983,
currentPage: offset,
data,
};
}
async getDetailManga(url: string): Promise<responseDetailManga> {
const sourceId = url;
Expand All @@ -46,31 +83,33 @@ export class Mangadex implements AbstractMangaFactory {
author = infoData.relationships[0].attributes.name;
title = infoData.attributes.title.en;
status = infoData.attributes.status;
for (let i = 0; i < response.data.data.attributes.tags.length; i++)
infoData.attributes.tags.map((e: any) => {
genres.push({
url: `https://mangadex.org/tag/` + infoData.attributes.tags[i].id,
name: infoData.attributes.tags[i].attributes.name.en,
path: '/tag/' + infoData.attributes.tags[i].id,
url: `https://mangadex.org/tag/` + e.id,
name: e.attributes.name.en,
path: '/tag/' + e.id,
});
});
})
.catch(function (error) {
console.log(error);
});
//Get info Manga Chapter
let chapters: chapter[] = [] as chapter[];
const chapters: chapter[] = [] as chapter[];
await axios
.get(
`https://api.mangadex.org/manga/${sourceId}/feed?translatedLanguage[]=en&includes[]=scanlation_group&&includes[]=user&order[volume]=desc&order[chapter]=desc&offset=0&contentRating[]=safe&contentRating[]=suggestive&contentRating[]=erotica&contentRating[]=pornographic`
)
.then(function (response) {
const chapterData = response.data.data;
for (let i = 0; i < chapterData.length; i++)
chapterData.map((e: any) => {
chapters.push({
path: '/' + chapterData[i].id,
url: `https://mangadex.org/chapter/${chapterData[i].id}`,
parent_href: '/chapter/' + chapterData[i].id,
title: chapterData[i].attributes.title,
path: '/' + e.id,
url: `https://mangadex.org/chapter/${e.id}`,
parent_href: '/chapter/' + e.id,
title: e.attributes.title,
});
});
})
.catch(function (error) {
console.log(error);
Expand Down Expand Up @@ -120,13 +159,13 @@ export class Mangadex implements AbstractMangaFactory {
)
.then(function (response) {
const hash = response.data.chapter.hash;
for (let i = 0; i < response.data.chapter.data.length; i++) {
response.data.chapter.data.map((e: any, i: number) => {
chapter_data.push({
_id: i,
src_origin: `https://uploads.mangadex.org/data/${hash}/${response.data.chapter.data[i]}`,
alt: title + ' id: ' + i,
});
}
});
})
.catch(function (error) {
console.log(error);
Expand All @@ -145,6 +184,44 @@ export class Mangadex implements AbstractMangaFactory {
keyword: string,
page?: number | undefined
): Promise<responseListManga> {
throw new Error('Method not implemented');
let totalData = 0;
let data: {
_id: number;
image_thumbnail: string;
title: string;
href: string;
}[] = [];
let offset = 0;
if (page != undefined)
if (page >= 0 && page <= 9983) offset = page;
else throw new Error('Offset is out of bound');
await axios
.get(
`https://api.mangadex.org/manga?limit=10&offset=${offset}&includes[]=cover_art&includes[]=artist&includes[]=author&contentRating[]=safe&contentRating[]=suggestive&contentRating[]=erotica&title=${keyword}&order[relevance]=desc`
)
.then(function (response) {
totalData = response.data.total;
const listLatestUpdate = response.data.data;
totalData = response.data.total;
data = listLatestUpdate.map((e: any, i: any) => {
return {
_id: i,
title: e.attributes.title.en,
href: e.id,
image_thumbnail: 'not implemented',
};
});
})
.catch(function (error) {
console.log(error);
});
return {
totalData,
canNext: offset <= 9967 ? true: false,
canPrev: offset >= 16 ? true: false,
totalPage: 9983,
currentPage: offset,
data,
};
}
}

0 comments on commit 0b49d80

Please sign in to comment.