mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 14:10:53 +00:00
Rewrite GitHub releases for ASF-ui
@JustArchiNET/asf-ui-dev Summary of changes:
Old:
- GET GitHub/Releases is rip (rewritten)
- GET GitHub/Releases/{version:required} is rip (renamed)
New:
- GET GitHub/Release, returns the most recent release (can be pre, can be stable)
- GET GitHub/Release/{version:required}, works like before, but also accepts "latest" as version for fetching latest stable release.
Expected usage:
- GET GitHub/Release for fetching most recent release
- If release equals user release, don't do anything more and save requests, display changelog
- Check if the release you fetched is stable, if yes, skip the extra request, otherwise, GET GitHub/Release/latest for latest stable.
- If stable release equals user's release, don't do anything more and save request, show both changelogs (pre and stable)
- Otherwise, decide if you want to also GET GitHub/Release/{userVersion} for that specific release.
Adapt appropriately for usage (I'd recommend to check if user has enabled pre-releases in the first place, because if he's on stable channel then likely you shouldn't display him pre-release changelogs at all, and skip the first request).
If in doubt, check swagger doc.
This commit is contained in:
@@ -58,19 +58,6 @@ namespace ArchiSteamFarm {
|
||||
return await GetReleaseFromURL(SharedInfo.GithubReleaseURL + "/tags/" + version).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[ItemCanBeNull]
|
||||
internal static async Task<ImmutableList<ReleaseResponse>> GetReleases(byte count) {
|
||||
if (count == 0) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(count));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
string releaseURL = SharedInfo.GithubReleaseURL + "?per_page=" + count;
|
||||
|
||||
return await GetReleasesFromURL(releaseURL).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private static MarkdownDocument ExtractChangelogFromBody(string markdownText) {
|
||||
if (string.IsNullOrEmpty(markdownText)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(markdownText));
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
@@ -71,47 +70,37 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches newest GitHub releases of ASF project.
|
||||
/// Fetches the most recent GitHub release of ASF project.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is internal API being utilizied by our ASF-ui IPC frontend. You should not depend on existence of any /Api/WWW endpoints as they can disappear and change anytime.
|
||||
/// </remarks>
|
||||
[HttpGet("GitHub/Releases")]
|
||||
[ProducesResponseType(typeof(GenericResponse<IReadOnlyCollection<GitHubReleaseResponse>>), (int) HttpStatusCode.OK)]
|
||||
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
|
||||
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.ServiceUnavailable)]
|
||||
public async Task<ActionResult<GenericResponse>> GitHubReleasesGet([FromQuery] byte count = 10) {
|
||||
if (count == 0) {
|
||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsEmpty, nameof(count))));
|
||||
}
|
||||
|
||||
ImmutableList<GitHub.ReleaseResponse> response = await GitHub.GetReleases(count).ConfigureAwait(false);
|
||||
|
||||
if ((response == null) || (response.Count == 0)) {
|
||||
return StatusCode((int) HttpStatusCode.ServiceUnavailable, new GenericResponse(false, string.Format(Strings.ErrorRequestFailedTooManyTimes, WebBrowser.MaxTries)));
|
||||
}
|
||||
|
||||
List<GitHubReleaseResponse> result = response.Select(singleResponse => new GitHubReleaseResponse(singleResponse)).ToList();
|
||||
|
||||
return Ok(new GenericResponse<IReadOnlyCollection<GitHubReleaseResponse>>(result));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches specific GitHub release of ASF project.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is internal API being utilizied by our ASF-ui IPC frontend. You should not depend on existence of any /Api/WWW endpoints as they can disappear and change anytime.
|
||||
/// </remarks>
|
||||
[HttpGet("GitHub/Releases/{version:required}")]
|
||||
[HttpGet("GitHub/Release")]
|
||||
[ProducesResponseType(typeof(GenericResponse<GitHubReleaseResponse>), (int) HttpStatusCode.OK)]
|
||||
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
|
||||
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.ServiceUnavailable)]
|
||||
public async Task<ActionResult<GenericResponse>> GitHubReleasesGet(string version) {
|
||||
public async Task<ActionResult<GenericResponse>> GitHubReleaseGet() {
|
||||
GitHub.ReleaseResponse releaseResponse = await GitHub.GetLatestRelease(false).ConfigureAwait(false);
|
||||
|
||||
return releaseResponse != null ? Ok(new GenericResponse<GitHubReleaseResponse>(new GitHubReleaseResponse(releaseResponse))) : StatusCode((int) HttpStatusCode.ServiceUnavailable, new GenericResponse(false, string.Format(Strings.ErrorRequestFailedTooManyTimes, WebBrowser.MaxTries)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches specific GitHub release of ASF project. Use "latest" for latest stable release.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is internal API being utilizied by our ASF-ui IPC frontend. You should not depend on existence of any /Api/WWW endpoints as they can disappear and change anytime.
|
||||
/// </remarks>
|
||||
[HttpGet("GitHub/Release/{version:required}")]
|
||||
[ProducesResponseType(typeof(GenericResponse<GitHubReleaseResponse>), (int) HttpStatusCode.OK)]
|
||||
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
|
||||
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.ServiceUnavailable)]
|
||||
public async Task<ActionResult<GenericResponse>> GitHubReleaseGet(string version) {
|
||||
if (string.IsNullOrEmpty(version)) {
|
||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsEmpty, nameof(version))));
|
||||
}
|
||||
|
||||
GitHub.ReleaseResponse releaseResponse = await GitHub.GetRelease(version).ConfigureAwait(false);
|
||||
GitHub.ReleaseResponse releaseResponse = version.Equals("latest", StringComparison.OrdinalIgnoreCase) ? await GitHub.GetLatestRelease().ConfigureAwait(false) : await GitHub.GetRelease(version).ConfigureAwait(false);
|
||||
|
||||
return releaseResponse != null ? Ok(new GenericResponse<GitHubReleaseResponse>(new GitHubReleaseResponse(releaseResponse))) : StatusCode((int) HttpStatusCode.ServiceUnavailable, new GenericResponse(false, string.Format(Strings.ErrorRequestFailedTooManyTimes, WebBrowser.MaxTries)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user