mirror of
				https://github.com/ImranR98/Obtainium.git
				synced 2025-10-30 21:13:28 +01:00 
			
		
		
		
	GitLab search (#422) + better settings UI
This commit is contained in:
		| @@ -73,7 +73,8 @@ class FDroid extends AppSource { | ||||
|  | ||||
|   @override | ||||
|   Future<Map<String, List<String>>> search(String query) async { | ||||
|     Response res = await sourceRequest('https://search.$host/?q=$query'); | ||||
|     Response res = await sourceRequest( | ||||
|         'https://search.$host/?q=${Uri.encodeQueryComponent(query)}'); | ||||
|     if (res.statusCode == 200) { | ||||
|       Map<String, List<String>> urlsWithDescriptions = {}; | ||||
|       parse(res.body).querySelectorAll('.package-header').forEach((e) { | ||||
|   | ||||
| @@ -35,7 +35,7 @@ class GitHub extends AppSource { | ||||
|           hint: tr('githubPATFormat'), | ||||
|           belowWidgets: [ | ||||
|             const SizedBox( | ||||
|               height: 8, | ||||
|               height: 4, | ||||
|             ), | ||||
|             GestureDetector( | ||||
|                 onTap: () { | ||||
| @@ -44,10 +44,13 @@ class GitHub extends AppSource { | ||||
|                       mode: LaunchMode.externalApplication); | ||||
|                 }, | ||||
|                 child: Text( | ||||
|                   tr('githubPATLinkText'), | ||||
|                   tr('about'), | ||||
|                   style: const TextStyle( | ||||
|                       decoration: TextDecoration.underline, fontSize: 12), | ||||
|                 )) | ||||
|                 )), | ||||
|             const SizedBox( | ||||
|               height: 4, | ||||
|             ), | ||||
|           ]) | ||||
|     ]; | ||||
|  | ||||
|   | ||||
| @@ -1,15 +1,47 @@ | ||||
| import 'dart:convert'; | ||||
|  | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:html/parser.dart'; | ||||
| import 'package:http/http.dart'; | ||||
| import 'package:obtainium/app_sources/github.dart'; | ||||
| import 'package:obtainium/custom_errors.dart'; | ||||
| import 'package:obtainium/providers/settings_provider.dart'; | ||||
| import 'package:obtainium/providers/source_provider.dart'; | ||||
| import 'package:obtainium/components/generated_form.dart'; | ||||
| import 'package:easy_localization/easy_localization.dart'; | ||||
| import 'package:url_launcher/url_launcher_string.dart'; | ||||
|  | ||||
| class GitLab extends AppSource { | ||||
|   GitLab() { | ||||
|     host = 'gitlab.com'; | ||||
|     overrideEligible = true; | ||||
|     canSearch = true; | ||||
|  | ||||
|     additionalSourceSpecificSettingFormItems = [ | ||||
|       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), | ||||
|                 )), | ||||
|             const SizedBox( | ||||
|               height: 4, | ||||
|             ) | ||||
|           ]) | ||||
|     ]; | ||||
|  | ||||
|     additionalSourceAppSpecificSettingFormItems = [ | ||||
|       [ | ||||
| @@ -29,6 +61,37 @@ class GitLab extends AppSource { | ||||
|     return url.substring(0, match.end); | ||||
|   } | ||||
|  | ||||
|   Future<String?> getPATIfAny() async { | ||||
|     SettingsProvider settingsProvider = SettingsProvider(); | ||||
|     await settingsProvider.initializeSettings(); | ||||
|     String? creds = settingsProvider | ||||
|         .getSettingString(additionalSourceSpecificSettingFormItems[0].key); | ||||
|     return creds != null && creds.isNotEmpty ? creds : null; | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   Future<Map<String, List<String>>> search(String query) async { | ||||
|     String? PAT = await getPATIfAny(); | ||||
|     if (PAT == null) { | ||||
|       throw CredsNeededError(name); | ||||
|     } | ||||
|     var url = | ||||
|         'https://$host/api/v4/search?private_token=$PAT&scope=projects&search=${Uri.encodeQueryComponent(query)}'; | ||||
|     var res = await sourceRequest(url); | ||||
|     if (res.statusCode != 200) { | ||||
|       throw getObtainiumHttpError(res); | ||||
|     } | ||||
|     var json = jsonDecode(res.body) as List<dynamic>; | ||||
|     Map<String, List<String>> results = {}; | ||||
|     json.forEach((element) { | ||||
|       results['https://$host/${element['path_with_namespace']}'] = [ | ||||
|         element['name_with_namespace'], | ||||
|         element['description'] ?? tr('noDescription') | ||||
|       ]; | ||||
|     }); | ||||
|     return results; | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   String? changeLogPageFromStandardUrl(String standardUrl) => | ||||
|       '$standardUrl/-/releases'; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user