diff --git a/ArchiSteamFarm/GitHub.cs b/ArchiSteamFarm/GitHub.cs index e1ab9db6c..9f4eff07b 100644 --- a/ArchiSteamFarm/GitHub.cs +++ b/ArchiSteamFarm/GitHub.cs @@ -58,19 +58,6 @@ namespace ArchiSteamFarm { return await GetReleaseFromURL(SharedInfo.GithubReleaseURL + "/tags/" + version).ConfigureAwait(false); } - [ItemCanBeNull] - internal static async Task> 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)); diff --git a/ArchiSteamFarm/IPC/Controllers/Api/WWWController.cs b/ArchiSteamFarm/IPC/Controllers/Api/WWWController.cs index cbe894c48..65ba09d39 100644 --- a/ArchiSteamFarm/IPC/Controllers/Api/WWWController.cs +++ b/ArchiSteamFarm/IPC/Controllers/Api/WWWController.cs @@ -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 { } /// - /// Fetches newest GitHub releases of ASF project. + /// Fetches the most recent GitHub release of ASF project. /// /// /// 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. /// - [HttpGet("GitHub/Releases")] - [ProducesResponseType(typeof(GenericResponse>), (int) HttpStatusCode.OK)] - [ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)] - [ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.ServiceUnavailable)] - public async Task> GitHubReleasesGet([FromQuery] byte count = 10) { - if (count == 0) { - return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsEmpty, nameof(count)))); - } - - ImmutableList 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 result = response.Select(singleResponse => new GitHubReleaseResponse(singleResponse)).ToList(); - - return Ok(new GenericResponse>(result)); - } - - /// - /// Fetches specific GitHub release of ASF project. - /// - /// - /// 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. - /// - [HttpGet("GitHub/Releases/{version:required}")] + [HttpGet("GitHub/Release")] [ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.OK)] [ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)] [ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.ServiceUnavailable)] - public async Task> GitHubReleasesGet(string version) { + public async Task> GitHubReleaseGet() { + GitHub.ReleaseResponse releaseResponse = await GitHub.GetLatestRelease(false).ConfigureAwait(false); + + return releaseResponse != null ? Ok(new GenericResponse(new GitHubReleaseResponse(releaseResponse))) : StatusCode((int) HttpStatusCode.ServiceUnavailable, new GenericResponse(false, string.Format(Strings.ErrorRequestFailedTooManyTimes, WebBrowser.MaxTries))); + } + + /// + /// Fetches specific GitHub release of ASF project. Use "latest" for latest stable release. + /// + /// + /// 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. + /// + [HttpGet("GitHub/Release/{version:required}")] + [ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.OK)] + [ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)] + [ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.ServiceUnavailable)] + public async Task> 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(new GitHubReleaseResponse(releaseResponse))) : StatusCode((int) HttpStatusCode.ServiceUnavailable, new GenericResponse(false, string.Format(Strings.ErrorRequestFailedTooManyTimes, WebBrowser.MaxTries))); }