mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-07-22 09:09:41 +02:00
Lint all files
This commit is contained in:
@@ -18,36 +18,41 @@ class GitLab extends AppSource {
|
||||
showReleaseDateAsVersionToggle = true;
|
||||
|
||||
sourceConfigSettingFormItems = [
|
||||
GeneratedFormTextField('gitlab-creds',
|
||||
label: tr('gitlabPATLabel'),
|
||||
password: true,
|
||||
required: false,
|
||||
belowWidgets: [
|
||||
const SizedBox(
|
||||
height: 4,
|
||||
GeneratedFormTextField(
|
||||
'gitlab-creds',
|
||||
label: tr('gitlabPATLabel'),
|
||||
password: true,
|
||||
required: false,
|
||||
belowWidgets: [
|
||||
const SizedBox(height: 4),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
launchUrlString(
|
||||
'https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html#create-a-personal-access-token',
|
||||
mode: LaunchMode.externalApplication,
|
||||
);
|
||||
},
|
||||
child: Text(
|
||||
tr('about'),
|
||||
style: const TextStyle(
|
||||
decoration: TextDecoration.underline,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
launchUrlString(
|
||||
'https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html#create-a-personal-access-token',
|
||||
mode: LaunchMode.externalApplication);
|
||||
},
|
||||
child: Text(
|
||||
tr('about'),
|
||||
style: const TextStyle(
|
||||
decoration: TextDecoration.underline, fontSize: 12),
|
||||
)),
|
||||
const SizedBox(
|
||||
height: 4,
|
||||
)
|
||||
])
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
],
|
||||
),
|
||||
];
|
||||
|
||||
additionalSourceAppSpecificSettingFormItems = [
|
||||
[
|
||||
GeneratedFormSwitch('fallbackToOlderReleases',
|
||||
label: tr('fallbackToOlderReleases'), defaultValue: true)
|
||||
]
|
||||
GeneratedFormSwitch(
|
||||
'fallbackToOlderReleases',
|
||||
label: tr('fallbackToOlderReleases'),
|
||||
defaultValue: true,
|
||||
),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -55,11 +60,13 @@ class GitLab extends AppSource {
|
||||
String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) {
|
||||
var urlSegments = url.split('/');
|
||||
var cutOffIndex = urlSegments.indexWhere((s) => s == '-');
|
||||
url =
|
||||
urlSegments.sublist(0, cutOffIndex <= 0 ? null : cutOffIndex).join('/');
|
||||
url = urlSegments
|
||||
.sublist(0, cutOffIndex <= 0 ? null : cutOffIndex)
|
||||
.join('/');
|
||||
RegExp standardUrlRegEx = RegExp(
|
||||
'^https?://(www\\.)?${getSourceRegex(hosts)}/[^/]+(/[^((\b/\b)|(\b/-/\b))]+){1,20}',
|
||||
caseSensitive: false);
|
||||
'^https?://(www\\.)?${getSourceRegex(hosts)}/[^/]+(/[^((\b/\b)|(\b/-/\b))]+){1,20}',
|
||||
caseSensitive: false,
|
||||
);
|
||||
RegExpMatch? match = standardUrlRegEx.firstMatch(url);
|
||||
if (match == null) {
|
||||
throw InvalidURLError(name);
|
||||
@@ -70,15 +77,19 @@ class GitLab extends AppSource {
|
||||
Future<String?> getPATIfAny(Map<String, dynamic> additionalSettings) async {
|
||||
SettingsProvider settingsProvider = SettingsProvider();
|
||||
await settingsProvider.initializeSettings();
|
||||
var sourceConfig =
|
||||
await getSourceConfigValues(additionalSettings, settingsProvider);
|
||||
var sourceConfig = await getSourceConfigValues(
|
||||
additionalSettings,
|
||||
settingsProvider,
|
||||
);
|
||||
String? creds = sourceConfig['gitlab-creds'];
|
||||
return creds != null && creds.isNotEmpty ? creds : null;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Map<String, List<String>>> search(String query,
|
||||
{Map<String, dynamic> querySettings = const {}}) async {
|
||||
Future<Map<String, List<String>>> search(
|
||||
String query, {
|
||||
Map<String, dynamic> querySettings = const {},
|
||||
}) async {
|
||||
var url =
|
||||
'https://${hosts[0]}/api/v4/projects?search=${Uri.encodeQueryComponent(query)}';
|
||||
var res = await sourceRequest(url, {});
|
||||
@@ -90,7 +101,7 @@ class GitLab extends AppSource {
|
||||
for (var element in json) {
|
||||
results['https://${hosts[0]}/${element['path_with_namespace']}'] = [
|
||||
element['name_with_namespace'],
|
||||
element['description'] ?? tr('noDescription')
|
||||
element['description'] ?? tr('noDescription'),
|
||||
];
|
||||
}
|
||||
return results;
|
||||
@@ -102,8 +113,9 @@ class GitLab extends AppSource {
|
||||
|
||||
@override
|
||||
Future<Map<String, String>?> getRequestHeaders(
|
||||
Map<String, dynamic> additionalSettings,
|
||||
{bool forAPKDownload = false}) async {
|
||||
Map<String, dynamic> additionalSettings, {
|
||||
bool forAPKDownload = false,
|
||||
}) async {
|
||||
// Change headers to pacify, e.g. cloudflare protection
|
||||
// Related to: (#1397, #1389, #1384, #1382, #1381, #1380, #1359, #854, #785, #697)
|
||||
var headers = <String, String>{};
|
||||
@@ -116,8 +128,11 @@ class GitLab extends AppSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<String> apkUrlPrefetchModifier(String apkUrl, String standardUrl,
|
||||
Map<String, dynamic> additionalSettings) async {
|
||||
Future<String> apkUrlPrefetchModifier(
|
||||
String apkUrl,
|
||||
String standardUrl,
|
||||
Map<String, dynamic> additionalSettings,
|
||||
) async {
|
||||
String? PAT = await getPATIfAny(hostChanged ? additionalSettings : {});
|
||||
String optionalAuth = (PAT != null) ? 'private_token=$PAT' : '';
|
||||
return '$apkUrl${(Uri.parse(apkUrl).query.isEmpty ? '?' : '&')}$optionalAuth';
|
||||
@@ -139,8 +154,9 @@ class GitLab extends AppSource {
|
||||
|
||||
// Get project ID
|
||||
Response res0 = await sourceRequest(
|
||||
'https://${hosts[0]}/api/v4/projects/$projectUriComponent?$optionalAuth',
|
||||
additionalSettings);
|
||||
'https://${hosts[0]}/api/v4/projects/$projectUriComponent?$optionalAuth',
|
||||
additionalSettings,
|
||||
);
|
||||
if (res0.statusCode != 200) {
|
||||
throw getObtainiumHttpError(res0);
|
||||
}
|
||||
@@ -151,8 +167,9 @@ class GitLab extends AppSource {
|
||||
|
||||
// Request data from REST API
|
||||
Response res = await sourceRequest(
|
||||
'https://${hosts[0]}/api/v4/projects/$projectUriComponent/${trackOnly ? 'repository/tags' : 'releases'}?$optionalAuth',
|
||||
additionalSettings);
|
||||
'https://${hosts[0]}/api/v4/projects/$projectUriComponent/${trackOnly ? 'repository/tags' : 'releases'}?$optionalAuth',
|
||||
additionalSettings,
|
||||
);
|
||||
if (res.statusCode != 200) {
|
||||
throw getObtainiumHttpError(res);
|
||||
}
|
||||
@@ -166,11 +183,13 @@ class GitLab extends AppSource {
|
||||
var url = (e['direct_asset_url'] ?? e['url'] ?? '') as String;
|
||||
var parsedUrl = url.isNotEmpty ? Uri.parse(url) : null;
|
||||
return MapEntry(
|
||||
(e['name'] ??
|
||||
(parsedUrl != null && parsedUrl.pathSegments.isNotEmpty
|
||||
? parsedUrl.pathSegments.last
|
||||
: 'unknown')) as String,
|
||||
(e['direct_asset_url'] ?? e['url'] ?? '') as String);
|
||||
(e['name'] ??
|
||||
(parsedUrl != null && parsedUrl.pathSegments.isNotEmpty
|
||||
? parsedUrl.pathSegments.last
|
||||
: 'unknown'))
|
||||
as String,
|
||||
(e['direct_asset_url'] ?? e['url'] ?? '') as String,
|
||||
);
|
||||
})
|
||||
.where((s) => s.key.isNotEmpty)
|
||||
.toList();
|
||||
@@ -193,11 +212,15 @@ class GitLab extends AppSource {
|
||||
}
|
||||
var releaseDateString =
|
||||
e['released_at'] ?? e['created_at'] ?? e['commit']?['created_at'];
|
||||
DateTime? releaseDate =
|
||||
releaseDateString != null ? DateTime.parse(releaseDateString) : null;
|
||||
return APKDetails(e['tag_name'] ?? e['name'], apkUrls.entries.toList(),
|
||||
AppNames(names.author, names.name.split('/').last),
|
||||
releaseDate: releaseDate);
|
||||
DateTime? releaseDate = releaseDateString != null
|
||||
? DateTime.parse(releaseDateString)
|
||||
: null;
|
||||
return APKDetails(
|
||||
e['tag_name'] ?? e['name'],
|
||||
apkUrls.entries.toList(),
|
||||
AppNames(names.author, names.name.split('/').last),
|
||||
releaseDate: releaseDate,
|
||||
);
|
||||
});
|
||||
if (apkDetailsList.isEmpty) {
|
||||
throw NoReleasesError();
|
||||
@@ -208,8 +231,9 @@ class GitLab extends AppSource {
|
||||
bool fallbackToOlderReleases =
|
||||
additionalSettings['fallbackToOlderReleases'] == true;
|
||||
if (finalResult.apkUrls.isEmpty && fallbackToOlderReleases && !trackOnly) {
|
||||
apkDetailsList =
|
||||
apkDetailsList.where((e) => e.apkUrls.isNotEmpty).toList();
|
||||
apkDetailsList = apkDetailsList
|
||||
.where((e) => e.apkUrls.isNotEmpty)
|
||||
.toList();
|
||||
finalResult = apkDetailsList.first;
|
||||
}
|
||||
|
||||
@@ -218,10 +242,13 @@ class GitLab extends AppSource {
|
||||
}
|
||||
|
||||
finalResult.apkUrls = finalResult.apkUrls.map((apkUrl) {
|
||||
if (RegExp('^$standardUrl/-/jobs/[0-9]+/artifacts/file/[^/]+')
|
||||
.hasMatch(apkUrl.value)) {
|
||||
if (RegExp(
|
||||
'^$standardUrl/-/jobs/[0-9]+/artifacts/file/[^/]+',
|
||||
).hasMatch(apkUrl.value)) {
|
||||
return MapEntry(
|
||||
apkUrl.key, apkUrl.value.replaceFirst('/file/', '/raw/'));
|
||||
apkUrl.key,
|
||||
apkUrl.value.replaceFirst('/file/', '/raw/'),
|
||||
);
|
||||
} else {
|
||||
return apkUrl;
|
||||
}
|
||||
|
Reference in New Issue
Block a user