mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-08-11 01:20:16 +02:00
Added descriptions to GitHub starred imports
This commit is contained in:
@@ -12,14 +12,20 @@ class GitHubStars implements MassAppUrlSource {
|
|||||||
@override
|
@override
|
||||||
late List<String> requiredArgs = ['Username'];
|
late List<String> requiredArgs = ['Username'];
|
||||||
|
|
||||||
Future<List<String>> getOnePageOfUserStarredUrls(
|
Future<Map<String, String>> getOnePageOfUserStarredUrlsWithDescriptions(
|
||||||
String username, int page) async {
|
String username, int page) async {
|
||||||
Response res = await get(Uri.parse(
|
Response res = await get(Uri.parse(
|
||||||
'https://${await GitHub().getCredentialPrefixIfAny()}api.github.com/users/$username/starred?per_page=100&page=$page'));
|
'https://${await GitHub().getCredentialPrefixIfAny()}api.github.com/users/$username/starred?per_page=100&page=$page'));
|
||||||
if (res.statusCode == 200) {
|
if (res.statusCode == 200) {
|
||||||
return (jsonDecode(res.body) as List<dynamic>)
|
Map<String, String> urlsWithDescriptions = {};
|
||||||
.map((e) => e['html_url'] as String)
|
for (var e in (jsonDecode(res.body) as List<dynamic>)) {
|
||||||
.toList();
|
urlsWithDescriptions.addAll({
|
||||||
|
e['html_url'] as String: e['description'] != null
|
||||||
|
? e['description'] as String
|
||||||
|
: 'No description'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return urlsWithDescriptions;
|
||||||
} else {
|
} else {
|
||||||
if (res.headers['x-ratelimit-remaining'] == '0') {
|
if (res.headers['x-ratelimit-remaining'] == '0') {
|
||||||
throw RateLimitError(
|
throw RateLimitError(
|
||||||
@@ -33,19 +39,20 @@ class GitHubStars implements MassAppUrlSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<String>> getUrls(List<String> args) async {
|
Future<Map<String, String>> getUrlsWithDescriptions(List<String> args) async {
|
||||||
if (args.length != requiredArgs.length) {
|
if (args.length != requiredArgs.length) {
|
||||||
throw ObtainiumError('Wrong number of arguments provided');
|
throw ObtainiumError('Wrong number of arguments provided');
|
||||||
}
|
}
|
||||||
List<String> urls = [];
|
Map<String, String> urlsWithDescriptions = {};
|
||||||
var page = 1;
|
var page = 1;
|
||||||
while (true) {
|
while (true) {
|
||||||
var pageUrls = await getOnePageOfUserStarredUrls(args[0], page++);
|
var pageUrls =
|
||||||
urls.addAll(pageUrls);
|
await getOnePageOfUserStarredUrlsWithDescriptions(args[0], page++);
|
||||||
|
urlsWithDescriptions.addAll(pageUrls);
|
||||||
if (pageUrls.length < 100) {
|
if (pageUrls.length < 100) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return urls;
|
return urlsWithDescriptions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -357,8 +357,10 @@ class _ImportExportPageState extends State<ImportExportPage> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
importInProgress = true;
|
importInProgress = true;
|
||||||
});
|
});
|
||||||
var urls = await source
|
var urlsWithDescriptions =
|
||||||
.getUrls(values);
|
await source
|
||||||
|
.getUrlsWithDescriptions(
|
||||||
|
values);
|
||||||
var selectedUrls =
|
var selectedUrls =
|
||||||
await showDialog<
|
await showDialog<
|
||||||
List<String>?>(
|
List<String>?>(
|
||||||
@@ -368,10 +370,7 @@ class _ImportExportPageState extends State<ImportExportPage> {
|
|||||||
ctx) {
|
ctx) {
|
||||||
return UrlSelectionModal(
|
return UrlSelectionModal(
|
||||||
urlsWithDescriptions:
|
urlsWithDescriptions:
|
||||||
Map.fromIterable(
|
urlsWithDescriptions);
|
||||||
urls,
|
|
||||||
value: (item) =>
|
|
||||||
''));
|
|
||||||
});
|
});
|
||||||
if (selectedUrls != null) {
|
if (selectedUrls != null) {
|
||||||
var errors =
|
var errors =
|
||||||
|
@@ -167,7 +167,7 @@ class AppSource {
|
|||||||
abstract class MassAppUrlSource {
|
abstract class MassAppUrlSource {
|
||||||
late String name;
|
late String name;
|
||||||
late List<String> requiredArgs;
|
late List<String> requiredArgs;
|
||||||
Future<List<String>> getUrls(List<String> args);
|
Future<Map<String, String>> getUrlsWithDescriptions(List<String> args);
|
||||||
}
|
}
|
||||||
|
|
||||||
class SourceProvider {
|
class SourceProvider {
|
||||||
|
Reference in New Issue
Block a user