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'] ?? ""; dateFormatLocale = json['dateFormatLocale'] ?? "";
hasCloudflare = json['hasCloudflare'] ?? false; hasCloudflare = json['hasCloudflare'] ?? false;
iconUrl = json['iconUrl'] ?? ""; iconUrl = json['iconUrl'] ?? "";
id = (json['id'] ?? sourceCodeLang == 0 id = (json['id'] ??
(sourceCodeLang == 0
? 'mangayomi-"${json['lang'] ?? ""}"."${json['name'] ?? ""}"' ? 'mangayomi-"${json['lang'] ?? ""}"."${json['name'] ?? ""}"'
: 'mangayomi-js-"${json['lang'] ?? ""}"."${json['name'] ?? ""}"') : 'mangayomi-js-"${json['lang'] ?? ""}"."${json['name'] ?? ""}"'))
.hashCode; .hashCode;
isFullData = json['isFullData'] ?? false; isFullData = json['isFullData'] ?? false;
isManga = json['isManga'] ?? false; isManga = json['isManga'] ?? false;

View File

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