mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-08-19 05:00:21 +02:00
Merge branch 'ImranR98:main' into rustore
This commit is contained in:
@@ -501,7 +501,7 @@ class GitHub extends AppSource {
|
||||
AppNames getAppNames(String standardUrl) {
|
||||
String temp = standardUrl.substring(standardUrl.indexOf('://') + 3);
|
||||
List<String> names = temp.substring(temp.indexOf('/') + 1).split('/');
|
||||
return AppNames(names[0], names[1]);
|
||||
return AppNames(names[0], names.sublist(1).join('/'));
|
||||
}
|
||||
|
||||
Future<Map<String, List<String>>> searchCommon(
|
||||
|
@@ -54,7 +54,7 @@ class GitLab extends AppSource {
|
||||
@override
|
||||
String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) {
|
||||
RegExp standardUrlRegEx = RegExp(
|
||||
'^https?://(www\\.)?${getSourceRegex(hosts)}/[^/]+/[^/]+',
|
||||
'^https?://(www\\.)?${getSourceRegex(hosts)}/[^/]+(/[^/]+){1,20}',
|
||||
caseSensitive: false);
|
||||
RegExpMatch? match = standardUrlRegEx.firstMatch(url);
|
||||
if (match == null) {
|
||||
@@ -126,6 +126,8 @@ class GitLab extends AppSource {
|
||||
) async {
|
||||
// Prepare request params
|
||||
var names = GitHub().getAppNames(standardUrl);
|
||||
String projectUriComponent =
|
||||
'${Uri.encodeComponent(names.author)}%2F${Uri.encodeComponent(names.name)}';
|
||||
String? PAT = await getPATIfAny(hostChanged ? additionalSettings : {});
|
||||
String optionalAuth = (PAT != null) ? 'private_token=$PAT' : '';
|
||||
|
||||
@@ -133,7 +135,7 @@ class GitLab extends AppSource {
|
||||
|
||||
// Get project ID
|
||||
Response res0 = await sourceRequest(
|
||||
'https://${hosts[0]}/api/v4/projects/${names.author}%2F${names.name}?$optionalAuth',
|
||||
'https://${hosts[0]}/api/v4/projects/$projectUriComponent?$optionalAuth',
|
||||
additionalSettings);
|
||||
if (res0.statusCode != 200) {
|
||||
throw getObtainiumHttpError(res0);
|
||||
@@ -145,7 +147,7 @@ class GitLab extends AppSource {
|
||||
|
||||
// Request data from REST API
|
||||
Response res = await sourceRequest(
|
||||
'https://${hosts[0]}/api/v4/projects/${names.author}%2F${names.name}/${trackOnly ? 'repository/tags' : 'releases'}?$optionalAuth',
|
||||
'https://${hosts[0]}/api/v4/projects/$projectUriComponent/${trackOnly ? 'repository/tags' : 'releases'}?$optionalAuth',
|
||||
additionalSettings);
|
||||
if (res.statusCode != 200) {
|
||||
throw getObtainiumHttpError(res);
|
||||
@@ -180,7 +182,7 @@ class GitLab extends AppSource {
|
||||
return APKDetails(
|
||||
e['tag_name'] ?? e['name'],
|
||||
getApkUrlsFromUrls(apkUrlsSet.toList()),
|
||||
GitHub().getAppNames(standardUrl),
|
||||
AppNames(names.author, names.name.split('/').last),
|
||||
releaseDate: releaseDate);
|
||||
});
|
||||
if (apkDetailsList.isEmpty) {
|
||||
|
@@ -44,7 +44,8 @@ List<MapEntry<Locale, String>> supportedLocales = const [
|
||||
MapEntry(Locale('da'), 'Dansk'),
|
||||
MapEntry(Locale('en', 'EO'),
|
||||
'Esperanto'), // https://github.com/aissat/easy_localization/issues/220#issuecomment-846035493
|
||||
MapEntry(Locale('in'), 'Bahasa Indonesia')
|
||||
MapEntry(Locale('in'), 'Bahasa Indonesia'),
|
||||
MapEntry(Locale('ko'), '한국어'),
|
||||
];
|
||||
const fallbackLocale = Locale('en');
|
||||
const localeDir = 'assets/translations';
|
||||
@@ -244,6 +245,7 @@ class _ObtainiumState extends State<Obtainium> {
|
||||
supportedLocales: context.supportedLocales,
|
||||
locale: context.locale,
|
||||
navigatorKey: globalNavigatorKey,
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: ThemeData(
|
||||
useMaterial3: true,
|
||||
colorScheme: settingsProvider.theme == ThemeSettings.dark
|
||||
|
@@ -151,13 +151,15 @@ Future<File> downloadFileWithRetry(String url, String fileName,
|
||||
{bool useExisting = true,
|
||||
Map<String, String>? headers,
|
||||
int retries = 3,
|
||||
bool allowInsecure = false}) async {
|
||||
bool allowInsecure = false,
|
||||
LogsProvider? logs}) async {
|
||||
try {
|
||||
return await downloadFile(
|
||||
url, fileName, fileNameHasExt, onProgress, destDir,
|
||||
useExisting: useExisting,
|
||||
headers: headers,
|
||||
allowInsecure: allowInsecure);
|
||||
allowInsecure: allowInsecure,
|
||||
logs: logs);
|
||||
} catch (e) {
|
||||
if (retries > 0 && e is ClientException) {
|
||||
await Future.delayed(const Duration(seconds: 5));
|
||||
@@ -166,7 +168,8 @@ Future<File> downloadFileWithRetry(String url, String fileName,
|
||||
useExisting: useExisting,
|
||||
headers: headers,
|
||||
retries: (retries - 1),
|
||||
allowInsecure: allowInsecure);
|
||||
allowInsecure: allowInsecure,
|
||||
logs: logs);
|
||||
} else {
|
||||
rethrow;
|
||||
}
|
||||
@@ -219,7 +222,8 @@ Future<File> downloadFile(String url, String fileName, bool fileNameHasExt,
|
||||
Function? onProgress, String destDir,
|
||||
{bool useExisting = true,
|
||||
Map<String, String>? headers,
|
||||
bool allowInsecure = false}) async {
|
||||
bool allowInsecure = false,
|
||||
LogsProvider? logs}) async {
|
||||
// Send the initial request but cancel it as soon as you have the headers
|
||||
var reqHeaders = headers ?? {};
|
||||
var req = Request('GET', Uri.parse(url));
|
||||
@@ -280,6 +284,42 @@ Future<File> downloadFile(String url, String fileName, bool fileNameHasExt,
|
||||
// Download to a '.temp' file (to distinguish btn. complete/incomplete files)
|
||||
File tempDownloadedFile = File('${downloadedFile.path}.part');
|
||||
|
||||
// If there is already a temp file, a download may already be in progress - account for this (see #2073)
|
||||
bool tempFileExists = tempDownloadedFile.existsSync();
|
||||
if (tempFileExists && useExisting) {
|
||||
logs?.add(
|
||||
'Partial download exists - will wait: ${tempDownloadedFile.uri.pathSegments.last}');
|
||||
bool isDownloading = true;
|
||||
int currentTempFileSize = await tempDownloadedFile.length();
|
||||
bool shouldReturn = false;
|
||||
while (isDownloading) {
|
||||
await Future.delayed(Duration(seconds: 7));
|
||||
if (tempDownloadedFile.existsSync()) {
|
||||
int newTempFileSize = await tempDownloadedFile.length();
|
||||
if (newTempFileSize > currentTempFileSize) {
|
||||
currentTempFileSize = newTempFileSize;
|
||||
logs?.add(
|
||||
'Existing partial download still in progress: ${tempDownloadedFile.uri.pathSegments.last}');
|
||||
} else {
|
||||
logs?.add(
|
||||
'Ignoring existing partial download: ${tempDownloadedFile.uri.pathSegments.last}');
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
shouldReturn = downloadedFile.existsSync();
|
||||
}
|
||||
}
|
||||
if (shouldReturn) {
|
||||
logs?.add(
|
||||
'Existing partial download completed - not repeating: ${tempDownloadedFile.uri.pathSegments.last}');
|
||||
client.close();
|
||||
return downloadedFile;
|
||||
} else {
|
||||
logs?.add(
|
||||
'Existing partial download not in progress: ${tempDownloadedFile.uri.pathSegments.last}');
|
||||
}
|
||||
}
|
||||
|
||||
// If the range feature is not available (or you need to start a ranged req from 0),
|
||||
// complete the already-started request, else cancel it and start a ranged request,
|
||||
// and open the file for writing in the appropriate mode
|
||||
@@ -419,9 +459,7 @@ class AppsProvider with ChangeNotifier {
|
||||
// Delete any partial APKs (if safe to do so)
|
||||
var cutoff = DateTime.now().subtract(const Duration(days: 7));
|
||||
APKDir.listSync()
|
||||
.where((element) =>
|
||||
element.path.endsWith('.part') ||
|
||||
element.statSync().modified.isBefore(cutoff))
|
||||
.where((element) => element.statSync().modified.isBefore(cutoff))
|
||||
.forEach((partialApk) {
|
||||
if (!areDownloadsRunning()) {
|
||||
partialApk.delete(recursive: true);
|
||||
@@ -495,7 +533,8 @@ class AppsProvider with ChangeNotifier {
|
||||
prevProg = prog;
|
||||
}, APKDir.path,
|
||||
useExisting: useExisting,
|
||||
allowInsecure: app.additionalSettings['allowInsecure'] == true);
|
||||
allowInsecure: app.additionalSettings['allowInsecure'] == true,
|
||||
logs: logs);
|
||||
// Set to 90 for remaining steps, will make null in 'finally'
|
||||
if (apps[app.id] != null) {
|
||||
apps[app.id]!.downloadProgress = -1;
|
||||
@@ -1124,7 +1163,8 @@ class AppsProvider with ChangeNotifier {
|
||||
forAPKDownload:
|
||||
fileUrl.key.endsWith('.apk') ? true : false),
|
||||
useExisting: false,
|
||||
allowInsecure: app.additionalSettings['allowInsecure'] == true);
|
||||
allowInsecure: app.additionalSettings['allowInsecure'] == true,
|
||||
logs: logs);
|
||||
notificationsProvider
|
||||
.notify(DownloadedNotification(fileUrl.key, fileUrl.value));
|
||||
} catch (e) {
|
||||
@@ -1414,8 +1454,10 @@ class AppsProvider with ChangeNotifier {
|
||||
app = getCorrectedInstallStatusAppIfPossible(app, info) ?? app;
|
||||
}
|
||||
if (!onlyIfExists || this.apps.containsKey(app.id)) {
|
||||
File('${(await getAppsDir()).path}/${app.id}.json')
|
||||
.writeAsStringSync(jsonEncode(app.toJson()));
|
||||
String filePath = '${(await getAppsDir()).path}/${app.id}.json';
|
||||
File('$filePath.tmp')
|
||||
.writeAsStringSync(jsonEncode(app.toJson())); // #2089
|
||||
File('$filePath.tmp').renameSync(filePath);
|
||||
}
|
||||
try {
|
||||
this.apps.update(app.id,
|
||||
|
Reference in New Issue
Block a user