mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-07-13 13:26:43 +02:00
- "Source config" refers to source-specific, app-agnostic settings - Don't use saved config for overridden sources - For overridden sources, use app-specific source config - Allow sources to show notes on add-app page (#720)
59 lines
1.8 KiB
Dart
59 lines
1.8 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
import 'package:http/http.dart';
|
|
import 'package:obtainium/app_sources/github.dart';
|
|
import 'package:obtainium/custom_errors.dart';
|
|
import 'package:obtainium/providers/source_provider.dart';
|
|
|
|
class GitHubStars implements MassAppUrlSource {
|
|
@override
|
|
late String name = tr('githubStarredRepos');
|
|
|
|
@override
|
|
late List<String> requiredArgs = [tr('uname')];
|
|
|
|
Future<Map<String, List<String>>> getOnePageOfUserStarredUrlsWithDescriptions(
|
|
String username, int page) async {
|
|
Response res = await get(Uri.parse(
|
|
'https://${await GitHub().getCredentialPrefixIfAny({})}api.github.com/users/$username/starred?per_page=100&page=$page'));
|
|
if (res.statusCode == 200) {
|
|
Map<String, List<String>> urlsWithDescriptions = {};
|
|
for (var e in (jsonDecode(res.body) as List<dynamic>)) {
|
|
urlsWithDescriptions.addAll({
|
|
e['html_url'] as String: [
|
|
e['full_name'] as String,
|
|
e['description'] != null
|
|
? e['description'] as String
|
|
: tr('noDescription')
|
|
]
|
|
});
|
|
}
|
|
return urlsWithDescriptions;
|
|
} else {
|
|
var gh = GitHub();
|
|
gh.rateLimitErrorCheck(res);
|
|
throw getObtainiumHttpError(res);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<Map<String, List<String>>> getUrlsWithDescriptions(
|
|
List<String> args) async {
|
|
if (args.length != requiredArgs.length) {
|
|
throw ObtainiumError(tr('wrongArgNum'));
|
|
}
|
|
Map<String, List<String>> urlsWithDescriptions = {};
|
|
var page = 1;
|
|
while (true) {
|
|
var pageUrls =
|
|
await getOnePageOfUserStarredUrlsWithDescriptions(args[0], page++);
|
|
urlsWithDescriptions.addAll(pageUrls);
|
|
if (pageUrls.length < 100) {
|
|
break;
|
|
}
|
|
}
|
|
return urlsWithDescriptions;
|
|
}
|
|
}
|