From aee42562698ad3e84f781d51e8aa5017a1a589bc Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 6 Jun 2018 00:02:30 -0400 Subject: remove obsolete Nexus API client --- src/SMAPI.Web/Framework/ConfigModels/ApiClientsConfig.cs | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/SMAPI.Web/Framework/ConfigModels') diff --git a/src/SMAPI.Web/Framework/ConfigModels/ApiClientsConfig.cs b/src/SMAPI.Web/Framework/ConfigModels/ApiClientsConfig.cs index de6c024a..9452fdf9 100644 --- a/src/SMAPI.Web/Framework/ConfigModels/ApiClientsConfig.cs +++ b/src/SMAPI.Web/Framework/ConfigModels/ApiClientsConfig.cs @@ -47,9 +47,6 @@ namespace StardewModdingAPI.Web.Framework.ConfigModels /**** ** Nexus Mods ****/ - /// The user agent for the Nexus Mods API client. - public string NexusUserAgent { get; set; } - /// The base URL for the Nexus Mods API. public string NexusBaseUrl { get; set; } @@ -62,9 +59,6 @@ namespace StardewModdingAPI.Web.Framework.ConfigModels /// The base URL for the Pastebin API. public string PastebinBaseUrl { get; set; } - /// The user agent for the Pastebin API client, where {0} is the SMAPI version. - public string PastebinUserAgent { get; set; } - /// The user key used to authenticate with the Pastebin API. public string PastebinUserKey { get; set; } -- cgit From 53a6833ab22fb41e909ed8ef50aa9262735818d9 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 6 Jun 2018 00:16:39 -0400 Subject: return file versions from Nexus in web API (#532) --- docs/release-notes.md | 1 + src/SMAPI.Web/Framework/Clients/Nexus/NexusMod.cs | 4 ++ .../Clients/Nexus/NexusWebScrapeClient.cs | 44 ++++++++++++++++++++-- .../Framework/ConfigModels/ApiClientsConfig.cs | 5 ++- .../Framework/ModRepositories/NexusRepository.cs | 2 +- src/SMAPI.Web/Startup.cs | 3 +- src/SMAPI.Web/appsettings.json | 1 + .../Framework/Clients/WebApi/ModInfoModel.cs | 4 +- 8 files changed, 55 insertions(+), 9 deletions(-) (limited to 'src/SMAPI.Web/Framework/ConfigModels') diff --git a/docs/release-notes.md b/docs/release-notes.md index 39b431cf..11a2a04c 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -59,6 +59,7 @@ * For SMAPI developers: * Added more consistent crossplatform handling using a new `EnvironmentUtility`, including MacOS detection. * Added beta update channel to SMAPI, the web API, and home page. + * Added latest mod file version (including optional files) to Nexus API results. * Added more stylish pufferchick on the home page. * Split mod DB out of `StardewModdingAPI.config.json` into its own file. * Rewrote input suppression using new SDV 1.3 APIs. diff --git a/src/SMAPI.Web/Framework/Clients/Nexus/NexusMod.cs b/src/SMAPI.Web/Framework/Clients/Nexus/NexusMod.cs index cd52c72b..4ecf2f76 100644 --- a/src/SMAPI.Web/Framework/Clients/Nexus/NexusMod.cs +++ b/src/SMAPI.Web/Framework/Clients/Nexus/NexusMod.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using StardewModdingAPI.Toolkit; namespace StardewModdingAPI.Web.Framework.Clients.Nexus { @@ -14,6 +15,9 @@ namespace StardewModdingAPI.Web.Framework.Clients.Nexus /// The mod's semantic version number. public string Version { get; set; } + /// The latest file version. + public ISemanticVersion LatestFileVersion { get; set; } + /// The mod's web URL. [JsonProperty("mod_page_uri")] public string Url { get; set; } diff --git a/src/SMAPI.Web/Framework/Clients/Nexus/NexusWebScrapeClient.cs b/src/SMAPI.Web/Framework/Clients/Nexus/NexusWebScrapeClient.cs index d0597965..df5a437d 100644 --- a/src/SMAPI.Web/Framework/Clients/Nexus/NexusWebScrapeClient.cs +++ b/src/SMAPI.Web/Framework/Clients/Nexus/NexusWebScrapeClient.cs @@ -1,8 +1,11 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Net; using System.Threading.Tasks; using HtmlAgilityPack; using Pathoschild.Http.Client; +using StardewModdingAPI.Toolkit; namespace StardewModdingAPI.Web.Framework.Clients.Nexus { @@ -12,9 +15,12 @@ namespace StardewModdingAPI.Web.Framework.Clients.Nexus /********* ** Properties *********/ - /// The URL for a Nexus web page excluding the base URL, where {0} is the mod ID. + /// The URL for a Nexus mod page for the user, excluding the base URL, where {0} is the mod ID. private readonly string ModUrlFormat; + /// The URL for a Nexus mod page to scrape for versions, excluding the base URL, where {0} is the mod ID. + public string ModScrapeUrlFormat { get; set; } + /// The underlying HTTP client. private readonly IClient Client; @@ -25,10 +31,12 @@ namespace StardewModdingAPI.Web.Framework.Clients.Nexus /// Construct an instance. /// The user agent for the Nexus Mods API client. /// The base URL for the Nexus Mods site. - /// The URL for a Nexus Mods web page excluding the , where {0} is the mod ID. - public NexusWebScrapeClient(string userAgent, string baseUrl, string modUrlFormat) + /// The URL for a Nexus Mods mod page for the user, excluding the , where {0} is the mod ID. + /// The URL for a Nexus mod page to scrape for versions, excluding the base URL, where {0} is the mod ID. + public NexusWebScrapeClient(string userAgent, string baseUrl, string modUrlFormat, string modScrapeUrlFormat) { this.ModUrlFormat = modUrlFormat; + this.ModScrapeUrlFormat = modScrapeUrlFormat; this.Client = new FluentClient(baseUrl).SetUserAgent(userAgent); } @@ -42,7 +50,7 @@ namespace StardewModdingAPI.Web.Framework.Clients.Nexus try { html = await this.Client - .GetAsync(string.Format(this.ModUrlFormat, id)) + .GetAsync(string.Format(this.ModScrapeUrlFormat, id)) .AsString(); } catch (ApiException ex) when (ex.Status == HttpStatusCode.NotFound) @@ -76,10 +84,38 @@ namespace StardewModdingAPI.Web.Framework.Clients.Nexus string name = doc.DocumentNode.SelectSingleNode("//h1")?.InnerText.Trim(); string version = doc.DocumentNode.SelectSingleNode("//ul[contains(@class, 'stats')]//li[@class='stat-version']//div[@class='stat']")?.InnerText.Trim(); + // extract file versions + List rawVersions = new List(); + foreach (var fileSection in doc.DocumentNode.SelectNodes("//div[contains(@class, 'files-tabs')]")) + { + string sectionName = fileSection.Descendants("h2").First().InnerText; + if (sectionName != "Main files" && sectionName != "Optional files") + continue; + + rawVersions.AddRange( + from statBox in fileSection.Descendants().Where(p => p.HasClass("stat-version")) + from versionStat in statBox.Descendants().Where(p => p.HasClass("stat")) + select versionStat.InnerText.Trim() + ); + } + + // choose latest file version + ISemanticVersion latestFileVersion = null; + foreach (string rawVersion in rawVersions) + { + if (!SemanticVersion.TryParse(rawVersion, out ISemanticVersion cur)) + continue; + + if (latestFileVersion == null || cur.IsNewerThan(latestFileVersion)) + latestFileVersion = cur; + } + + // yield info return new NexusMod { Name = name, Version = version, + LatestFileVersion = latestFileVersion, Url = url }; } diff --git a/src/SMAPI.Web/Framework/ConfigModels/ApiClientsConfig.cs b/src/SMAPI.Web/Framework/ConfigModels/ApiClientsConfig.cs index 9452fdf9..ae8f18d2 100644 --- a/src/SMAPI.Web/Framework/ConfigModels/ApiClientsConfig.cs +++ b/src/SMAPI.Web/Framework/ConfigModels/ApiClientsConfig.cs @@ -50,9 +50,12 @@ namespace StardewModdingAPI.Web.Framework.ConfigModels /// The base URL for the Nexus Mods API. public string NexusBaseUrl { get; set; } - /// The URL for a Nexus Mods API query excluding the , where {0} is the mod ID. + /// The URL for a Nexus mod page for the user, excluding the , where {0} is the mod ID. public string NexusModUrlFormat { get; set; } + /// The URL for a Nexus mod page to scrape for versions, excluding the , where {0} is the mod ID. + public string NexusModScrapeUrlFormat { get; set; } + /**** ** Pastebin ****/ diff --git a/src/SMAPI.Web/Framework/ModRepositories/NexusRepository.cs b/src/SMAPI.Web/Framework/ModRepositories/NexusRepository.cs index 6cac6b8f..4afcda10 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(name: mod.Name, version: this.NormaliseVersion(mod.Version), url: mod.Url); + return new ModInfoModel(name: mod.Name, version: this.NormaliseVersion(mod.Version), previewVersion: mod.LatestFileVersion?.ToString(), url: mod.Url); } catch (Exception ex) { diff --git a/src/SMAPI.Web/Startup.cs b/src/SMAPI.Web/Startup.cs index 2019d6db..58584348 100644 --- a/src/SMAPI.Web/Startup.cs +++ b/src/SMAPI.Web/Startup.cs @@ -85,7 +85,8 @@ namespace StardewModdingAPI.Web services.AddSingleton(new NexusWebScrapeClient( userAgent: userAgent, baseUrl: api.NexusBaseUrl, - modUrlFormat: api.NexusModUrlFormat + modUrlFormat: api.NexusModUrlFormat, + modScrapeUrlFormat: api.NexusModScrapeUrlFormat )); services.AddSingleton(new PastebinClient( diff --git a/src/SMAPI.Web/appsettings.json b/src/SMAPI.Web/appsettings.json index fda77183..2f87dbe5 100644 --- a/src/SMAPI.Web/appsettings.json +++ b/src/SMAPI.Web/appsettings.json @@ -32,6 +32,7 @@ "NexusBaseUrl": "https://www.nexusmods.com/stardewvalley/", "NexusModUrlFormat": "mods/{0}", + "NexusModScrapeUrlFormat": "mods/{0}?tab=files", "PastebinBaseUrl": "https://pastebin.com/", "PastebinUserKey": null, // see top note diff --git a/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModInfoModel.cs b/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModInfoModel.cs index e1a204c6..c8e296f0 100644 --- a/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModInfoModel.cs +++ b/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModInfoModel.cs @@ -9,10 +9,10 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.WebApi /// The mod name. public string Name { get; set; } - /// The semantic version for the mod's latest release. + /// The mod's latest release number. public string Version { get; set; } - /// The semantic version for the mod's latest preview release, if available and different from . + /// The mod's latest optional release, if newer than . public string PreviewVersion { get; set; } /// The mod's web URL. -- cgit From c9fedebaf3231a2d5a00a95ff1ffd3ac5dac4ae2 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 28 Jun 2018 22:30:34 -0400 Subject: add support for unofficial version in update checks (#532) --- docs/release-notes.md | 1 + src/SMAPI.Web/Controllers/ModsApiController.cs | 47 +++++++++++++++++++++- .../Framework/ConfigModels/ModUpdateCheckConfig.cs | 3 ++ src/SMAPI.Web/appsettings.json | 4 +- src/SMAPI/Program.cs | 3 ++ .../Framework/Clients/WebApi/ModEntryModel.cs | 3 ++ 6 files changed, 58 insertions(+), 3 deletions(-) (limited to 'src/SMAPI.Web/Framework/ConfigModels') diff --git a/docs/release-notes.md b/docs/release-notes.md index a8f6d851..14cf78a2 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -10,6 +10,7 @@ * Improved update checks: * added beta update channel; * added support for optional files on Nexus; + * added support for unofficial updates from the wiki (only if the installed version is incompatible); * added console warning for mods which don't have update checks configured; * fixed mod update checks failing if a mod only has prerelease versions on GitHub; * fixed Nexus mod update alerts not showing HTTPS links. diff --git a/src/SMAPI.Web/Controllers/ModsApiController.cs b/src/SMAPI.Web/Controllers/ModsApiController.cs index c4f1023b..b9af17dc 100644 --- a/src/SMAPI.Web/Controllers/ModsApiController.cs +++ b/src/SMAPI.Web/Controllers/ModsApiController.cs @@ -10,6 +10,7 @@ using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Options; using StardewModdingAPI.Toolkit; using StardewModdingAPI.Toolkit.Framework.Clients.WebApi; +using StardewModdingAPI.Toolkit.Framework.Clients.Wiki; using StardewModdingAPI.Toolkit.Framework.ModData; using StardewModdingAPI.Web.Framework.Clients.Chucklefish; using StardewModdingAPI.Web.Framework.Clients.GitHub; @@ -45,6 +46,9 @@ namespace StardewModdingAPI.Web.Controllers /// The internal mod metadata list. private readonly ModDatabase ModDatabase; + /// The web URL for the wiki compatibility list. + private readonly string WikiCompatibilityPageUrl; + /********* ** Public methods @@ -60,6 +64,7 @@ namespace StardewModdingAPI.Web.Controllers { this.ModDatabase = new ModToolkit().GetModDatabase(Path.Combine(environment.WebRootPath, "StardewModdingAPI.metadata.json")); ModUpdateCheckConfig config = configProvider.Value; + this.WikiCompatibilityPageUrl = config.WikiCompatibilityPageUrl; this.Cache = cache; this.SuccessCacheMinutes = config.SuccessCacheMinutes; @@ -84,6 +89,9 @@ namespace StardewModdingAPI.Web.Controllers ISemanticVersion apiVersion = this.GetApiVersion(); ModSearchEntryModel[] searchMods = this.GetSearchMods(model, apiVersion).ToArray(); + // fetch wiki data + WikiCompatibilityEntry[] wikiData = await this.GetWikiDataAsync(); + // perform checks IDictionary mods = new Dictionary(StringComparer.CurrentCultureIgnoreCase); foreach (ModSearchEntryModel mod in searchMods) @@ -123,7 +131,7 @@ namespace StardewModdingAPI.Web.Controllers continue; } - if (result.Main == null || result.Main.Version.IsOlderThan(version)) + if (this.IsNewer(version, result.Main?.Version)) { result.Name = data.Name; result.Main = new ModEntryVersionModel(version, data.Url); @@ -139,7 +147,7 @@ namespace StardewModdingAPI.Web.Controllers continue; } - if (result.Optional == null || result.Optional.Version.IsOlderThan(version)) + if (this.IsNewer(version, result.Optional?.Version)) { result.Name = result.Name ?? data.Name; result.Optional = new ModEntryVersionModel(version, data.Url); @@ -147,6 +155,13 @@ namespace StardewModdingAPI.Web.Controllers } } + // get unofficial version + { + WikiCompatibilityEntry wikiEntry = wikiData.FirstOrDefault(entry => entry.ID.Contains(result.ID.Trim(), StringComparer.InvariantCultureIgnoreCase)); + if (wikiEntry?.UnofficialVersion != null && this.IsNewer(wikiEntry.UnofficialVersion, result.Main?.Version) && this.IsNewer(wikiEntry.UnofficialVersion, result.Optional?.Version)) + result.Unofficial = new ModEntryVersionModel(wikiEntry.UnofficialVersion, this.WikiCompatibilityPageUrl); + } + // fallback to preview if latest is invalid if (result.Main == null && result.Optional != null) { @@ -199,6 +214,14 @@ namespace StardewModdingAPI.Web.Controllers return true; } + /// Get whether a version is newer than an version. + /// The current version. + /// The other version. + private bool IsNewer(ISemanticVersion current, ISemanticVersion other) + { + return current != null && (other == null || other.IsOlderThan(current)); + } + /// Get the mods for which the API should return data. /// The search model. /// The requested API version. @@ -222,6 +245,26 @@ namespace StardewModdingAPI.Web.Controllers } } + /// Get mod data from the wiki compatibility list. + private async Task GetWikiDataAsync() + { + ModToolkit toolkit = new ModToolkit(); + return await this.Cache.GetOrCreateAsync($"_wiki", async entry => + { + try + { + WikiCompatibilityEntry[] entries = await toolkit.GetWikiCompatibilityListAsync(); + entry.AbsoluteExpiration = DateTimeOffset.UtcNow.AddMinutes(this.SuccessCacheMinutes); + return entries; + } + catch + { + entry.AbsoluteExpiration = DateTimeOffset.UtcNow.AddMinutes(this.ErrorCacheMinutes); + return new WikiCompatibilityEntry[0]; + } + }); + } + /// Get the mod info for an update key. /// The namespaced update key. private async Task GetInfoForUpdateKeyAsync(string updateKey) diff --git a/src/SMAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs b/src/SMAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs index fc3b7dc2..ce4f3cb5 100644 --- a/src/SMAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs +++ b/src/SMAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs @@ -24,5 +24,8 @@ namespace StardewModdingAPI.Web.Framework.ConfigModels /// The repository key for Nexus Mods. public string NexusKey { get; set; } + + /// The web URL for the wiki compatibility list. + public string WikiCompatibilityPageUrl { get; set; } } } diff --git a/src/SMAPI.Web/appsettings.json b/src/SMAPI.Web/appsettings.json index 2f87dbe5..837ba536 100644 --- a/src/SMAPI.Web/appsettings.json +++ b/src/SMAPI.Web/appsettings.json @@ -46,6 +46,8 @@ "ChucklefishKey": "Chucklefish", "GitHubKey": "GitHub", - "NexusKey": "Nexus" + "NexusKey": "Nexus", + + "WikiCompatibilityPageUrl": "https://smapi.io/compat" } } diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs index a1180474..d899e512 100644 --- a/src/SMAPI/Program.cs +++ b/src/SMAPI/Program.cs @@ -675,12 +675,15 @@ namespace StardewModdingAPI ISemanticVersion localVersion = mod.DataRecord?.GetLocalVersionForUpdateChecks(mod.Manifest.Version) ?? mod.Manifest.Version; ISemanticVersion latestVersion = mod.DataRecord?.GetRemoteVersionForUpdateChecks(result.Main?.Version) ?? result.Main?.Version; ISemanticVersion optionalVersion = mod.DataRecord?.GetRemoteVersionForUpdateChecks(result.Optional?.Version) ?? result.Optional?.Version; + ISemanticVersion unofficialVersion = result.Unofficial?.Version; // show update alerts if (this.IsValidUpdate(localVersion, latestVersion, useBetaChannel: true)) updates.Add(Tuple.Create(mod, latestVersion, result.Main?.Url)); else if (this.IsValidUpdate(localVersion, optionalVersion, useBetaChannel: localVersion.IsPrerelease())) updates.Add(Tuple.Create(mod, optionalVersion, result.Optional?.Url)); + else if (this.IsValidUpdate(localVersion, unofficialVersion, useBetaChannel: mod.Status == ModMetadataStatus.Failed)) + updates.Add(Tuple.Create(mod, unofficialVersion, result.Unofficial?.Url)); } // show update errors diff --git a/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModEntryModel.cs b/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModEntryModel.cs index 581a524c..adfdfef9 100644 --- a/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModEntryModel.cs +++ b/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModEntryModel.cs @@ -20,6 +20,9 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.WebApi /// The latest optional version, if newer than . public ModEntryVersionModel Optional { get; set; } + /// The latest unofficial version, if newer than and . + public ModEntryVersionModel Unofficial { get; set; } + /// The errors that occurred while fetching update data. public string[] Errors { get; set; } = new string[0]; -- cgit From 84d52b1735204550c6369270c03f61944c2c88bd Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 29 Jul 2018 12:43:04 -0400 Subject: make beta version on smapi.io optional (#569) --- src/SMAPI.Web/Controllers/IndexController.cs | 11 +++++++++-- src/SMAPI.Web/Controllers/LogParserController.cs | 10 +++++----- src/SMAPI.Web/Framework/ConfigModels/ContextConfig.cs | 15 --------------- src/SMAPI.Web/Framework/ConfigModels/SiteConfig.cs | 18 ++++++++++++++++++ src/SMAPI.Web/Startup.cs | 2 +- src/SMAPI.Web/Views/Shared/_Layout.cshtml | 6 +++--- src/SMAPI.Web/appsettings.Development.json | 7 +++++-- src/SMAPI.Web/appsettings.json | 9 ++++++--- 8 files changed, 47 insertions(+), 31 deletions(-) delete mode 100644 src/SMAPI.Web/Framework/ConfigModels/ContextConfig.cs create mode 100644 src/SMAPI.Web/Framework/ConfigModels/SiteConfig.cs (limited to 'src/SMAPI.Web/Framework/ConfigModels') diff --git a/src/SMAPI.Web/Controllers/IndexController.cs b/src/SMAPI.Web/Controllers/IndexController.cs index 09bad112..8c4a0332 100644 --- a/src/SMAPI.Web/Controllers/IndexController.cs +++ b/src/SMAPI.Web/Controllers/IndexController.cs @@ -6,8 +6,10 @@ using System.Threading.Tasks; using HtmlAgilityPack; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Caching.Memory; +using Microsoft.Extensions.Options; using StardewModdingAPI.Toolkit; using StardewModdingAPI.Web.Framework.Clients.GitHub; +using StardewModdingAPI.Web.Framework.ConfigModels; using StardewModdingAPI.Web.ViewModels; namespace StardewModdingAPI.Web.Controllers @@ -20,6 +22,9 @@ namespace StardewModdingAPI.Web.Controllers /********* ** Properties *********/ + /// The site config settings. + private readonly SiteConfig SiteConfig; + /// The cache in which to store release data. private readonly IMemoryCache Cache; @@ -39,10 +44,12 @@ namespace StardewModdingAPI.Web.Controllers /// Construct an instance. /// The cache in which to store release data. /// The GitHub API client. - public IndexController(IMemoryCache cache, IGitHubClient github) + /// The context config settings. + public IndexController(IMemoryCache cache, IGitHubClient github, IOptions siteConfig) { this.Cache = cache; this.GitHub = github; + this.SiteConfig = siteConfig.Value; } /// Display the index page. @@ -60,7 +67,7 @@ namespace StardewModdingAPI.Web.Controllers IndexVersionModel stableVersionModel = stableVersion != null ? new IndexVersionModel(stableVersion.Version.ToString(), stableVersion.Release.Body, stableVersion.Asset.DownloadUrl, stableVersionForDevs?.Asset.DownloadUrl) : new IndexVersionModel("unknown", "", "https://github.com/Pathoschild/SMAPI/releases", null); // just in case something goes wrong) - IndexVersionModel betaVersionModel = betaVersion != null + IndexVersionModel betaVersionModel = betaVersion != null && this.SiteConfig.EnableSmapiBeta ? new IndexVersionModel(betaVersion.Version.ToString(), betaVersion.Release.Body, betaVersion.Asset.DownloadUrl, betaVersionForDevs?.Asset.DownloadUrl) : null; diff --git a/src/SMAPI.Web/Controllers/LogParserController.cs b/src/SMAPI.Web/Controllers/LogParserController.cs index 354bdb06..17f8d3aa 100644 --- a/src/SMAPI.Web/Controllers/LogParserController.cs +++ b/src/SMAPI.Web/Controllers/LogParserController.cs @@ -21,8 +21,8 @@ namespace StardewModdingAPI.Web.Controllers /********* ** Properties *********/ - /// The log parser config settings. - private readonly ContextConfig Config; + /// The site config settings. + private readonly SiteConfig Config; /// The underlying Pastebin client. private readonly IPastebinClient Pastebin; @@ -39,11 +39,11 @@ namespace StardewModdingAPI.Web.Controllers ** Constructor ***/ /// Construct an instance. - /// The context config settings. + /// The context config settings. /// The Pastebin API client. - public LogParserController(IOptions contextProvider, IPastebinClient pastebin) + public LogParserController(IOptions siteConfig, IPastebinClient pastebin) { - this.Config = contextProvider.Value; + this.Config = siteConfig.Value; this.Pastebin = pastebin; } diff --git a/src/SMAPI.Web/Framework/ConfigModels/ContextConfig.cs b/src/SMAPI.Web/Framework/ConfigModels/ContextConfig.cs deleted file mode 100644 index 117462f4..00000000 --- a/src/SMAPI.Web/Framework/ConfigModels/ContextConfig.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace StardewModdingAPI.Web.Framework.ConfigModels -{ - /// The config settings for the app context. - public class ContextConfig // must be public to pass into views - { - /********* - ** Accessors - *********/ - /// The root URL for the app. - public string RootUrl { get; set; } - - /// The root URL for the log parser. - public string LogParserUrl { get; set; } - } -} diff --git a/src/SMAPI.Web/Framework/ConfigModels/SiteConfig.cs b/src/SMAPI.Web/Framework/ConfigModels/SiteConfig.cs new file mode 100644 index 00000000..3d428015 --- /dev/null +++ b/src/SMAPI.Web/Framework/ConfigModels/SiteConfig.cs @@ -0,0 +1,18 @@ +namespace StardewModdingAPI.Web.Framework.ConfigModels +{ + /// The site config settings. + public class SiteConfig // must be public to pass into views + { + /********* + ** Accessors + *********/ + /// The root URL for the app. + public string RootUrl { get; set; } + + /// The root URL for the log parser. + public string LogParserUrl { get; set; } + + /// Whether to show SMAPI beta versions on the main page, if any. + public bool EnableSmapiBeta { get; set; } + } +} diff --git a/src/SMAPI.Web/Startup.cs b/src/SMAPI.Web/Startup.cs index ced6e1c7..bf3ec9a1 100644 --- a/src/SMAPI.Web/Startup.cs +++ b/src/SMAPI.Web/Startup.cs @@ -50,7 +50,7 @@ namespace StardewModdingAPI.Web // init configuration services .Configure(this.Configuration.GetSection("ModUpdateCheck")) - .Configure(this.Configuration.GetSection("Context")) + .Configure(this.Configuration.GetSection("Site")) .Configure(options => options.ConstraintMap.Add("semanticVersion", typeof(VersionConstraint))) .AddMemoryCache() .AddMvc() diff --git a/src/SMAPI.Web/Views/Shared/_Layout.cshtml b/src/SMAPI.Web/Views/Shared/_Layout.cshtml index d435e760..29da9100 100644 --- a/src/SMAPI.Web/Views/Shared/_Layout.cshtml +++ b/src/SMAPI.Web/Views/Shared/_Layout.cshtml @@ -1,6 +1,6 @@ @using Microsoft.Extensions.Options @using StardewModdingAPI.Web.Framework.ConfigModels -@inject IOptions ContextConfig +@inject IOptions SiteConfig @@ -15,8 +15,8 @@ diff --git a/src/SMAPI.Web/appsettings.Development.json b/src/SMAPI.Web/appsettings.Development.json index 495af120..67bb7748 100644 --- a/src/SMAPI.Web/appsettings.Development.json +++ b/src/SMAPI.Web/appsettings.Development.json @@ -16,10 +16,13 @@ "Microsoft": "Information" } }, - "Context": { + + "Site": { "RootUrl": "http://localhost:59482/", - "LogParserUrl": "http://localhost:59482/log/" + "LogParserUrl": "http://localhost:59482/log/", + "EnableSmapiBeta": false }, + "ApiClients": { "GitHubUsername": null, "GitHubPassword": null, diff --git a/src/SMAPI.Web/appsettings.json b/src/SMAPI.Web/appsettings.json index 837ba536..9e3270ae 100644 --- a/src/SMAPI.Web/appsettings.json +++ b/src/SMAPI.Web/appsettings.json @@ -13,10 +13,13 @@ "Default": "Warning" } }, - "Context": { - "RootUrl": null, // see top note - "LogParserUrl": null // see top note + + "Site": { + "RootUrl": null, // see top note + "LogParserUrl": null, // see top note + "EnableSmapiBeta": null // see top note }, + "ApiClients": { "UserAgent": "SMAPI/{0} (+https://smapi.io)", -- cgit