APKPure, SourceHut, Bugfixes

This commit is contained in:
Imran Remtulla
2023-05-05 22:35:32 -04:00
parent 84b512f282
commit fb9e66332d
23 changed files with 445 additions and 122 deletions

View File

@@ -125,10 +125,13 @@ class AppsProvider with ChangeNotifier {
}
downloadFile(String url, String fileName, Function? onProgress,
{bool useExisting = true}) async {
{bool useExisting = true, Map<String, String>? headers}) async {
var destDir = (await getExternalCacheDirectories())!.first.path;
StreamedResponse response =
await Client().send(Request('GET', Uri.parse(url)));
var req = Request('GET', Uri.parse(url));
if (headers != null) {
req.headers.addAll(headers);
}
StreamedResponse response = await Client().send(req);
File downloadedFile = File('$destDir/$fileName');
if (!(downloadedFile.existsSync() && useExisting)) {
File tempDownloadedFile = File('${downloadedFile.path}.part');
@@ -170,15 +173,16 @@ class AppsProvider with ChangeNotifier {
notifyListeners();
}
try {
String downloadUrl = await SourceProvider()
.getSource(app.url, overrideSource: app.overrideSource)
.apkUrlPrefetchModifier(app.apkUrls[app.preferredApkIndex].value);
AppSource source = SourceProvider()
.getSource(app.url, overrideSource: app.overrideSource);
String downloadUrl = await source.apkUrlPrefetchModifier(
app.apkUrls[app.preferredApkIndex].value, app.url);
var fileName = '${app.id}-${downloadUrl.hashCode}.apk';
var notif = DownloadNotification(app.finalName, 100);
notificationsProvider?.cancel(notif.id);
int? prevProg;
File downloadedFile =
await downloadFile(downloadUrl, fileName, (double? progress) {
File downloadedFile = await downloadFile(downloadUrl, fileName,
headers: source.requestHeaders, (double? progress) {
int? prog = progress?.ceil();
if (apps[app.id] != null) {
apps[app.id]!.downloadProgress = progress;

View File

@@ -7,7 +7,9 @@ import 'package:device_info_plus/device_info_plus.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:html/dom.dart';
import 'package:http/http.dart';
import 'package:obtainium/app_sources/apkcombo.dart';
import 'package:obtainium/app_sources/apkmirror.dart';
import 'package:obtainium/app_sources/apkpure.dart';
import 'package:obtainium/app_sources/codeberg.dart';
import 'package:obtainium/app_sources/fdroid.dart';
import 'package:obtainium/app_sources/fdroidrepo.dart';
@@ -20,6 +22,7 @@ import 'package:obtainium/app_sources/mullvad.dart';
import 'package:obtainium/app_sources/neutroncode.dart';
import 'package:obtainium/app_sources/signal.dart';
import 'package:obtainium/app_sources/sourceforge.dart';
import 'package:obtainium/app_sources/sourcehut.dart';
import 'package:obtainium/app_sources/steammobile.dart';
import 'package:obtainium/app_sources/telegramapp.dart';
import 'package:obtainium/app_sources/vlc.dart';
@@ -315,6 +318,7 @@ abstract class AppSource {
late String name;
bool enforceTrackOnly = false;
bool changeLogIfAnyIsMarkDown = true;
bool overrideEligible = false;
AppSource() {
name = runtimeType.toString();
@@ -344,6 +348,18 @@ abstract class AppSource {
return url;
}
Map<String, String>? get requestHeaders => null;
Future<Response> sourceRequest(String url) async {
if (requestHeaders != null) {
var req = Request('GET', Uri.parse(url));
req.headers.addAll(requestHeaders!);
return Response.fromStream(await Client().send(req));
} else {
return get(Uri.parse(url));
}
}
String sourceSpecificStandardizeURL(String url) {
throw NotImplementedError();
}
@@ -410,7 +426,8 @@ abstract class AppSource {
return null;
}
Future<String> apkUrlPrefetchModifier(String apkUrl) async {
Future<String> apkUrlPrefetchModifier(
String apkUrl, String standardUrl) async {
return apkUrl;
}
@@ -459,7 +476,10 @@ class SourceProvider {
FDroidRepo(),
Jenkins(),
SourceForge(),
SourceHut(),
APKMirror(),
APKPure(),
// APKCombo(), // Can't get past their scraping blocking yet (get 403 Forbidden)
Mullvad(),
Signal(),
VLC(),