summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/release-notes.md3
-rw-r--r--src/SMAPI.Web/Framework/Clients/Nexus/DisabledNexusClient.cs31
-rw-r--r--src/SMAPI.Web/Startup.cs23
3 files changed, 49 insertions, 8 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md
index 01ba6e30..de30a23b 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -64,6 +64,9 @@ the C# mod that loads them is updated.
* Fixed issue where suppressing `[Left|Right]Thumbstick[Down|Left]` keys would suppress the opposite direction instead.
* Fixed null handling in various edge cases.
+### For SMAPI contributors
+* You no longer need a Nexus API key to launch the SMAPI web project locally.
+
## 3.13.4
Released 16 January 2022 for Stardew Valley 1.5.6 or later.
diff --git a/src/SMAPI.Web/Framework/Clients/Nexus/DisabledNexusClient.cs b/src/SMAPI.Web/Framework/Clients/Nexus/DisabledNexusClient.cs
new file mode 100644
index 00000000..6edd5f64
--- /dev/null
+++ b/src/SMAPI.Web/Framework/Clients/Nexus/DisabledNexusClient.cs
@@ -0,0 +1,31 @@
+using System.Threading.Tasks;
+using StardewModdingAPI.Toolkit.Framework.UpdateData;
+
+namespace StardewModdingAPI.Web.Framework.Clients.Nexus
+{
+ /// <summary>A client for the Nexus website which does nothing, used for local development.</summary>
+ internal class DisabledNexusClient : INexusClient
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// <inheritdoc />
+ public ModSiteKey SiteKey => ModSiteKey.Nexus;
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Get update check info about a mod.</summary>
+ /// <param name="id">The mod ID.</param>
+ public Task<IModPage?> GetModData(string id)
+ {
+ return Task.FromResult<IModPage?>(
+ new GenericModPage(ModSiteKey.Nexus, id).SetError(RemoteModStatus.TemporaryError, "The Nexus client is currently disabled due to the configuration.")
+ );
+ }
+
+ /// <inheritdoc />
+ public void Dispose() { }
+ }
+}
diff --git a/src/SMAPI.Web/Startup.cs b/src/SMAPI.Web/Startup.cs
index 98dbca5e..2693aa90 100644
--- a/src/SMAPI.Web/Startup.cs
+++ b/src/SMAPI.Web/Startup.cs
@@ -128,14 +128,21 @@ namespace StardewModdingAPI.Web
modUrlFormat: api.ModDropModPageUrl
));
- services.AddSingleton<INexusClient>(new NexusClient(
- webUserAgent: userAgent,
- webBaseUrl: api.NexusBaseUrl,
- webModUrlFormat: api.NexusModUrlFormat,
- webModScrapeUrlFormat: api.NexusModScrapeUrlFormat,
- apiAppVersion: version,
- apiKey: api.NexusApiKey
- ));
+ if (!string.IsNullOrWhiteSpace(api.NexusApiKey))
+ {
+ services.AddSingleton<INexusClient>(new NexusClient(
+ webUserAgent: userAgent,
+ webBaseUrl: api.NexusBaseUrl,
+ webModUrlFormat: api.NexusModUrlFormat,
+ webModScrapeUrlFormat: api.NexusModScrapeUrlFormat,
+ apiAppVersion: version,
+ apiKey: api.NexusApiKey
+ ));
+ }
+ else
+ {
+ services.AddSingleton<INexusClient>(new DisabledNexusClient());
+ }
services.AddSingleton<IPastebinClient>(new PastebinClient(
baseUrl: api.PastebinBaseUrl,