Fixed relative link handling in HTML source

This commit is contained in:
Imran Remtulla
2023-04-12 15:17:08 -04:00
parent 6275cbf114
commit 0704dfe2ee

View File

@@ -34,16 +34,20 @@ class HTML extends AppSource {
var rel = links.last;
var apkName = rel.split('/').last;
var version = apkName.substring(0, apkName.length - 4);
List<String> apkUrls = [rel]
.map((e) => e.toLowerCase().startsWith('http://') ||
e.toLowerCase().startsWith('https://')
? e
: e.startsWith('/')
? '${uri.origin}/$e'
: uri.path.endsWith('.html') || uri.path.endsWith('.php')
? '${uri.origin}/${uri.path.split('/').sublist(0, uri.path.split('/').length - 1).join('/')}/$e'
: '${uri.origin}/${uri.path}/$e')
.toList();
List<String> apkUrls = [rel].map((e) {
try {
Uri.parse(e).origin;
return e;
} catch (err) {
// is relative
}
var currPathSegments = uri.path.split('/');
if (e.startsWith('/') || currPathSegments.isEmpty) {
return '${uri.origin}/$e';
} else {
return '${uri.origin}/${currPathSegments.sublist(0, currPathSegments.length - 1).join('/')}/$e';
}
}).toList();
return APKDetails(
version, getApkUrlsFromUrls(apkUrls), AppNames(uri.host, tr('app')));
} else {