Skip to content

Commit

Permalink
fix: Download latest integrations non-pre-release
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Apr 28, 2024
1 parent 7e0f18e commit 4a72267
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 66 deletions.
66 changes: 5 additions & 61 deletions lib/services/github_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,6 @@ class GithubAPI {

Future<Map<String, dynamic>?> getLatestRelease(
String repoName,
) async {
try {
final response = await _dio.get(
'/repos/$repoName/releases',
);
return response.data[0];
} on Exception catch (e) {
if (kDebugMode) {
print(e);
}
return null;
}
}

Future<Map<String, dynamic>?> getPatchesRelease(
String repoName,
String version,
) async {
try {
final response = await _dio.get(
'/repos/$repoName/releases/tags/$version',
);
return response.data;
} on Exception catch (e) {
if (kDebugMode) {
print(e);
}
return null;
}
}

Future<Map<String, dynamic>?> getLatestPatchesRelease(
String repoName,
) async {
try {
final response = await _dio.get(
Expand Down Expand Up @@ -108,32 +75,7 @@ class GithubAPI {
}
}

Future<File?> getLatestReleaseFile(
String extension,
String repoName,
) async {
try {
final Map<String, dynamic>? release = await getLatestRelease(repoName);
if (release != null) {
final Map<String, dynamic>? asset =
(release['assets'] as List<dynamic>).firstWhereOrNull(
(asset) => (asset['name'] as String).endsWith(extension),
);
if (asset != null) {
return await _downloadManager.getSingleFile(
asset['browser_download_url'],
);
}
}
} on Exception catch (e) {
if (kDebugMode) {
print(e);
}
}
return null;
}

Future<File?> getPatchesReleaseFile(
Future<File?> getReleaseFile(
String extension,
String repoName,
String version,
Expand All @@ -145,8 +87,10 @@ class GithubAPI {
url,
);
}
final Map<String, dynamic>? release =
await getPatchesRelease(repoName, version);
final response = await _dio.get(
'/repos/$repoName/releases/tags/$version',
);
final Map<String, dynamic>? release = response.data;
if (release != null) {
final Map<String, dynamic>? asset =
(release['assets'] as List<dynamic>).firstWhereOrNull(
Expand Down
8 changes: 4 additions & 4 deletions lib/services/manager_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ class ManagerAPI {
final String repoName = !isUsingAlternativeSources() ? defaultPatchesRepo : getPatchesRepo();
final String currentVersion = await getCurrentPatchesVersion();
final String url = getPatchesDownloadURL();
return await _githubAPI.getPatchesReleaseFile(
return await _githubAPI.getReleaseFile(
'.jar',
repoName,
currentVersion,
Expand All @@ -441,7 +441,7 @@ class ManagerAPI {
final String repoName = !isUsingAlternativeSources() ? defaultIntegrationsRepo : getIntegrationsRepo();
final String currentVersion = await getCurrentIntegrationsVersion();
final String url = getIntegrationsDownloadURL();
return await _githubAPI.getPatchesReleaseFile(
return await _githubAPI.getReleaseFile(
'.apk',
repoName,
currentVersion,
Expand Down Expand Up @@ -470,7 +470,7 @@ class ManagerAPI {
);
} else {
final release =
await _githubAPI.getLatestPatchesRelease(getPatchesRepo());
await _githubAPI.getLatestRelease(getPatchesRepo());
if (release != null) {
final DateTime timestamp =
DateTime.parse(release['created_at'] as String);
Expand Down Expand Up @@ -519,7 +519,7 @@ class ManagerAPI {
);
} else {
final release =
await _githubAPI.getLatestPatchesRelease(getPatchesRepo());
await _githubAPI.getLatestRelease(getPatchesRepo());
if (release != null) {
return release['tag_name'];
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/views/home/home_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ class HomeViewModel extends BaseViewModel {
}

Future<Map<String, dynamic>?> getLatestPatchesRelease() {
return _githubAPI.getLatestPatchesRelease(_managerAPI.defaultPatchesRepo);
return _githubAPI.getLatestRelease(_managerAPI.defaultPatchesRepo);
}

Future<String?> getLatestPatchesReleaseTime() {
Expand Down

0 comments on commit 4a72267

Please sign in to comment.