From 3ca6fb562417748c87567d6bb6915d56b2c1b57c Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 27 Nov 2021 23:59:13 -0500 Subject: automatically include beta versions on Nexus for SMAPI update checks --- src/SMAPI.Web/Controllers/ModsApiController.cs | 7 +++++++ .../Framework/ConfigModels/ModUpdateCheckConfig.cs | 3 +++ src/SMAPI.Web/Framework/ConfigModels/SmapiInfoConfig.cs | 15 +++++++++++++++ src/SMAPI.Web/appsettings.json | 7 ++++++- 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/SMAPI.Web/Framework/ConfigModels/SmapiInfoConfig.cs (limited to 'src/SMAPI.Web') diff --git a/src/SMAPI.Web/Controllers/ModsApiController.cs b/src/SMAPI.Web/Controllers/ModsApiController.cs index dcddaf10..37d763cc 100644 --- a/src/SMAPI.Web/Controllers/ModsApiController.cs +++ b/src/SMAPI.Web/Controllers/ModsApiController.cs @@ -81,6 +81,8 @@ namespace StardewModdingAPI.Web.Controllers if (model?.Mods == null) return new ModEntryModel[0]; + ModUpdateCheckConfig config = this.Config.Value; + // fetch wiki data WikiModEntry[] wikiData = this.WikiCache.GetWikiMods().Select(p => p.Data).ToArray(); IDictionary mods = new Dictionary(StringComparer.CurrentCultureIgnoreCase); @@ -89,6 +91,11 @@ namespace StardewModdingAPI.Web.Controllers if (string.IsNullOrWhiteSpace(mod.ID)) continue; + // special case: if this is an update check for the official SMAPI repo, check the Nexus mod page for beta versions + if (mod.ID == config.SmapiInfo.ID && mod.UpdateKeys?.Any(key => key == config.SmapiInfo.DefaultUpdateKey) == true && mod.InstalledVersion?.IsPrerelease() == true) + mod.UpdateKeys = mod.UpdateKeys.Concat(config.SmapiInfo.AddBetaUpdateKeys).ToArray(); + + // fetch result ModEntryModel result = await this.GetModData(mod, wikiData, model.IncludeExtendedMetadata, model.ApiVersion); if (!model.IncludeExtendedMetadata && (model.ApiVersion == null || mod.InstalledVersion == null)) { diff --git a/src/SMAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs b/src/SMAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs index bd58dba0..aea695b8 100644 --- a/src/SMAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs +++ b/src/SMAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs @@ -14,5 +14,8 @@ namespace StardewModdingAPI.Web.Framework.ConfigModels /// Update-check metadata to override. public ModOverrideConfig[] ModOverrides { get; set; } + + /// The update-check config for SMAPI's own update checks. + public SmapiInfoConfig SmapiInfo { get; set; } } } diff --git a/src/SMAPI.Web/Framework/ConfigModels/SmapiInfoConfig.cs b/src/SMAPI.Web/Framework/ConfigModels/SmapiInfoConfig.cs new file mode 100644 index 00000000..d69fabb3 --- /dev/null +++ b/src/SMAPI.Web/Framework/ConfigModels/SmapiInfoConfig.cs @@ -0,0 +1,15 @@ +namespace StardewModdingAPI.Web.Framework.ConfigModels +{ + /// The update-check config for SMAPI's own update checks. + internal class SmapiInfoConfig + { + /// The mod ID used for SMAPI update checks. + public string ID { get; set; } + + /// The default update key used for SMAPI update checks. + public string DefaultUpdateKey { get; set; } + + /// The update keys to add for SMAPI update checks when the player has a beta version installed. + public string[] AddBetaUpdateKeys { get; set; } + } +} diff --git a/src/SMAPI.Web/appsettings.json b/src/SMAPI.Web/appsettings.json index 1837170b..0265a928 100644 --- a/src/SMAPI.Web/appsettings.json +++ b/src/SMAPI.Web/appsettings.json @@ -75,6 +75,11 @@ "ID": "MartyrPher.SMAPI-Android-Installer", "AllowNonStandardVersions": true } - ] + ], + "SmapiInfo": { + "ID": "Pathoschild.SMAPI", + "DefaultUpdateKey": "GitHub:Pathoschild/SMAPI", + "AddBetaUpdateKeys": [ "Nexus:2400" ] + } } } -- cgit