Fix map index error

This commit is contained in:
kodjomoustapha
2023-11-17 20:09:05 +01:00
parent 74d66f84a8
commit 50a6c84d47
3 changed files with 27 additions and 19 deletions

File diff suppressed because one or more lines are too long

View File

@@ -127,22 +127,25 @@ class MangaDex extends MProvider {
final res = await http('GET', json.encode({"url": urll})); final res = await http('GET', json.encode({"url": urll}));
final dataRes = json.decode(res); // final dataRes = json.decode(res);
final host = dataRes["baseUrl"]; final host = getMapValue(res, "baseUrl");
final hash = dataRes["chapter"]["hash"]; final chapter = getMapValue(res, "chapter", encode: true);
final chapterDatas = dataRes["chapter"]["data"] as List; final hash = getMapValue(chapter, "hash");
final chapterDatas =
json.decode(getMapValue(chapter, "data", encode: true)) as List;
return chapterDatas.map((e) => "$host/data/$hash/$e").toList(); return chapterDatas.map((e) => "$host/data/$hash/$e").toList();
} }
MPages mangaRes(String res, MSource source) { MPages mangaRes(String res, MSource source) {
final datasRes = json.decode(res); final datasRes = getMapValue(res, "data", encode: true);
final resJson = datasRes["data"] as List;
final resJson = json.decode(datasRes) as List;
List<MManga> mangaList = []; List<MManga> mangaList = [];
for (var e in resJson) { for (var e in resJson) {
MManga manga = MManga(); MManga manga = MManga();
manga.name = findTitle(e, source.lang); manga.name = findTitle(json.encode(e), source.lang);
manga.imageUrl = getCover(e); manga.imageUrl = getCover(json.encode(e));
manga.link = "/manga/${e["id"]}"; manga.link = "/manga/${getMapValue(json.encode(e), "id")}";
mangaList.add(manga); mangaList.add(manga);
} }
return MPages(mangaList, true); return MPages(mangaList, true);
@@ -229,10 +232,12 @@ class MangaDex extends MProvider {
return ctnRating; return ctnRating;
} }
String findTitle(Map<String, dynamic> dataRes, String lang) { String findTitle(String dataRes, String lang) {
final altTitlesJ = dataRes["attributes"]["altTitles"]; final attributes = getMapValue(dataRes, "attributes", encode: true);
final titleJ = dataRes["attributes"]["title"]; final altTitlesJ =
final title = getMapValue(json.encode(titleJ), "en"); json.decode(getMapValue(attributes, "altTitles", encode: true));
final titleJ = getMapValue(attributes, "title", encode: true);
final title = getMapValue(titleJ, "en");
if (title.isEmpty) { if (title.isEmpty) {
for (var r in altTitlesJ) { for (var r in altTitlesJ) {
final altTitle = getMapValue(json.encode(r), "en"); final altTitle = getMapValue(json.encode(r), "en");
@@ -244,15 +249,18 @@ class MangaDex extends MProvider {
return title; return title;
} }
String getCover(Map<String, dynamic> dataRes) { String getCover(String dataRes) {
final relationships = dataRes["relationships"]; final relationships = json
.decode(getMapValue(dataRes, "relationships", encode: true)) as List;
String coverFileName = "".toString(); String coverFileName = "".toString();
for (var a in relationships) { for (var a in relationships) {
final relationType = a["type"]; final relationType = getMapValue(json.encode(a), "type");
if (relationType == "cover_art") { if (relationType == "cover_art") {
if (coverFileName.isEmpty) { if (coverFileName.isEmpty) {
final attributes =
getMapValue(json.encode(a), "attributes", encode: true);
coverFileName = coverFileName =
"https://uploads.mangadex.org/covers/${dataRes["id"]}/${a["attributes"]["fileName"]}"; "https://uploads.mangadex.org/covers/${getMapValue(dataRes, "id")}/${getMapValue(attributes, "fileName")}";
} }
} }
} }

View File

@@ -4,7 +4,7 @@ import '../../../../utils/utils.dart';
const apiUrl = 'https://api.mangadex.org'; const apiUrl = 'https://api.mangadex.org';
const baseUrl = 'https://mangadex.org'; const baseUrl = 'https://mangadex.org';
const isNsfw = true; const isNsfw = true;
const mangadexVersion = "0.0.35"; const mangadexVersion = "0.0.4";
const mangadexSourceCodeUrl = const mangadexSourceCodeUrl =
"https://raw.githubusercontent.com/kodjodevf/mangayomi-extensions/main/manga/src/all/mangadex/mangadex-v$mangadexVersion.dart"; "https://raw.githubusercontent.com/kodjodevf/mangayomi-extensions/main/manga/src/all/mangadex/mangadex-v$mangadexVersion.dart";
String _iconUrl = getIconUrl("mangadex", "all"); String _iconUrl = getIconUrl("mangadex", "all");