prepare home page for upcoming beta (#457)
This commit is contained in:
parent
ff6df97ae8
commit
594d176d39
|
@ -3,6 +3,7 @@ using System.Text.RegularExpressions;
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using StardewModdingAPI.Common;
|
||||
using StardewModdingAPI.Web.Framework.Clients.GitHub;
|
||||
using StardewModdingAPI.Web.ViewModels;
|
||||
|
||||
|
@ -23,7 +24,10 @@ namespace StardewModdingAPI.Web.Controllers
|
|||
private readonly IGitHubClient GitHub;
|
||||
|
||||
/// <summary>The cache time for release info.</summary>
|
||||
private readonly TimeSpan CacheTime = TimeSpan.FromMinutes(5);
|
||||
private readonly TimeSpan CacheTime = TimeSpan.FromSeconds(1);
|
||||
|
||||
/// <summary>The GitHub repository name to check for update.</summary>
|
||||
private readonly string RepositoryName = "Pathoschild/SMAPI";
|
||||
|
||||
|
||||
/*********
|
||||
|
@ -42,17 +46,24 @@ namespace StardewModdingAPI.Web.Controllers
|
|||
[HttpGet]
|
||||
public async Task<ViewResult> Index()
|
||||
{
|
||||
// fetch latest SMAPI release
|
||||
GitRelease release = await this.Cache.GetOrCreateAsync("latest-smapi-release", async entry =>
|
||||
// fetch SMAPI releases
|
||||
IndexVersionModel stableVersion = await this.Cache.GetOrCreateAsync("stable-version", async entry =>
|
||||
{
|
||||
entry.AbsoluteExpiration = DateTimeOffset.UtcNow.Add(this.CacheTime);
|
||||
return await this.GitHub.GetLatestReleaseAsync("Pathoschild/SMAPI");
|
||||
GitRelease release = await this.GitHub.GetLatestReleaseAsync(this.RepositoryName, includePrerelease: false);
|
||||
return new IndexVersionModel(release.Name, release.Body, this.GetMainDownloadUrl(release), this.GetDevDownloadUrl(release));
|
||||
});
|
||||
IndexVersionModel betaVersion = await this.Cache.GetOrCreateAsync("beta-version", async entry =>
|
||||
{
|
||||
entry.AbsoluteExpiration = DateTimeOffset.UtcNow.Add(this.CacheTime);
|
||||
GitRelease release = await this.GitHub.GetLatestReleaseAsync(this.RepositoryName, includePrerelease: true);
|
||||
return release.IsPrerelease
|
||||
? this.GetBetaDownload(release)
|
||||
: null;
|
||||
});
|
||||
string downloadUrl = this.GetMainDownloadUrl(release);
|
||||
string devDownloadUrl = this.GetDevDownloadUrl(release);
|
||||
|
||||
// render view
|
||||
var model = new IndexModel(release.Name, release.Body, downloadUrl, devDownloadUrl);
|
||||
var model = new IndexModel(stableVersion, betaVersion);
|
||||
return this.View(model);
|
||||
}
|
||||
|
||||
|
@ -89,5 +100,33 @@ namespace StardewModdingAPI.Web.Controllers
|
|||
// fallback just in case
|
||||
return "https://github.com/pathoschild/SMAPI/releases";
|
||||
}
|
||||
|
||||
/// <summary>Get the latest beta download for a SMAPI release.</summary>
|
||||
/// <param name="release">The SMAPI release.</param>
|
||||
private IndexVersionModel GetBetaDownload(GitRelease release)
|
||||
{
|
||||
// get download with the latest version
|
||||
SemanticVersionImpl latestVersion = null;
|
||||
string latestUrl = null;
|
||||
foreach (GitAsset asset in release.Assets ?? new GitAsset[0])
|
||||
{
|
||||
// parse version
|
||||
Match versionMatch = Regex.Match(asset.FileName, @"SMAPI-([\d\.]+(?:-.+)?)-installer.zip");
|
||||
if (!versionMatch.Success || !SemanticVersionImpl.TryParse(versionMatch.Groups[1].Value, out SemanticVersionImpl version))
|
||||
continue;
|
||||
|
||||
// save latest version
|
||||
if (latestVersion == null || latestVersion.CompareTo(version) < 0)
|
||||
{
|
||||
latestVersion = version;
|
||||
latestUrl = asset.DownloadUrl;
|
||||
}
|
||||
}
|
||||
|
||||
// return if prerelease
|
||||
return latestVersion?.Tag != null
|
||||
? new IndexVersionModel(latestVersion.ToString(), release.Body, latestUrl, null)
|
||||
: null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,17 +6,11 @@ namespace StardewModdingAPI.Web.ViewModels
|
|||
/*********
|
||||
** Accessors
|
||||
*********/
|
||||
/// <summary>The latest SMAPI version.</summary>
|
||||
public string LatestVersion { get; set; }
|
||||
/// <summary>The latest stable SMAPI version.</summary>
|
||||
public IndexVersionModel StableVersion { get; set; }
|
||||
|
||||
/// <summary>The Markdown description for the release.</summary>
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>The main download URL.</summary>
|
||||
public string DownloadUrl { get; set; }
|
||||
|
||||
/// <summary>The for-developers download URL.</summary>
|
||||
public string DevDownloadUrl { get; set; }
|
||||
/// <summary>The latest prerelease SMAPI version (if newer than <see cref="StableVersion"/>).</summary>
|
||||
public IndexVersionModel BetaVersion { get; set; }
|
||||
|
||||
|
||||
/*********
|
||||
|
@ -26,16 +20,12 @@ namespace StardewModdingAPI.Web.ViewModels
|
|||
public IndexModel() { }
|
||||
|
||||
/// <summary>Construct an instance.</summary>
|
||||
/// <param name="latestVersion">The latest SMAPI version.</param>
|
||||
/// <param name="description">The Markdown description for the release.</param>
|
||||
/// <param name="downloadUrl">The main download URL.</param>
|
||||
/// <param name="devDownloadUrl">The for-developers download URL.</param>
|
||||
internal IndexModel(string latestVersion, string description, string downloadUrl, string devDownloadUrl)
|
||||
/// <param name="stableVersion">The latest stable SMAPI version.</param>
|
||||
/// <param name="betaVersion">The latest prerelease SMAPI version (if newer than <paramref name="stableVersion"/>).</param>
|
||||
internal IndexModel(IndexVersionModel stableVersion, IndexVersionModel betaVersion)
|
||||
{
|
||||
this.LatestVersion = latestVersion;
|
||||
this.Description = description;
|
||||
this.DownloadUrl = downloadUrl;
|
||||
this.DevDownloadUrl = devDownloadUrl;
|
||||
this.StableVersion = stableVersion;
|
||||
this.BetaVersion = betaVersion;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
namespace StardewModdingAPI.Web.ViewModels
|
||||
{
|
||||
/// <summary>The fields for a SMAPI version.</summary>
|
||||
public class IndexVersionModel
|
||||
{
|
||||
/*********
|
||||
** Accessors
|
||||
*********/
|
||||
/// <summary>The release version.</summary>
|
||||
public string Version { get; set; }
|
||||
|
||||
/// <summary>The Markdown description for the release.</summary>
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>The main download URL.</summary>
|
||||
public string DownloadUrl { get; set; }
|
||||
|
||||
/// <summary>The for-developers download URL (not applicable for prerelease versions).</summary>
|
||||
public string DevDownloadUrl { get; set; }
|
||||
|
||||
|
||||
/*********
|
||||
** Public methods
|
||||
*********/
|
||||
/// <summary>Construct an instance.</summary>
|
||||
public IndexVersionModel() { }
|
||||
|
||||
/// <summary>Construct an instance.</summary>
|
||||
/// <param name="version">The release number.</param>
|
||||
/// <param name="description">The Markdown description for the release.</param>
|
||||
/// <param name="downloadUrl">The main download URL.</param>
|
||||
/// <param name="devDownloadUrl">The for-developers download URL (not applicable for prerelease versions).</param>
|
||||
internal IndexVersionModel(string version, string description, string downloadUrl, string devDownloadUrl)
|
||||
{
|
||||
this.Version = version;
|
||||
this.Description = description;
|
||||
this.DownloadUrl = downloadUrl;
|
||||
this.DevDownloadUrl = devDownloadUrl;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,7 +13,11 @@
|
|||
</p>
|
||||
|
||||
<div id="call-to-action">
|
||||
<a href="@Model.DownloadUrl" class="main-cta">Download SMAPI @Model.LatestVersion</a><br />
|
||||
<a href="@Model.StableVersion.DownloadUrl" class="main-cta">Download SMAPI @Model.StableVersion.Version</a><br />
|
||||
@if (Model.BetaVersion != null)
|
||||
{
|
||||
<a href="@Model.BetaVersion.DownloadUrl" class="secondary-cta">Download SMAPI @Model.BetaVersion.Version<br /><small>for Stardew Valley 1.3 beta</small></a><br />
|
||||
}
|
||||
<a href="https://stardewvalleywiki.com/Modding:Installing_SMAPI" class="secondary-cta">Install guide</a><br />
|
||||
<a href="https://stardewvalleywiki.com/Modding:Player_FAQs" class="secondary-cta">FAQs</a><br />
|
||||
<img src="favicon.ico" />
|
||||
|
@ -25,12 +29,29 @@
|
|||
<li>Get help <a href="https://stardewvalleywiki.com/Modding:Community#Discord">on Discord</a> or <a href="https://community.playstarbound.com/threads/smapi-stardew-modding-api.108375/">in the forums</a></li>
|
||||
</ul>
|
||||
|
||||
<h2>What's new in SMAPI @Model.LatestVersion?</h2>
|
||||
<div class="github-description">
|
||||
@Html.Raw(Markdig.Markdown.ToHtml(Model.Description))
|
||||
</div>
|
||||
@if (Model.BetaVersion == null)
|
||||
{
|
||||
<h2>What's new in SMAPI @Model.StableVersion.Version?</h2>
|
||||
<div class="github-description">
|
||||
@Html.Raw(Markdig.Markdown.ToHtml(Model.StableVersion.Description))
|
||||
</div>
|
||||
<p>See the <a href="https://github.com/Pathoschild/SMAPI/blob/develop/docs/release-notes.md#release-notes">release notes</a> and <a href="https://stardewvalleywiki.com/Modding:SMAPI_compatibility">mod compatibility list</a> for more info.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<h2>What's new in...</h2>
|
||||
<h3>SMAPI @Model.StableVersion.Version?</h3>
|
||||
<div class="github-description">
|
||||
@Html.Raw(Markdig.Markdown.ToHtml(Model.StableVersion.Description))
|
||||
</div>
|
||||
<p>See the <a href="https://github.com/Pathoschild/SMAPI/blob/develop/docs/release-notes.md#release-notes">release notes</a> and <a href="https://stardewvalleywiki.com/Modding:SMAPI_compatibility">mod compatibility list</a> for more info.</p>
|
||||
|
||||
<p>See the <a href="https://github.com/Pathoschild/SMAPI/blob/develop/docs/release-notes.md#release-notes">release notes</a> and <a href="https://stardewvalleywiki.com/Modding:SMAPI_compatibility">mod compatibility list</a> for more info.</p>
|
||||
<h3>SMAPI @Model.BetaVersion.Version?</h3>
|
||||
<div class="github-description">
|
||||
@Html.Raw(Markdig.Markdown.ToHtml(Model.BetaVersion.Description))
|
||||
</div>
|
||||
<p>See the <a href="https://github.com/Pathoschild/SMAPI/blob/develop/docs/release-notes.md#release-notes">release notes</a> and <a href="https://stardewvalleywiki.com/Modding:SMAPI_compatibility">mod compatibility list</a> for more info.</p>
|
||||
}
|
||||
|
||||
<h2>Donate to support SMAPI ♥</h2>
|
||||
<p>
|
||||
|
@ -62,7 +83,7 @@
|
|||
|
||||
<h2>For mod creators</h2>
|
||||
<ul>
|
||||
<li><a href="@Model.DevDownloadUrl">SMAPI @Model.LatestVersion for developers</a> (includes <a href="https://docs.microsoft.com/en-us/visualstudio/ide/using-intellisense">intellisense</a> and full console output)</li>
|
||||
<li><a href="@Model.StableVersion.DevDownloadUrl">SMAPI @Model.StableVersion.Version for developers</a> (includes <a href="https://docs.microsoft.com/en-us/visualstudio/ide/using-intellisense">intellisense</a> and full console output)</li>
|
||||
<li><a href="https://stardewvalleywiki.com/Modding:Index">Modding documentation</a></li>
|
||||
<li>Need help? Come <a href="https://stardewvalleywiki.com/Modding:Community#Discord">chat on Discord</a>.</li>
|
||||
</ul>
|
||||
|
|
Loading…
Reference in New Issue