mirror of
				https://github.com/ImranR98/Obtainium.git
				synced 2025-10-27 11:43:47 +01:00 
			
		
		
		
	Third party GitLab search (#1108)
This commit is contained in:
		| @@ -54,17 +54,25 @@ class FDroidRepo extends AppSource { | ||||
|   @override | ||||
|   Future<Map<String, List<String>>> search(String query, | ||||
|       {Map<String, dynamic> querySettings = const {}}) async { | ||||
|     query = removeQueryParamsFromUrl(standardizeUrl(query)); | ||||
|     var res = await sourceRequest('$query/index.xml'); | ||||
|     String? url = querySettings['url']; | ||||
|     if (url == null) { | ||||
|       throw NoReleasesError(); | ||||
|     } | ||||
|     url = removeQueryParamsFromUrl(standardizeUrl(url)); | ||||
|     var res = await sourceRequest('$url/index.xml'); | ||||
|     if (res.statusCode == 200) { | ||||
|       var body = parse(res.body); | ||||
|       Map<String, List<String>> results = {}; | ||||
|       body.querySelectorAll('application').toList().forEach((app) { | ||||
|         String appId = app.attributes['id']!; | ||||
|         results['$query?appId=$appId'] = [ | ||||
|           app.querySelector('name')?.innerHtml ?? appId, | ||||
|           app.querySelector('desc')?.innerHtml ?? '' | ||||
|         ]; | ||||
|         String appName = app.querySelector('name')?.innerHtml ?? appId; | ||||
|         String appDesc = app.querySelector('desc')?.innerHtml ?? ''; | ||||
|         if (query.isEmpty || | ||||
|             appId.contains(query) || | ||||
|             appName.contains(query) || | ||||
|             appDesc.contains(query)) { | ||||
|           results['$url?appId=$appId'] = [appName, appDesc]; | ||||
|         } | ||||
|       }); | ||||
|       return results; | ||||
|     } else { | ||||
|   | ||||
| @@ -48,6 +48,12 @@ class GitLab extends AppSource { | ||||
|             label: tr('fallbackToOlderReleases'), defaultValue: true) | ||||
|       ] | ||||
|     ]; | ||||
|     searchQuerySettingFormItems = [ | ||||
|       GeneratedFormTextField('PAT', | ||||
|           label: tr('gitlabPATLabel').split('(')[0], | ||||
|           password: true, | ||||
|           required: false) | ||||
|     ]; | ||||
|   } | ||||
|  | ||||
|   @override | ||||
| @@ -80,12 +86,18 @@ class GitLab extends AppSource { | ||||
|   @override | ||||
|   Future<Map<String, List<String>>> search(String query, | ||||
|       {Map<String, dynamic> querySettings = const {}}) async { | ||||
|     String? PAT = await getPATIfAny({}); | ||||
|     if (PAT == null) { | ||||
|       throw CredsNeededError(name); | ||||
|     String? PAT; | ||||
|     if (!hostChanged) { | ||||
|       PAT = await getPATIfAny({}); | ||||
|       if (PAT == null) { | ||||
|         throw CredsNeededError(name); | ||||
|       } | ||||
|     } | ||||
|     if ((querySettings['PAT'] as String?)?.isNotEmpty == true) { | ||||
|       PAT = querySettings['PAT']; | ||||
|     } | ||||
|     var url = | ||||
|         'https://$host/api/v4/search?private_token=$PAT&scope=projects&search=${Uri.encodeQueryComponent(query)}'; | ||||
|         'https://$host/api/v4/search?${PAT?.isNotEmpty == true ? 'private_token=$PAT&' : ''}scope=projects&search=${Uri.encodeQueryComponent(query)}'; | ||||
|     var res = await sourceRequest(url); | ||||
|     if (res.statusCode != 200) { | ||||
|       throw getObtainiumHttpError(res); | ||||
| @@ -174,7 +186,6 @@ class GitLab extends AppSource { | ||||
|           ...getLinksFromParsedHTML(entryContent, | ||||
|                   RegExp('/[^/]+\\.apk\$', caseSensitive: false), '') | ||||
|               .where((element) => Uri.parse(element).host != '') | ||||
|                | ||||
|         ]; | ||||
|         var entryId = entry.querySelector('id')?.innerHtml; | ||||
|         var version = | ||||
|   | ||||
| @@ -4,6 +4,7 @@ import 'dart:io'; | ||||
| import 'package:easy_localization/easy_localization.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:flutter/services.dart'; | ||||
| import 'package:obtainium/app_sources/fdroidrepo.dart'; | ||||
| import 'package:obtainium/components/custom_app_bar.dart'; | ||||
| import 'package:obtainium/components/generated_form.dart'; | ||||
| import 'package:obtainium/components/generated_form_modal.dart'; | ||||
| @@ -189,17 +190,29 @@ class _ImportExportPageState extends State<ImportExportPage> { | ||||
|                 items: [ | ||||
|                   [ | ||||
|                     GeneratedFormTextField('searchQuery', | ||||
|                         label: tr('searchQuery')) | ||||
|                         label: tr('searchQuery'), | ||||
|                         required: source.name != FDroidRepo().name) | ||||
|                   ], | ||||
|                   ...source.searchQuerySettingFormItems.map((e) => [e]), | ||||
|                   [ | ||||
|                     GeneratedFormTextField('url', | ||||
|                         label: source.host != null | ||||
|                             ? tr('overrideSource') | ||||
|                             : plural('url', 1).substring(2), | ||||
|                         defaultValue: source.host ?? '', | ||||
|                         required: true) | ||||
|                   ], | ||||
|                   ...source.searchQuerySettingFormItems.map((e) => [e]) | ||||
|                 ], | ||||
|               ); | ||||
|             }); | ||||
|         if (values != null && | ||||
|             (values['searchQuery'] as String?)?.isNotEmpty == true) { | ||||
|         if (values != null) { | ||||
|           setState(() { | ||||
|             importInProgress = true; | ||||
|           }); | ||||
|           if (values['url'] != source.host) { | ||||
|             source = sourceProvider.getSource(values['url'], | ||||
|                 overrideSource: source.runtimeType.toString()); | ||||
|           } | ||||
|           var urlsWithDescriptions = await source | ||||
|               .search(values['searchQuery'] as String, querySettings: values); | ||||
|           if (urlsWithDescriptions.isNotEmpty) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user