Added remaining possible types, removed type ifs
This commit is contained in:
parent
eb28e96769
commit
93950947b8
1 changed files with 6 additions and 74 deletions
|
|
@ -19,7 +19,12 @@ export class MALAPIManga extends APIModel {
|
||||||
this.types = [MediaType.Manga];
|
this.types = [MediaType.Manga];
|
||||||
this.typeMappings = new Map<string, string>();
|
this.typeMappings = new Map<string, string>();
|
||||||
this.typeMappings.set('manga', 'manga');
|
this.typeMappings.set('manga', 'manga');
|
||||||
|
this.typeMappings.set('manhwa', 'manhwa');
|
||||||
|
this.typeMappings.set('doujinshi', 'doujin');
|
||||||
|
this.typeMappings.set('one-shot', 'oneshot');
|
||||||
|
this.typeMappings.set('manhua', 'manhua');
|
||||||
this.typeMappings.set('light novel', 'lnovel');
|
this.typeMappings.set('light novel', 'lnovel');
|
||||||
|
this.typeMappings.set('novel', 'novel');
|
||||||
}
|
}
|
||||||
|
|
||||||
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
|
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
|
||||||
|
|
@ -40,7 +45,6 @@ export class MALAPIManga extends APIModel {
|
||||||
|
|
||||||
for (const result of data.data) {
|
for (const result of data.data) {
|
||||||
const type = this.typeMappings.get(result.type?.toLowerCase());
|
const type = this.typeMappings.get(result.type?.toLowerCase());
|
||||||
if (type === undefined) {
|
|
||||||
ret.push(
|
ret.push(
|
||||||
new MangaModel({
|
new MangaModel({
|
||||||
subType: type,
|
subType: type,
|
||||||
|
|
@ -71,41 +75,7 @@ export class MALAPIManga extends APIModel {
|
||||||
personalRating: 0,
|
personalRating: 0,
|
||||||
},
|
},
|
||||||
} as MangaModel)
|
} as MangaModel)
|
||||||
);
|
)
|
||||||
}
|
|
||||||
if (type === 'manga' || type === "lnovel") {
|
|
||||||
ret.push(
|
|
||||||
new MangaModel({
|
|
||||||
subType: type,
|
|
||||||
title: result.title,
|
|
||||||
synopsis: result.synopsis,
|
|
||||||
englishTitle: result.title_english ?? result.title,
|
|
||||||
alternateTitles: result.titles?.map((x: any) => x.title) ?? [],
|
|
||||||
year: result.year ?? result.published?.prop?.from?.year ?? '',
|
|
||||||
dataSource: this.apiName,
|
|
||||||
url: result.url,
|
|
||||||
id: result.mal_id,
|
|
||||||
|
|
||||||
genres: result.genres?.map((x: any) => x.name) ?? [],
|
|
||||||
authors: result.authors?.map((x: any) => x.name) ?? [],
|
|
||||||
chapters: result.chapters,
|
|
||||||
volumes: result.volumes,
|
|
||||||
onlineRating: result.score ?? 0,
|
|
||||||
image: result.images?.jpg?.image_url ?? '',
|
|
||||||
|
|
||||||
released: true,
|
|
||||||
publishedFrom: new Date(result.published?.from).toLocaleDateString() ?? 'unknown',
|
|
||||||
publishedTo: new Date(result.published?.to).toLocaleDateString() ?? 'unknown',
|
|
||||||
status: result.status,
|
|
||||||
|
|
||||||
userData: {
|
|
||||||
watched: false,
|
|
||||||
lastWatched: '',
|
|
||||||
personalRating: 0,
|
|
||||||
},
|
|
||||||
} as MangaModel)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
@ -126,7 +96,6 @@ export class MALAPIManga extends APIModel {
|
||||||
const result = data.data;
|
const result = data.data;
|
||||||
|
|
||||||
const type = this.typeMappings.get(result.type?.toLowerCase());
|
const type = this.typeMappings.get(result.type?.toLowerCase());
|
||||||
if (type === undefined) {
|
|
||||||
const model = new MangaModel({
|
const model = new MangaModel({
|
||||||
subType: type,
|
subType: type,
|
||||||
title: result.title,
|
title: result.title,
|
||||||
|
|
@ -159,41 +128,4 @@ export class MALAPIManga extends APIModel {
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === 'manga' || type === 'lnovel') {
|
|
||||||
const model = new MangaModel({
|
|
||||||
subType: type,
|
|
||||||
title: result.title,
|
|
||||||
synopsis: result.synopsis,
|
|
||||||
englishTitle: result.title_english ?? result.title,
|
|
||||||
alternateTitles: result.titles?.map((x: any) => x.title) ?? [],
|
|
||||||
year: result.year ?? result.published?.prop?.from?.year ?? '',
|
|
||||||
dataSource: this.apiName,
|
|
||||||
url: result.url,
|
|
||||||
id: result.mal_id,
|
|
||||||
|
|
||||||
genres: result.genres?.map((x: any) => x.name) ?? [],
|
|
||||||
authors: result.authors?.map((x: any) => x.name) ?? [],
|
|
||||||
chapters: result.chapters,
|
|
||||||
volumes: result.volumes,
|
|
||||||
onlineRating: result.score ?? 0,
|
|
||||||
image: result.images?.jpg?.image_url ?? '',
|
|
||||||
|
|
||||||
released: true,
|
|
||||||
publishedFrom: new Date(result.published?.from).toLocaleDateString() ?? 'unknown',
|
|
||||||
publishedTo: new Date(result.published?.to).toLocaleDateString() ?? 'unknown',
|
|
||||||
status: result.status,
|
|
||||||
|
|
||||||
userData: {
|
|
||||||
watched: false,
|
|
||||||
lastWatched: '',
|
|
||||||
personalRating: 0,
|
|
||||||
},
|
|
||||||
} as MangaModel);
|
|
||||||
|
|
||||||
return model;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue