From 436c071ba4ecbe43769b438277d441057d05403e Mon Sep 17 00:00:00 2001
From: Jesse Plamondon-Willard
Date: Thu, 15 Mar 2018 19:52:18 -0400
Subject: add support for preview GitHub releases (#457)
---
.../Framework/Clients/GitHub/GitHubClient.cs | 50 ++++++++++++++++------
.../Framework/Clients/GitHub/GitRelease.cs | 4 ++
.../Framework/Clients/GitHub/IGitHubClient.cs | 5 ++-
.../Framework/ConfigModels/ApiClientsConfig.cs | 7 ++-
.../ModRepositories/ChucklefishRepository.cs | 2 +-
.../Framework/ModRepositories/GitHubRepository.cs | 19 ++++++--
.../Framework/ModRepositories/NexusRepository.cs | 2 +-
src/SMAPI.Web/Startup.cs | 3 +-
src/SMAPI.Web/appsettings.json | 3 +-
9 files changed, 70 insertions(+), 25 deletions(-)
(limited to 'src/SMAPI.Web')
diff --git a/src/SMAPI.Web/Framework/Clients/GitHub/GitHubClient.cs b/src/SMAPI.Web/Framework/Clients/GitHub/GitHubClient.cs
index 0b205660..4abe0737 100644
--- a/src/SMAPI.Web/Framework/Clients/GitHub/GitHubClient.cs
+++ b/src/SMAPI.Web/Framework/Clients/GitHub/GitHubClient.cs
@@ -1,4 +1,5 @@
using System;
+using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Pathoschild.Http.Client;
@@ -11,8 +12,11 @@ namespace StardewModdingAPI.Web.Framework.Clients.GitHub
/*********
** Properties
*********/
- /// The URL for a GitHub releases API query excluding the base URL, where {0} is the repository owner and name.
- private readonly string ReleaseUrlFormat;
+ /// The URL for a GitHub API query for the latest stable release, excluding the base URL, where {0} is the organisation and project name.
+ private readonly string StableReleaseUrlFormat;
+
+ /// The URL for a GitHub API query for the latest release (including prerelease), excluding the base URL, where {0} is the organisation and project name.
+ private readonly string AnyReleaseUrlFormat;
/// The underlying HTTP client.
private readonly IClient Client;
@@ -23,14 +27,16 @@ namespace StardewModdingAPI.Web.Framework.Clients.GitHub
*********/
/// Construct an instance.
/// The base URL for the GitHub API.
- /// The URL for a GitHub releases API query excluding the , where {0} is the repository owner and name.
+ /// The URL for a GitHub API query for the latest stable release, excluding the , where {0} is the organisation and project name.
+ /// The URL for a GitHub API query for the latest release (including prerelease), excluding the , where {0} is the organisation and project name.
/// The user agent for the API client.
/// The Accept header value expected by the GitHub API.
/// The username with which to authenticate to the GitHub API.
/// The password with which to authenticate to the GitHub API.
- public GitHubClient(string baseUrl, string releaseUrlFormat, string userAgent, string acceptHeader, string username, string password)
+ public GitHubClient(string baseUrl, string stableReleaseUrlFormat, string anyReleaseUrlFormat, string userAgent, string acceptHeader, string username, string password)
{
- this.ReleaseUrlFormat = releaseUrlFormat;
+ this.StableReleaseUrlFormat = stableReleaseUrlFormat;
+ this.AnyReleaseUrlFormat = anyReleaseUrlFormat;
this.Client = new FluentClient(baseUrl)
.SetUserAgent(userAgent)
@@ -41,18 +47,23 @@ namespace StardewModdingAPI.Web.Framework.Clients.GitHub
/// Get the latest release for a GitHub repository.
/// The repository key (like Pathoschild/SMAPI ).
- /// Returns the latest release if found, else null .
- public async Task GetLatestReleaseAsync(string repo)
+ /// Whether to return a prerelease version if it's latest.
+ /// Returns the release if found, else null .
+ public async Task GetLatestReleaseAsync(string repo, bool includePrerelease = false)
{
- // validate key format
- if (!repo.Contains("/") || repo.IndexOf("/", StringComparison.InvariantCultureIgnoreCase) != repo.LastIndexOf("/", StringComparison.InvariantCultureIgnoreCase))
- throw new ArgumentException($"The value '{repo}' isn't a valid GitHub repository key, must be a username and project name like 'Pathoschild/SMAPI'.", nameof(repo));
-
- // fetch info
+ this.AssetKeyFormat(repo);
try
{
+ if (includePrerelease)
+ {
+ GitRelease[] results = await this.Client
+ .GetAsync(string.Format(this.AnyReleaseUrlFormat, repo))
+ .AsArray();
+ return results.FirstOrDefault();
+ }
+
return await this.Client
- .GetAsync(string.Format(this.ReleaseUrlFormat, repo))
+ .GetAsync(string.Format(this.StableReleaseUrlFormat, repo))
.As();
}
catch (ApiException ex) when (ex.Status == HttpStatusCode.NotFound)
@@ -66,5 +77,18 @@ namespace StardewModdingAPI.Web.Framework.Clients.GitHub
{
this.Client?.Dispose();
}
+
+
+ /*********
+ ** Private methods
+ *********/
+ /// Assert that a repository key is formatted correctly.
+ /// The repository key (like Pathoschild/SMAPI ).
+ /// The repository key is invalid.
+ private void AssetKeyFormat(string repo)
+ {
+ if (repo == null || !repo.Contains("/") || repo.IndexOf("/", StringComparison.InvariantCultureIgnoreCase) != repo.LastIndexOf("/", StringComparison.InvariantCultureIgnoreCase))
+ throw new ArgumentException($"The value '{repo}' isn't a valid GitHub repository key, must be a username and project name like 'Pathoschild/SMAPI'.", nameof(repo));
+ }
}
}
diff --git a/src/SMAPI.Web/Framework/Clients/GitHub/GitRelease.cs b/src/SMAPI.Web/Framework/Clients/GitHub/GitRelease.cs
index b944088d..827374fb 100644
--- a/src/SMAPI.Web/Framework/Clients/GitHub/GitRelease.cs
+++ b/src/SMAPI.Web/Framework/Clients/GitHub/GitRelease.cs
@@ -19,6 +19,10 @@ namespace StardewModdingAPI.Web.Framework.Clients.GitHub
/// The Markdown description for the release.
public string Body { get; set; }
+ /// Whether this is a prerelease version.
+ [JsonProperty("prerelease")]
+ public bool IsPrerelease { get; set; }
+
/// The attached files.
public GitAsset[] Assets { get; set; }
}
diff --git a/src/SMAPI.Web/Framework/Clients/GitHub/IGitHubClient.cs b/src/SMAPI.Web/Framework/Clients/GitHub/IGitHubClient.cs
index 6e8eadff..9519c26f 100644
--- a/src/SMAPI.Web/Framework/Clients/GitHub/IGitHubClient.cs
+++ b/src/SMAPI.Web/Framework/Clients/GitHub/IGitHubClient.cs
@@ -11,7 +11,8 @@ namespace StardewModdingAPI.Web.Framework.Clients.GitHub
*********/
/// Get the latest release for a GitHub repository.
/// The repository key (like Pathoschild/SMAPI ).
- /// Returns the latest release if found, else null .
- Task GetLatestReleaseAsync(string repo);
+ /// Whether to return a prerelease version if it's latest.
+ /// Returns the release if found, else null .
+ Task GetLatestReleaseAsync(string repo, bool includePrerelease = false);
}
}
diff --git a/src/SMAPI.Web/Framework/ConfigModels/ApiClientsConfig.cs b/src/SMAPI.Web/Framework/ConfigModels/ApiClientsConfig.cs
index 61219414..de6c024a 100644
--- a/src/SMAPI.Web/Framework/ConfigModels/ApiClientsConfig.cs
+++ b/src/SMAPI.Web/Framework/ConfigModels/ApiClientsConfig.cs
@@ -29,8 +29,11 @@ namespace StardewModdingAPI.Web.Framework.ConfigModels
/// The base URL for the GitHub API.
public string GitHubBaseUrl { get; set; }
- /// The URL for a GitHub API latest-release query excluding the , where {0} is the organisation and project name.
- public string GitHubReleaseUrlFormat { get; set; }
+ /// The URL for a GitHub API query for the latest stable release, excluding the , where {0} is the organisation and project name.
+ public string GitHubStableReleaseUrlFormat { get; set; }
+
+ /// The URL for a GitHub API query for the latest release (including prerelease), excluding the , where {0} is the organisation and project name.
+ public string GitHubAnyReleaseUrlFormat { get; set; }
/// The Accept header value expected by the GitHub API.
public string GitHubAcceptHeader { get; set; }
diff --git a/src/SMAPI.Web/Framework/ModRepositories/ChucklefishRepository.cs b/src/SMAPI.Web/Framework/ModRepositories/ChucklefishRepository.cs
index 266055a6..3e5a4272 100644
--- a/src/SMAPI.Web/Framework/ModRepositories/ChucklefishRepository.cs
+++ b/src/SMAPI.Web/Framework/ModRepositories/ChucklefishRepository.cs
@@ -43,7 +43,7 @@ namespace StardewModdingAPI.Web.Framework.ModRepositories
return new ModInfoModel("Found no mod with this ID.");
// create model
- return new ModInfoModel(mod.Name, this.NormaliseVersion(mod.Version), mod.Url);
+ return new ModInfoModel(name: mod.Name, version: this.NormaliseVersion(mod.Version), url: mod.Url);
}
catch (Exception ex)
{
diff --git a/src/SMAPI.Web/Framework/ModRepositories/GitHubRepository.cs b/src/SMAPI.Web/Framework/ModRepositories/GitHubRepository.cs
index 7bad6127..59eb8cd1 100644
--- a/src/SMAPI.Web/Framework/ModRepositories/GitHubRepository.cs
+++ b/src/SMAPI.Web/Framework/ModRepositories/GitHubRepository.cs
@@ -38,10 +38,21 @@ namespace StardewModdingAPI.Web.Framework.ModRepositories
// fetch info
try
{
- GitRelease release = await this.Client.GetLatestReleaseAsync(id);
- return release != null
- ? new ModInfoModel(id, this.NormaliseVersion(release.Tag), $"https://github.com/{id}/releases")
- : new ModInfoModel("Found no mod with this ID.");
+ // get latest release
+ GitRelease latest = await this.Client.GetLatestReleaseAsync(id, includePrerelease: true);
+ GitRelease preview = null;
+ if (latest == null)
+ return new ModInfoModel("Found no mod with this ID.");
+
+ // get latest stable release (if not latest)
+ if (latest.IsPrerelease)
+ {
+ preview = latest;
+ latest = await this.Client.GetLatestReleaseAsync(id, includePrerelease: false);
+ }
+
+ // return data
+ return new ModInfoModel(name: id, version: this.NormaliseVersion(latest?.Tag), previewVersion: this.NormaliseVersion(preview?.Tag), url: $"https://github.com/{id}/releases");
}
catch (Exception ex)
{
diff --git a/src/SMAPI.Web/Framework/ModRepositories/NexusRepository.cs b/src/SMAPI.Web/Framework/ModRepositories/NexusRepository.cs
index e1dc0fcc..6411ad4c 100644
--- a/src/SMAPI.Web/Framework/ModRepositories/NexusRepository.cs
+++ b/src/SMAPI.Web/Framework/ModRepositories/NexusRepository.cs
@@ -43,7 +43,7 @@ namespace StardewModdingAPI.Web.Framework.ModRepositories
return new ModInfoModel("Found no mod with this ID.");
if (mod.Error != null)
return new ModInfoModel(mod.Error);
- return new ModInfoModel(mod.Name, this.NormaliseVersion(mod.Version), mod.Url);
+ return new ModInfoModel(name: mod.Name, version: this.NormaliseVersion(mod.Version), url: mod.Url);
}
catch (Exception ex)
{
diff --git a/src/SMAPI.Web/Startup.cs b/src/SMAPI.Web/Startup.cs
index d7d4d074..47102e5c 100644
--- a/src/SMAPI.Web/Startup.cs
+++ b/src/SMAPI.Web/Startup.cs
@@ -74,7 +74,8 @@ namespace StardewModdingAPI.Web
services.AddSingleton(new GitHubClient(
baseUrl: api.GitHubBaseUrl,
- releaseUrlFormat: api.GitHubReleaseUrlFormat,
+ stableReleaseUrlFormat: api.GitHubStableReleaseUrlFormat,
+ anyReleaseUrlFormat: api.GitHubAnyReleaseUrlFormat,
userAgent: userAgent,
acceptHeader: api.GitHubAcceptHeader,
username: api.GitHubUsername,
diff --git a/src/SMAPI.Web/appsettings.json b/src/SMAPI.Web/appsettings.json
index 3cf72ddb..bfe827fa 100644
--- a/src/SMAPI.Web/appsettings.json
+++ b/src/SMAPI.Web/appsettings.json
@@ -24,7 +24,8 @@
"ChucklefishModPageUrlFormat": "resources/{0}",
"GitHubBaseUrl": "https://api.github.com",
- "GitHubReleaseUrlFormat": "repos/{0}/releases/latest",
+ "GitHubStableReleaseUrlFormat": "repos/{0}/releases/latest",
+ "GitHubAnyReleaseUrlFormat": "repos/{0}/releases?per_page=1",
"GitHubAcceptHeader": "application/vnd.github.v3+json",
"GitHubUsername": null, // see top note
"GitHubPassword": null, // see top note
--
cgit
From ff6df97ae8ca12f45aaba1776472f1dc10234b91 Mon Sep 17 00:00:00 2001
From: Jesse Plamondon-Willard
Date: Thu, 15 Mar 2018 21:26:03 -0400
Subject: fix error handling in update check API (#457)
---
src/SMAPI.Web/Controllers/ModsApiController.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'src/SMAPI.Web')
diff --git a/src/SMAPI.Web/Controllers/ModsApiController.cs b/src/SMAPI.Web/Controllers/ModsApiController.cs
index abae7db7..c99c87fb 100644
--- a/src/SMAPI.Web/Controllers/ModsApiController.cs
+++ b/src/SMAPI.Web/Controllers/ModsApiController.cs
@@ -115,9 +115,9 @@ namespace StardewModdingAPI.Web.Controllers
if (info.Error == null)
{
if (info.Version == null)
- info = new ModInfoModel(info.Name, info.Version, info.Url, "Mod has no version number.");
+ info = new ModInfoModel(name: info.Name, version: info.Version, url: info.Url, error: "Mod has no version number.");
if (!allowInvalidVersions && !Regex.IsMatch(info.Version, this.VersionRegex, RegexOptions.CultureInvariant | RegexOptions.IgnoreCase))
- info = new ModInfoModel(info.Name, info.Version, info.Url, $"Mod has invalid semantic version '{info.Version}'.");
+ info = new ModInfoModel(name: info.Name, version: info.Version, url: info.Url, error: $"Mod has invalid semantic version '{info.Version}'.");
}
// cache & return
--
cgit
From 594d176d39691ff46b2c99fdfaa4299a4ea43616 Mon Sep 17 00:00:00 2001
From: Jesse Plamondon-Willard
Date: Thu, 15 Mar 2018 23:36:16 -0400
Subject: prepare home page for upcoming beta (#457)
---
src/SMAPI.Web/Controllers/IndexController.cs | 53 +++++++++++++++++++++++----
src/SMAPI.Web/ViewModels/IndexModel.cs | 28 +++++---------
src/SMAPI.Web/ViewModels/IndexVersionModel.cs | 41 +++++++++++++++++++++
src/SMAPI.Web/Views/Index/Index.cshtml | 35 ++++++++++++++----
4 files changed, 124 insertions(+), 33 deletions(-)
create mode 100644 src/SMAPI.Web/ViewModels/IndexVersionModel.cs
(limited to 'src/SMAPI.Web')
diff --git a/src/SMAPI.Web/Controllers/IndexController.cs b/src/SMAPI.Web/Controllers/IndexController.cs
index 5d45118f..0464e50a 100644
--- a/src/SMAPI.Web/Controllers/IndexController.cs
+++ b/src/SMAPI.Web/Controllers/IndexController.cs
@@ -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;
/// The cache time for release info.
- private readonly TimeSpan CacheTime = TimeSpan.FromMinutes(5);
+ private readonly TimeSpan CacheTime = TimeSpan.FromSeconds(1);
+
+ /// The GitHub repository name to check for update.
+ private readonly string RepositoryName = "Pathoschild/SMAPI";
/*********
@@ -42,17 +46,24 @@ namespace StardewModdingAPI.Web.Controllers
[HttpGet]
public async Task 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);
+ 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);
- return await this.GitHub.GetLatestReleaseAsync("Pathoschild/SMAPI");
+ 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";
}
+
+ /// Get the latest beta download for a SMAPI release.
+ /// The SMAPI release.
+ 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;
+ }
}
}
diff --git a/src/SMAPI.Web/ViewModels/IndexModel.cs b/src/SMAPI.Web/ViewModels/IndexModel.cs
index 6d3da91e..4268c878 100644
--- a/src/SMAPI.Web/ViewModels/IndexModel.cs
+++ b/src/SMAPI.Web/ViewModels/IndexModel.cs
@@ -6,17 +6,11 @@ namespace StardewModdingAPI.Web.ViewModels
/*********
** Accessors
*********/
- /// The latest SMAPI version.
- public string LatestVersion { get; set; }
+ /// The latest stable SMAPI version.
+ public IndexVersionModel StableVersion { get; set; }
- /// The Markdown description for the release.
- public string Description { get; set; }
-
- /// The main download URL.
- public string DownloadUrl { get; set; }
-
- /// The for-developers download URL.
- public string DevDownloadUrl { get; set; }
+ /// The latest prerelease SMAPI version (if newer than ).
+ public IndexVersionModel BetaVersion { get; set; }
/*********
@@ -26,16 +20,12 @@ namespace StardewModdingAPI.Web.ViewModels
public IndexModel() { }
/// Construct an instance.
- /// The latest SMAPI version.
- /// The Markdown description for the release.
- /// The main download URL.
- /// The for-developers download URL.
- internal IndexModel(string latestVersion, string description, string downloadUrl, string devDownloadUrl)
+ /// The latest stable SMAPI version.
+ /// The latest prerelease SMAPI version (if newer than ).
+ internal IndexModel(IndexVersionModel stableVersion, IndexVersionModel betaVersion)
{
- this.LatestVersion = latestVersion;
- this.Description = description;
- this.DownloadUrl = downloadUrl;
- this.DevDownloadUrl = devDownloadUrl;
+ this.StableVersion = stableVersion;
+ this.BetaVersion = betaVersion;
}
}
}
diff --git a/src/SMAPI.Web/ViewModels/IndexVersionModel.cs b/src/SMAPI.Web/ViewModels/IndexVersionModel.cs
new file mode 100644
index 00000000..4f63b979
--- /dev/null
+++ b/src/SMAPI.Web/ViewModels/IndexVersionModel.cs
@@ -0,0 +1,41 @@
+namespace StardewModdingAPI.Web.ViewModels
+{
+ /// The fields for a SMAPI version.
+ public class IndexVersionModel
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// The release version.
+ public string Version { get; set; }
+
+ /// The Markdown description for the release.
+ public string Description { get; set; }
+
+ /// The main download URL.
+ public string DownloadUrl { get; set; }
+
+ /// The for-developers download URL (not applicable for prerelease versions).
+ public string DevDownloadUrl { get; set; }
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// Construct an instance.
+ public IndexVersionModel() { }
+
+ /// Construct an instance.
+ /// The release number.
+ /// The Markdown description for the release.
+ /// The main download URL.
+ /// The for-developers download URL (not applicable for prerelease versions).
+ internal IndexVersionModel(string version, string description, string downloadUrl, string devDownloadUrl)
+ {
+ this.Version = version;
+ this.Description = description;
+ this.DownloadUrl = downloadUrl;
+ this.DevDownloadUrl = devDownloadUrl;
+ }
+ }
+}
diff --git a/src/SMAPI.Web/Views/Index/Index.cshtml b/src/SMAPI.Web/Views/Index/Index.cshtml
index ad58898e..4efb9f8a 100644
--- a/src/SMAPI.Web/Views/Index/Index.cshtml
+++ b/src/SMAPI.Web/Views/Index/Index.cshtml
@@ -13,7 +13,11 @@
-
Download SMAPI @Model.LatestVersion
+
Download SMAPI @Model.StableVersion.Version
+ @if (Model.BetaVersion != null)
+ {
+
Download SMAPI @Model.BetaVersion.Versionfor Stardew Valley 1.3 beta
+ }
Install guide
FAQs
@@ -25,12 +29,29 @@
Get help on Discord or in the forums
-
What's new in SMAPI @Model.LatestVersion?
-
- @Html.Raw(Markdig.Markdown.ToHtml(Model.Description))
-
+@if (Model.BetaVersion == null)
+{
+
What's new in SMAPI @Model.StableVersion.Version?
+
+ @Html.Raw(Markdig.Markdown.ToHtml(Model.StableVersion.Description))
+
+
See the release notes and mod compatibility list for more info.
+}
+else
+{
+
What's new in...
+
SMAPI @Model.StableVersion.Version?
+
+ @Html.Raw(Markdig.Markdown.ToHtml(Model.StableVersion.Description))
+
+
See the release notes and mod compatibility list for more info.
-
See the release notes and mod compatibility list for more info.
+
SMAPI @Model.BetaVersion.Version?
+
+ @Html.Raw(Markdig.Markdown.ToHtml(Model.BetaVersion.Description))
+
+
See the release notes and mod compatibility list for more info.
+}
Donate to support SMAPI ♥
@@ -62,7 +83,7 @@
For mod creators
--
cgit
From ada351b163d928b5c01787e3ac3ad25ee6fe1ce4 Mon Sep 17 00:00:00 2001
From: Jesse Plamondon-Willard
Date: Fri, 16 Mar 2018 20:28:16 -0400
Subject: reduce cache time for failed update checks to 5 minutes (#454)
---
docs/release-notes.md | 1 +
src/SMAPI.Web/Controllers/ModsApiController.cs | 12 ++++++++----
src/SMAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs | 7 +++++--
src/SMAPI.Web/appsettings.json | 3 ++-
4 files changed, 16 insertions(+), 7 deletions(-)
(limited to 'src/SMAPI.Web')
diff --git a/docs/release-notes.md b/docs/release-notes.md
index 393090f2..9d654133 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -21,6 +21,7 @@
* Fixed rare crash with some combinations of manifest fields and internal mod data.
* Fixed update checks failing for Nexus Mods due to a change in their API.
* Fixed update checks failing for some older mods with non-standard versions.
+ * Fixed failed update checks being cached for an hour (now cached 5 minutes).
* Fixed error when a content pack needs a mod that couldn't be loaded.
* Fixed Linux ["magic number is wrong" errors](https://github.com/mono/mono/issues/6752) by changing default terminal order.
* Updated compatibility list and added update checks for more mods.
diff --git a/src/SMAPI.Web/Controllers/ModsApiController.cs b/src/SMAPI.Web/Controllers/ModsApiController.cs
index c99c87fb..24517263 100644
--- a/src/SMAPI.Web/Controllers/ModsApiController.cs
+++ b/src/SMAPI.Web/Controllers/ModsApiController.cs
@@ -29,8 +29,11 @@ namespace StardewModdingAPI.Web.Controllers
/// The cache in which to store mod metadata.
private readonly IMemoryCache Cache;
- /// The number of minutes update checks should be cached before refetching them.
- private readonly int CacheMinutes;
+ /// The number of minutes successful update checks should be cached before refetching them.
+ private readonly int SuccessCacheMinutes;
+
+ /// The number of minutes failed update checks should be cached before refetching them.
+ private readonly int ErrorCacheMinutes;
/// A regex which matches SMAPI-style semantic version.
private readonly string VersionRegex;
@@ -50,7 +53,8 @@ namespace StardewModdingAPI.Web.Controllers
ModUpdateCheckConfig config = configProvider.Value;
this.Cache = cache;
- this.CacheMinutes = config.CacheMinutes;
+ this.SuccessCacheMinutes = config.SuccessCacheMinutes;
+ this.ErrorCacheMinutes = config.ErrorCacheMinutes;
this.VersionRegex = config.SemanticVersionRegex;
this.Repositories =
new IModRepository[]
@@ -121,7 +125,7 @@ namespace StardewModdingAPI.Web.Controllers
}
// cache & return
- entry.AbsoluteExpiration = DateTimeOffset.UtcNow.AddMinutes(this.CacheMinutes);
+ entry.AbsoluteExpiration = DateTimeOffset.UtcNow.AddMinutes(info.Error == null ? this.SuccessCacheMinutes : this.ErrorCacheMinutes);
return info;
});
}
diff --git a/src/SMAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs b/src/SMAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs
index 58c3a100..fc3b7dc2 100644
--- a/src/SMAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs
+++ b/src/SMAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs
@@ -6,8 +6,11 @@ namespace StardewModdingAPI.Web.Framework.ConfigModels
/*********
** Accessors
*********/
- /// The number of minutes update checks should be cached before refetching them.
- public int CacheMinutes { get; set; }
+ /// The number of minutes successful update checks should be cached before refetching them.
+ public int SuccessCacheMinutes { get; set; }
+
+ /// The number of minutes failed update checks should be cached before refetching them.
+ public int ErrorCacheMinutes { get; set; }
/// A regex which matches SMAPI-style semantic version.
/// Derived from SMAPI's SemanticVersion implementation.
diff --git a/src/SMAPI.Web/appsettings.json b/src/SMAPI.Web/appsettings.json
index bfe827fa..03ca31ed 100644
--- a/src/SMAPI.Web/appsettings.json
+++ b/src/SMAPI.Web/appsettings.json
@@ -40,7 +40,8 @@
},
"ModUpdateCheck": {
- "CacheMinutes": 60,
+ "SuccessCacheMinutes": 60,
+ "ErrorCacheMinutes": 5,
"SemanticVersionRegex": "^(?>(?0|[1-9]\\d*))\\.(?>(?0|[1-9]\\d*))(?>(?:\\.(?0|[1-9]\\d*))?)(?:-(?(?>[a-z0-9]+[\\-\\.]?)+))?$",
"ChucklefishKey": "Chucklefish",
--
cgit
From 91561eedc7c8247a6179e0158eb9f9affdf65012 Mon Sep 17 00:00:00 2001
From: Jesse Plamondon-Willard
Date: Fri, 23 Mar 2018 01:21:50 -0400
Subject: fix log parser errors when log text contains {{tokens}}
---
docs/release-notes.md | 4 ++++
src/SMAPI.Web/Views/LogParser/Index.cshtml | 36 +++++++++++++++---------------
2 files changed, 22 insertions(+), 18 deletions(-)
(limited to 'src/SMAPI.Web')
diff --git a/docs/release-notes.md b/docs/release-notes.md
index 9d654133..059105c3 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -15,6 +15,10 @@
* Added support for beta releases on the home page.
-->
+## 2.5.4
+* For the [log parser][]:
+ * Fixed error when log text contains certain tokens.
+
## 2.5.3
* For players:
* Simplified and improved skipped-mod messages.
diff --git a/src/SMAPI.Web/Views/LogParser/Index.cshtml b/src/SMAPI.Web/Views/LogParser/Index.cshtml
index d2d8004e..9c21c8c0 100644
--- a/src/SMAPI.Web/Views/LogParser/Index.cshtml
+++ b/src/SMAPI.Web/Views/LogParser/Index.cshtml
@@ -54,23 +54,23 @@
Game info:
SMAPI version:
- @Model.ParsedLog.ApiVersion
+ @Model.ParsedLog.ApiVersion
Game version:
- @Model.ParsedLog.GameVersion
+ @Model.ParsedLog.GameVersion
Platform:
- @Model.ParsedLog.OperatingSystem
+ @Model.ParsedLog.OperatingSystem
Mods path:
- @Model.ParsedLog.ModPath
+ @Model.ParsedLog.ModPath
Log started:
- @Model.ParsedLog.Timestamp.UtcDateTime.ToString("yyyy-MM-dd HH:mm") UTC ({{localTimeStarted}} your time)
+ @Model.ParsedLog.Timestamp.UtcDateTime.ToString("yyyy-MM-dd HH:mm") UTC ({{localTimeStarted}} your time)
@@ -85,7 +85,7 @@
{
-
+
@mod.Name
@if (contentPacks != null && contentPacks.TryGetValue(mod.Name, out LogModInfo[] contentPackList))
{
@@ -97,19 +97,19 @@
}
- @mod.Version
- @mod.Author
+ @mod.Version
+ @mod.Author
@if (mod.Errors == 0)
{
- no errors
+ no errors
}
else if (mod.Errors == 1)
{
- @mod.Errors error
+ @mod.Errors error
}
else
{
- @mod.Errors errors
+ @mod.Errors errors
}
}
@@ -130,16 +130,16 @@
string levelStr = message.Level.ToString().ToLower();
- @message.Time
- @message.Level.ToString().ToUpper()
- @message.Mod
- @message.Text
+ @message.Time
+ @message.Level.ToString().ToUpper()
+ @message.Mod
+ @message.Text
if (message.Repeated > 0)
{
- repeats [@message.Repeated] times.
+ repeats [@message.Repeated] times.
}
}
@@ -151,11 +151,11 @@ else if (Model.ParsedLog?.IsValid == false)
Parsed log
We couldn't parse that file, but you can still share the link.
-
Error details: @Model.ParsedLog.Error
+
Error details: @Model.ParsedLog.Error
Raw log
- @Model.ParsedLog.RawText
+ @Model.ParsedLog.RawText
}
--
cgit
From 4d668eb7022819391a6c1834e1351c9b4fc52104 Mon Sep 17 00:00:00 2001
From: Jesse Plamondon-Willard
Date: Sun, 25 Mar 2018 12:17:58 -0400
Subject: update API packages
---
src/SMAPI.Web/StardewModdingAPI.Web.csproj | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
(limited to 'src/SMAPI.Web')
diff --git a/src/SMAPI.Web/StardewModdingAPI.Web.csproj b/src/SMAPI.Web/StardewModdingAPI.Web.csproj
index 19198503..e2eee8a8 100644
--- a/src/SMAPI.Web/StardewModdingAPI.Web.csproj
+++ b/src/SMAPI.Web/StardewModdingAPI.Web.csproj
@@ -10,13 +10,13 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
--
cgit
From 56288e1d0ec072d35040b7954fc7c0f8b086663e Mon Sep 17 00:00:00 2001
From: Jesse Plamondon-Willard
Date: Mon, 26 Mar 2018 09:22:45 -0400
Subject: fix log parser timestamp not rendered
---
src/SMAPI.Web/Views/LogParser/Index.cshtml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'src/SMAPI.Web')
diff --git a/src/SMAPI.Web/Views/LogParser/Index.cshtml b/src/SMAPI.Web/Views/LogParser/Index.cshtml
index 9c21c8c0..7213e286 100644
--- a/src/SMAPI.Web/Views/LogParser/Index.cshtml
+++ b/src/SMAPI.Web/Views/LogParser/Index.cshtml
@@ -70,7 +70,7 @@
Log started:
- @Model.ParsedLog.Timestamp.UtcDateTime.ToString("yyyy-MM-dd HH:mm") UTC ({{localTimeStarted}} your time)
+ @Model.ParsedLog.Timestamp.UtcDateTime.ToString("yyyy-MM-dd HH:mm") UTC ({{localTimeStarted}} your time)
--
cgit