fix generate multiple langage for JS source

This commit is contained in:
kodjomoustapha
2024-11-05 10:00:02 +01:00
parent d11ce30c95
commit 18f59fdb9e
2 changed files with 21 additions and 13 deletions

View File

@@ -63,9 +63,10 @@ class Source {
dateFormatLocale = json['dateFormatLocale'] ?? "";
hasCloudflare = json['hasCloudflare'] ?? false;
iconUrl = json['iconUrl'] ?? "";
id = (json['id'] ?? sourceCodeLang == 0
? 'mangayomi-"${json['lang'] ?? ""}"."${json['name'] ?? ""}"'
: 'mangayomi-js-"${json['lang'] ?? ""}"."${json['name'] ?? ""}"')
id = (json['id'] ??
(sourceCodeLang == 0
? 'mangayomi-"${json['lang'] ?? ""}"."${json['name'] ?? ""}"'
: 'mangayomi-js-"${json['lang'] ?? ""}"."${json['name'] ?? ""}"'))
.hashCode;
isFullData = json['isFullData'] ?? false;
isManga = json['isManga'] ?? false;

View File

@@ -49,19 +49,26 @@ List<Source> _searchJsSources(Directory dir) {
if (entity is Directory) {
sourceList.addAll(_searchJsSources(entity));
} else if (entity is File && entity.path.endsWith('.js')) {
final RegExp regex = RegExp(
r'const\s+mangayomiSources\s*=\s*(\[.*?\]);',
final regex = RegExp(r'const\s+mangayomiSources\s*=\s*(\[.*?\]);',
dotAll: true);
final defaultSource = Source();
Match? match = regex.firstMatch(entity.readAsStringSync());
final match = regex.firstMatch(entity.readAsStringSync());
if (match != null) {
sourceList.addAll((jsonDecode(match.group(1)!) as List)
.map((e) => Source.fromJson(e)
..sourceCodeLanguage = 1
..appMinVerReq = defaultSource.appMinVerReq
..sourceCodeUrl =
"https://raw.githubusercontent.com/kodjodevf/mangayomi-extensions/$branchName/javascript/${e["pkgPath"] ?? e["pkgName"]}")
.toList());
for (var sourceJson in jsonDecode(match.group(1)!) as List) {
final langs = sourceJson["langs"] as List?;
final source = Source.fromJson(sourceJson)
..sourceCodeLanguage = 1
..appMinVerReq = defaultSource.appMinVerReq
..sourceCodeUrl =
"https://raw.githubusercontent.com/kodjodevf/mangayomi-extensions/$branchName/javascript/${sourceJson["pkgPath"] ?? sourceJson["pkgName"]}";
if (langs?.isNotEmpty ?? false) {
for (var lang in langs!) {
sourceList.add(Source.fromJson(source.toJson())..lang = lang);
}
} else {
sourceList.add(source);
}
}
}
}
}