mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-10-25 11:53:45 +02:00
Merge pull request #1544 from ImranR98/dev
- Don't trust content-length header from sites w/o accept-ranges support (#1542) + bugfixes - Allow for spaces in HTML link and version filters (#1537)
This commit is contained in:
@@ -244,16 +244,17 @@ class HTML extends AppSource {
|
|||||||
true) {
|
true) {
|
||||||
var reg = RegExp(additionalSettings['customLinkFilterRegex']);
|
var reg = RegExp(additionalSettings['customLinkFilterRegex']);
|
||||||
links = allLinks
|
links = allLinks
|
||||||
.where((element) =>
|
.where((element) => reg.hasMatch(
|
||||||
reg.hasMatch(filterLinkByText ? element.value : element.key))
|
filterLinkByText ? element.value : Uri.decodeFull(element.key)))
|
||||||
.toList();
|
.toList();
|
||||||
} else {
|
} else {
|
||||||
links = allLinks
|
links = allLinks
|
||||||
.where((element) =>
|
.where((element) => Uri.parse(filterLinkByText
|
||||||
Uri.parse(filterLinkByText ? element.value : element.key)
|
? element.value
|
||||||
.path
|
: Uri.decodeFull(element.key))
|
||||||
.toLowerCase()
|
.path
|
||||||
.endsWith('.apk'))
|
.toLowerCase()
|
||||||
|
.endsWith('.apk'))
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
if (!skipSort) {
|
if (!skipSort) {
|
||||||
@@ -315,7 +316,7 @@ class HTML extends AppSource {
|
|||||||
additionalSettings['matchGroupToUse'] as String?,
|
additionalSettings['matchGroupToUse'] as String?,
|
||||||
additionalSettings['versionExtractWholePage'] == true
|
additionalSettings['versionExtractWholePage'] == true
|
||||||
? versionExtractionWholePageString
|
? versionExtractionWholePageString
|
||||||
: rel);
|
: Uri.decodeFull(rel));
|
||||||
version ??=
|
version ??=
|
||||||
additionalSettings['defaultPseudoVersioningMethod'] == 'APKLinkHash'
|
additionalSettings['defaultPseudoVersioningMethod'] == 'APKLinkHash'
|
||||||
? rel.hashCode.toString()
|
? rel.hashCode.toString()
|
||||||
|
|||||||
@@ -235,8 +235,9 @@ Future<File> downloadFile(
|
|||||||
var fullContentLength = response.contentLength;
|
var fullContentLength = response.contentLength;
|
||||||
if (useExisting && downloadedFile.existsSync()) {
|
if (useExisting && downloadedFile.existsSync()) {
|
||||||
var length = downloadedFile.lengthSync();
|
var length = downloadedFile.lengthSync();
|
||||||
if (fullContentLength == null) {
|
if (fullContentLength == null || !rangeFeatureEnabled) {
|
||||||
// Assume full
|
// If there is no content length reported, assume it the existing file is fully downloaded
|
||||||
|
// Also if the range feature is not supported, don't trust the content length if any (#1542)
|
||||||
client.close();
|
client.close();
|
||||||
return downloadedFile;
|
return downloadedFile;
|
||||||
} else {
|
} else {
|
||||||
@@ -291,14 +292,11 @@ Future<File> downloadFile(
|
|||||||
return s;
|
return s;
|
||||||
}).pipe(sink);
|
}).pipe(sink);
|
||||||
await sink.close();
|
await sink.close();
|
||||||
bool likelyCorruptFile = (progress ?? 0) > 101;
|
|
||||||
progress = null;
|
progress = null;
|
||||||
if (onProgress != null) {
|
if (onProgress != null) {
|
||||||
onProgress(progress);
|
onProgress(progress);
|
||||||
}
|
}
|
||||||
if (response.statusCode < 200 ||
|
if (response.statusCode < 200 || response.statusCode > 299) {
|
||||||
response.statusCode > 299 ||
|
|
||||||
likelyCorruptFile) {
|
|
||||||
tempDownloadedFile.deleteSync(recursive: true);
|
tempDownloadedFile.deleteSync(recursive: true);
|
||||||
throw response.reasonPhrase ?? tr('unexpectedError');
|
throw response.reasonPhrase ?? tr('unexpectedError');
|
||||||
}
|
}
|
||||||
@@ -392,30 +390,26 @@ class AppsProvider with ChangeNotifier {
|
|||||||
}();
|
}();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<File> handleAPKIDChange(App app, PackageInfo? newInfo,
|
Future<File> handleAPKIDChange(App app, PackageInfo newInfo,
|
||||||
File downloadedFile, String downloadUrl) async {
|
File downloadedFile, String downloadUrl) async {
|
||||||
// If the APK package ID is different from the App ID, it is either new (using a placeholder ID) or the ID has changed
|
// If the APK package ID is different from the App ID, it is either new (using a placeholder ID) or the ID has changed
|
||||||
// The former case should be handled (give the App its real ID), the latter is a security issue
|
// The former case should be handled (give the App its real ID), the latter is a security issue
|
||||||
var isTempIdBool = isTempId(app);
|
var isTempIdBool = isTempId(app);
|
||||||
if (newInfo != null) {
|
if (app.id != newInfo.packageName) {
|
||||||
if (app.id != newInfo.packageName) {
|
if (apps[app.id] != null && !isTempIdBool && !app.allowIdChange) {
|
||||||
if (apps[app.id] != null && !isTempIdBool && !app.allowIdChange) {
|
throw IDChangedError(newInfo.packageName!);
|
||||||
throw IDChangedError(newInfo.packageName!);
|
}
|
||||||
}
|
var idChangeWasAllowed = app.allowIdChange;
|
||||||
var idChangeWasAllowed = app.allowIdChange;
|
app.allowIdChange = false;
|
||||||
app.allowIdChange = false;
|
var originalAppId = app.id;
|
||||||
var originalAppId = app.id;
|
app.id = newInfo.packageName!;
|
||||||
app.id = newInfo.packageName!;
|
downloadedFile = downloadedFile.renameSync(
|
||||||
downloadedFile = downloadedFile.renameSync(
|
'${downloadedFile.parent.path}/${app.id}-${downloadUrl.hashCode}.${downloadedFile.path.split('.').last}');
|
||||||
'${downloadedFile.parent.path}/${app.id}-${downloadUrl.hashCode}.${downloadedFile.path.split('.').last}');
|
if (apps[originalAppId] != null) {
|
||||||
if (apps[originalAppId] != null) {
|
await removeApps([originalAppId]);
|
||||||
await removeApps([originalAppId]);
|
await saveApps([app],
|
||||||
await saveApps([app],
|
onlyIfExists: !isTempIdBool && !idChangeWasAllowed);
|
||||||
onlyIfExists: !isTempIdBool && !idChangeWasAllowed);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (isTempIdBool) {
|
|
||||||
throw ObtainiumError('Could not get ID from APK');
|
|
||||||
}
|
}
|
||||||
return downloadedFile;
|
return downloadedFile;
|
||||||
}
|
}
|
||||||
@@ -479,6 +473,10 @@ class AppsProvider with ChangeNotifier {
|
|||||||
newInfo =
|
newInfo =
|
||||||
await pm.getPackageArchiveInfo(archiveFilePath: apks.first.path);
|
await pm.getPackageArchiveInfo(archiveFilePath: apks.first.path);
|
||||||
}
|
}
|
||||||
|
if (newInfo == null) {
|
||||||
|
downloadedFile.delete();
|
||||||
|
throw ObtainiumError('Could not get ID from APK');
|
||||||
|
}
|
||||||
downloadedFile =
|
downloadedFile =
|
||||||
await handleAPKIDChange(app, newInfo, downloadedFile, downloadUrl);
|
await handleAPKIDChange(app, newInfo, downloadedFile, downloadUrl);
|
||||||
// Delete older versions of the file if any
|
// Delete older versions of the file if any
|
||||||
|
|||||||
20
pubspec.lock
20
pubspec.lock
@@ -275,10 +275,10 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: flutter_archive
|
name: flutter_archive
|
||||||
sha256: "004132780d382df5171589ab793e2efc9c3eef570fe72d78b4ccfbfbe52762ae"
|
sha256: "5ca235f304c12bf468979235f400f79846d204169d715939e39197106f5fc970"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "6.0.0"
|
version: "6.0.3"
|
||||||
flutter_fgbg:
|
flutter_fgbg:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@@ -336,10 +336,10 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: flutter_markdown
|
name: flutter_markdown
|
||||||
sha256: "31c12de79262b5431c5492e9c89948aa789158435f707d3519a7fdef6af28af7"
|
sha256: "04c4722cc36ec5af38acc38ece70d22d3c2123c61305d555750a091517bbe504"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.6.22+1"
|
version: "0.6.23"
|
||||||
flutter_plugin_android_lifecycle:
|
flutter_plugin_android_lifecycle:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -362,10 +362,10 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: fluttertoast
|
name: fluttertoast
|
||||||
sha256: dfdde255317af381bfc1c486ed968d5a43a2ded9c931e87cbecd88767d6a71c1
|
sha256: "81b68579e23fcbcada2db3d50302813d2371664afe6165bc78148050ab94bf66"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "8.2.4"
|
version: "8.2.5"
|
||||||
gtk:
|
gtk:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -903,10 +903,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: url_launcher_web
|
name: url_launcher_web
|
||||||
sha256: "3692a459204a33e04bc94f5fb91158faf4f2c8903281ddd82915adecdb1a901d"
|
sha256: "8d9e750d8c9338601e709cd0885f95825086bd8b642547f26bda435aade95d8a"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.3.0"
|
version: "2.3.1"
|
||||||
url_launcher_windows:
|
url_launcher_windows:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -991,10 +991,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: win32_registry
|
name: win32_registry
|
||||||
sha256: "41fd8a189940d8696b1b810efb9abcf60827b6cbfab90b0c43e8439e3a39d85a"
|
sha256: "10589e0d7f4e053f2c61023a31c9ce01146656a70b7b7f0828c0b46d7da2a9bb"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.2"
|
version: "1.1.3"
|
||||||
xdg_directories:
|
xdg_directories:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
|||||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||||
# In Windows, build-name is used as the major, minor, and patch parts
|
# In Windows, build-name is used as the major, minor, and patch parts
|
||||||
# of the product and file versions while build-number is used as the build suffix.
|
# of the product and file versions while build-number is used as the build suffix.
|
||||||
version: 1.1.3+2260
|
version: 1.1.4+2261
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=3.0.0 <4.0.0'
|
sdk: '>=3.0.0 <4.0.0'
|
||||||
|
|||||||
Reference in New Issue
Block a user