Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typography has been added to mangadex #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 32 additions & 20 deletions src/lib/mangadex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import {
responseDetailManga,
responseListManga,
} from '../types/type';
import {
ResponseSearchMangaDex,
ResponseChapterData,
ResponseDataChapterInfoData,
ResponseDetailsChapters,
ResponseDetailsGenres,
} from '../types/mangadex';
export class Mangadex implements AbstractMangaFactory {
baseUrl: string;
all_genres: genre[];
Expand All @@ -16,7 +23,7 @@ export class Mangadex implements AbstractMangaFactory {
this.baseUrl = baseUrl;
this.all_genres = [] as genre[];
}
async getListByGenre(
getListByGenre(
genre: genre,
page?: number | undefined,
status?: any,
Expand All @@ -43,10 +50,10 @@ export class Mangadex implements AbstractMangaFactory {
.get(
`https://api.mangadex.org/manga?limit=16&offset=${offset}&contentRating[]=safe&contentRating[]=suggestive&contentRating[]=erotica&contentRating[]=pornographic`
)
.then(function (response) {
.then(function (response: ResponseSearchMangaDex) {
const listLatestUpdate = response.data.data;
totalData = response.data.total;
data = listLatestUpdate.map((e: any, i: any) => {
data = listLatestUpdate.map((e, i) => {
return {
_id: offset + i,
title: e.attributes.title.en,
Expand All @@ -60,7 +67,7 @@ export class Mangadex implements AbstractMangaFactory {
});
return {
totalData,
canNext: offset <= 9967 ? true: false,
canNext: offset <= 9967 ? true : false,
canPrev: offset === 0 ? false : true,
totalPage: 9983,
currentPage: offset,
Expand All @@ -79,11 +86,12 @@ export class Mangadex implements AbstractMangaFactory {
`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;
const responseAxios = response.data as ResponseDetailsGenres;
const infoData = responseAxios.data;
author = infoData.relationships[0].attributes?.name ?? '';
title = infoData.attributes.title.en;
status = infoData.attributes.status;
infoData.attributes.tags.map((e: any) => {
infoData.attributes.tags.map((e) => {
genres.push({
url: `https://mangadex.org/tag/` + e.id,
name: e.attributes.name.en,
Expand All @@ -98,11 +106,12 @@ export class Mangadex implements AbstractMangaFactory {
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`
`https://api.mangadex.org/manga/${sourceId}/feed?translatedLanguage[]=es-la&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: any) => {
const responseAxio = response.data as ResponseDetailsChapters;
const chapterData = responseAxio.data;
chapterData.map((e) => {
chapters.push({
path: '/' + e.id,
url: `https://mangadex.org/chapter/${e.id}`,
Expand Down Expand Up @@ -140,14 +149,16 @@ export class Mangadex implements AbstractMangaFactory {
`https://api.mangadex.org/chapter/${sourceId}?includes[]=scanlation_group&includes[]=manga&includes[]=user`
)
.then(function (response) {
const infoData = response.data.data;
const responseAxios = response.data as ResponseDataChapterInfoData;
const infoData = responseAxios.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}]`;
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
title = `${infoData.relationships[mangaId].attributes.title?.en} chap ${infoData.attributes.chapter} [${infoData.attributes.title}]`;
})
.catch(function (error) {
console.log(error);
Expand All @@ -158,12 +169,13 @@ export class Mangadex implements AbstractMangaFactory {
`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: any, i: number) => {
const responseAxios = response.data as ResponseChapterData;
const hash = responseAxios.chapter.hash;
responseAxios.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,
src_origin: `https://uploads.mangadex.org/data/${hash}/${responseAxios.chapter.data[i]}`,
alt: `${title} id: ${i}`,
});
});
})
Expand Down Expand Up @@ -199,11 +211,11 @@ export class Mangadex implements AbstractMangaFactory {
.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) {
.then(function (response: ResponseSearchMangaDex) {
totalData = response.data.total;
const listLatestUpdate = response.data.data;
totalData = response.data.total;
data = listLatestUpdate.map((e: any, i: any) => {
data = listLatestUpdate.map((e, i) => {
return {
_id: i,
title: e.attributes.title.en,
Expand All @@ -217,8 +229,8 @@ export class Mangadex implements AbstractMangaFactory {
});
return {
totalData,
canNext: offset <= 9967 ? true: false,
canPrev: offset >= 16 ? true: false,
canNext: offset <= 9967 ? true : false,
canPrev: offset >= 16 ? true : false,
totalPage: 9983,
currentPage: offset,
data,
Expand Down
13 changes: 13 additions & 0 deletions src/types/mangadex/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ResponseChapterData } from './responseChapterData';
import { ResponseDataChapterInfoData } from './responseDataChapterInfoData';
import { ResponseDetailsChapters } from './responseDetailsChapters';
import { ResponseDetailsGenres } from './responseDetailsGenres';
import { ResponseSearchMangaDex } from './responseSearch';

export {
ResponseChapterData,
ResponseDataChapterInfoData,
ResponseDetailsChapters,
ResponseDetailsGenres,
ResponseSearchMangaDex,
};
11 changes: 11 additions & 0 deletions src/types/mangadex/responseChapterData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export type ResponseChapterData = {
result: string;
baseUrl: string;
chapter: _Chapter;
};

type _Chapter = {
hash: string;
data: string[];
dataSaver: string[];
};
135 changes: 135 additions & 0 deletions src/types/mangadex/responseDataChapterInfoData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
export type ResponseDataChapterInfoData = {
result: string;
response: string;
data: _Data;
};

type _Data = {
id: string;
type: string;
attributes: _DataAttributes;
relationships: _Relationship[];
};

type _DataAttributes = {
volume: string;
chapter: string;
title: string;
translatedLanguage: string;
externalUrl: null;
publishAt: string;
readableAt: string;
createdAt: string;
updatedAt: string;
pages: number;
version: number;
};

type _Relationship = {
id: string;
type: string;
attributes: _RelationshipAttributes;
};

type _RelationshipAttributes = {
name?: string;
altNames?: unknown[];
locked?: boolean;
website?: string;
ircServer?: null;
ircChannel?: null;
discord?: string;
contactEmail?: string;
description?: _Description[] | null;
twitter?: string;
mangaUpdates?: null;
focusedLanguages?: string[];
official?: boolean;
verified?: boolean;
inactive?: boolean;
publishDelay?: null;
exLicensed?: boolean;
createdAt?: string;
updatedAt?: string;
version: number;
title?: _Title;
altTitles?: _AltTitle[];
isLocked?: boolean;
links?: _Links;
originalLanguage?: string;
lastVolume?: string;
lastChapter?: string;
publicationDemographic?: string;
status?: string;
year?: number;
contentRating?: string;
tags?: _Tag[];
state?: string;
chapterNumbersResetOnNewVolume?: boolean;
availableTranslatedLanguages?: string[];
latestUploadedChapter?: string;
username?: string;
roles?: string[];
};

type _Links = {
al: string;
ap: string;
bw: string;
kt: string;
mu: string;
amz: string;
cdj: string;
ebj: string;
mal: string;
raw: string;
engtl: string;
};

type _Tag = {
id: string;
type: string;
attributes: _TagAttributes;
relationships: unknown[];
};

type _TagAttributes = {
name: _Title;
description: _Description;
group: string;
version: number;
};

type _Title = {
en: string;
};

type _AltTitle = {
ko?: string;
my?: string;
th?: string;
bn?: string;
ne?: string;
zh?: string;
'zh-hk'?: string;
mn?: string;
ar?: string;
fa?: string;
he?: string;
vi?: string;
ru?: string;
ms?: string;
uk?: string;
ta?: string;
hi?: string;
kk?: string;
ja?: string;
};

type _Description = {
en: string;
run: string;
uk: string;
'es-la': string;
'pr-br': string;
};
64 changes: 64 additions & 0 deletions src/types/mangadex/responseDetailsChapters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
export type ResponseDetailsChapters = {
result: string;
response: string;
data: Datum[];
limit: number;
offset: number;
total: number;
};

type Datum = {
id: string;
type: string;
attributes: DatumAttributes;
relationships: Relationship[];
};

type DatumAttributes = {
volume: string;
chapter: string;
title: string;
translatedLanguage: string;
externalUrl: null;
publishAt: string;
readableAt: string;
createdAt: string;
updatedAt: string;
pages: number;
version: number;
};

type Relationship = {
id: string;
type: string;
attributes?: RelationshipAttributes;
};

type RelationshipAttributes = {
name?: string;
altNames?: AltName[];
locked?: boolean;
website?: string;
ircServer?: null;
ircChannel?: null;
discord?: string;
contactEmail?: string;
description?: string;
twitter?: string;
mangaUpdates?: string;
focusedLanguages?: string[];
official?: boolean;
verified?: boolean;
inactive?: boolean;
exLicensed?: boolean;
createdAt?: string;
updatedAt?: string;
version: number;
publishDelay?: null;
username?: string;
roles?: string[];
};

type AltName = {
en: string;
};
Loading