mirror of
https://github.com/ReVanced/revanced-manager.git
synced 2026-01-25 12:01:02 +00:00
fix: code refactoring (#5)
This commit is contained in:
@@ -1,52 +1,19 @@
|
||||
import 'dart:io';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:path_provider/path_provider.dart' as p;
|
||||
import 'package:revanced_manager/constants.dart';
|
||||
import 'package:revanced_manager/services/github_api.dart';
|
||||
|
||||
@lazySingleton
|
||||
class ManagerAPI {
|
||||
final Dio dio = Dio();
|
||||
final GithubAPI githubAPI = GithubAPI();
|
||||
final GithubAPI _githubAPI = GithubAPI();
|
||||
|
||||
Future<String?> getPath() async {
|
||||
final path = await p.getApplicationSupportDirectory();
|
||||
Directory('${path.path}/revanced').createSync();
|
||||
final workDirPath = '${path.path}/revanced';
|
||||
return workDirPath;
|
||||
Future<File?> downloadPatches() async {
|
||||
return await _githubAPI.latestRelease(ghOrg, patchesRepo);
|
||||
}
|
||||
|
||||
Future<File?> downloadAssets(String repo) async {
|
||||
try {
|
||||
final workDir = await getPath();
|
||||
final dlUrl = await githubAPI.latestRelease(ghOrg, repo);
|
||||
final name = dlUrl
|
||||
?.split('/')
|
||||
.lastWhere((element) => element.contains('revanced'));
|
||||
final assetFile = File('$workDir/$name');
|
||||
final response = await dio.get(
|
||||
dlUrl!,
|
||||
options: Options(
|
||||
responseType: ResponseType.bytes,
|
||||
followRedirects: true,
|
||||
receiveTimeout: 0,
|
||||
),
|
||||
);
|
||||
final raf = assetFile.openSync(mode: FileMode.write);
|
||||
raf.writeFromSync(response.data);
|
||||
raf.closeSync();
|
||||
return assetFile;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
Future<File?> downloadIntegrations() async {
|
||||
return await _githubAPI.latestRelease(ghOrg, integrationsRepo);
|
||||
}
|
||||
|
||||
Future<void> downloadPatches() async {
|
||||
await downloadAssets(patchesRepo);
|
||||
}
|
||||
|
||||
Future<void> downloadIntegrations() async {
|
||||
await downloadAssets(integrationsRepo);
|
||||
Future<File?> downloadManager() async {
|
||||
return await _githubAPI.latestRelease(ghOrg, managerRepo);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user