summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI.Web')
-rw-r--r--src/SMAPI.Web/Controllers/ModsApiController.cs34
-rw-r--r--src/SMAPI.Web/Framework/ConfigModels/ModOverrideConfig.cs15
-rw-r--r--src/SMAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs3
-rw-r--r--src/SMAPI.Web/appsettings.json9
4 files changed, 41 insertions, 20 deletions
diff --git a/src/SMAPI.Web/Controllers/ModsApiController.cs b/src/SMAPI.Web/Controllers/ModsApiController.cs
index 8e65b6b9..8370fe09 100644
--- a/src/SMAPI.Web/Controllers/ModsApiController.cs
+++ b/src/SMAPI.Web/Controllers/ModsApiController.cs
@@ -41,11 +41,8 @@ namespace StardewModdingAPI.Web.Controllers
/// <summary>The cache in which to store mod data.</summary>
private readonly IModCacheRepository ModCache;
- /// <summary>The number of minutes successful update checks should be cached before refetching them.</summary>
- private readonly int SuccessCacheMinutes;
-
- /// <summary>The number of minutes failed update checks should be cached before refetching them.</summary>
- private readonly int ErrorCacheMinutes;
+ /// <summary>The config settings for mod update checks.</summary>
+ private readonly IOptions<ModUpdateCheckConfig> Config;
/// <summary>The internal mod metadata list.</summary>
private readonly ModDatabase ModDatabase;
@@ -58,21 +55,19 @@ namespace StardewModdingAPI.Web.Controllers
/// <param name="environment">The web hosting environment.</param>
/// <param name="wikiCache">The cache in which to store wiki data.</param>
/// <param name="modCache">The cache in which to store mod metadata.</param>
- /// <param name="configProvider">The config settings for mod update checks.</param>
+ /// <param name="config">The config settings for mod update checks.</param>
/// <param name="chucklefish">The Chucklefish API client.</param>
/// <param name="curseForge">The CurseForge API client.</param>
/// <param name="github">The GitHub API client.</param>
/// <param name="modDrop">The ModDrop API client.</param>
/// <param name="nexus">The Nexus API client.</param>
- public ModsApiController(IHostingEnvironment environment, IWikiCacheRepository wikiCache, IModCacheRepository modCache, IOptions<ModUpdateCheckConfig> configProvider, IChucklefishClient chucklefish, ICurseForgeClient curseForge, IGitHubClient github, IModDropClient modDrop, INexusClient nexus)
+ public ModsApiController(IHostingEnvironment environment, IWikiCacheRepository wikiCache, IModCacheRepository modCache, IOptions<ModUpdateCheckConfig> config, IChucklefishClient chucklefish, ICurseForgeClient curseForge, IGitHubClient github, IModDropClient modDrop, INexusClient nexus)
{
this.ModDatabase = new ModToolkit().GetModDatabase(Path.Combine(environment.WebRootPath, "SMAPI.metadata.json"));
- ModUpdateCheckConfig config = configProvider.Value;
this.WikiCache = wikiCache;
this.ModCache = modCache;
- this.SuccessCacheMinutes = config.SuccessCacheMinutes;
- this.ErrorCacheMinutes = config.ErrorCacheMinutes;
+ this.Config = config;
this.Repositories =
new IModRepository[]
{
@@ -133,7 +128,8 @@ namespace StardewModdingAPI.Web.Controllers
ModDataRecord record = this.ModDatabase.Get(search.ID);
WikiModEntry wikiEntry = wikiData.FirstOrDefault(entry => entry.ID.Contains(search.ID.Trim(), StringComparer.InvariantCultureIgnoreCase));
UpdateKey[] updateKeys = this.GetUpdateKeys(search.UpdateKeys, record, wikiEntry).ToArray();
- bool isSmapi = search.ID == "Pathoschild.SMAPI";
+ ModOverrideConfig overrides = this.Config.Value.ModOverrides.FirstOrDefault(p => p.ID.Equals(search.ID?.Trim(), StringComparison.InvariantCultureIgnoreCase));
+ bool allowNonStandardVersions = overrides?.AllowNonStandardVersions ?? false;
// get latest versions
ModEntryModel result = new ModEntryModel { ID = search.ID };
@@ -152,7 +148,7 @@ namespace StardewModdingAPI.Web.Controllers
}
// fetch data
- ModInfoModel data = await this.GetInfoForUpdateKeyAsync(updateKey, allowNonStandardVersions: isSmapi);
+ ModInfoModel data = await this.GetInfoForUpdateKeyAsync(updateKey, allowNonStandardVersions);
if (data.Error != null)
{
errors.Add(data.Error);
@@ -162,7 +158,7 @@ namespace StardewModdingAPI.Web.Controllers
// handle main version
if (data.Version != null)
{
- ISemanticVersion version = this.GetMappedVersion(data.Version, wikiEntry?.MapRemoteVersions, allowNonStandard: isSmapi);
+ ISemanticVersion version = this.GetMappedVersion(data.Version, wikiEntry?.MapRemoteVersions, allowNonStandardVersions);
if (version == null)
{
errors.Add($"The update key '{updateKey}' matches a mod with invalid semantic version '{data.Version}'.");
@@ -176,7 +172,7 @@ namespace StardewModdingAPI.Web.Controllers
// handle optional version
if (data.PreviewVersion != null)
{
- ISemanticVersion version = this.GetMappedVersion(data.PreviewVersion, wikiEntry?.MapRemoteVersions, allowNonStandard: isSmapi);
+ ISemanticVersion version = this.GetMappedVersion(data.PreviewVersion, wikiEntry?.MapRemoteVersions, allowNonStandardVersions);
if (version == null)
{
errors.Add($"The update key '{updateKey}' matches a mod with invalid optional semantic version '{data.PreviewVersion}'.");
@@ -216,16 +212,16 @@ namespace StardewModdingAPI.Web.Controllers
}
// special cases
- if (isSmapi)
+ if (overrides?.SetUrl != null)
{
if (main != null)
- main.Url = "https://smapi.io/";
+ main.Url = overrides.SetUrl;
if (optional != null)
- optional.Url = "https://smapi.io/";
+ optional.Url = overrides.SetUrl;
}
// get recommended update (if any)
- ISemanticVersion installedVersion = this.GetMappedVersion(search.InstalledVersion?.ToString(), wikiEntry?.MapLocalVersions, allowNonStandard: isSmapi);
+ ISemanticVersion installedVersion = this.GetMappedVersion(search.InstalledVersion?.ToString(), wikiEntry?.MapLocalVersions, allowNonStandard: allowNonStandardVersions);
if (apiVersion != null && installedVersion != null)
{
// get newer versions
@@ -288,7 +284,7 @@ namespace StardewModdingAPI.Web.Controllers
private async Task<ModInfoModel> GetInfoForUpdateKeyAsync(UpdateKey updateKey, bool allowNonStandardVersions)
{
// get mod
- if (!this.ModCache.TryGetMod(updateKey.Repository, updateKey.ID, out CachedMod mod) || this.ModCache.IsStale(mod.LastUpdated, mod.FetchStatus == RemoteModStatus.TemporaryError ? this.ErrorCacheMinutes : this.SuccessCacheMinutes))
+ if (!this.ModCache.TryGetMod(updateKey.Repository, updateKey.ID, out CachedMod mod) || this.ModCache.IsStale(mod.LastUpdated, mod.FetchStatus == RemoteModStatus.TemporaryError ? this.Config.Value.ErrorCacheMinutes : this.Config.Value.SuccessCacheMinutes))
{
// get site
if (!this.Repositories.TryGetValue(updateKey.Repository, out IModRepository repository))
diff --git a/src/SMAPI.Web/Framework/ConfigModels/ModOverrideConfig.cs b/src/SMAPI.Web/Framework/ConfigModels/ModOverrideConfig.cs
new file mode 100644
index 00000000..f382d7b5
--- /dev/null
+++ b/src/SMAPI.Web/Framework/ConfigModels/ModOverrideConfig.cs
@@ -0,0 +1,15 @@
+namespace StardewModdingAPI.Web.Framework.ConfigModels
+{
+ /// <summary>Override update-check metadata for a mod.</summary>
+ internal class ModOverrideConfig
+ {
+ /// <summary>The unique ID from the mod's manifest.</summary>
+ public string ID { get; set; }
+
+ /// <summary>Whether to allow non-standard versions.</summary>
+ public bool AllowNonStandardVersions { get; set; }
+
+ /// <summary>The mod page URL to use regardless of which site has the update, or <c>null</c> to use the site URL.</summary>
+ public string SetUrl { get; set; }
+ }
+}
diff --git a/src/SMAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs b/src/SMAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs
index 46073eb8..bd58dba0 100644
--- a/src/SMAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs
+++ b/src/SMAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs
@@ -11,5 +11,8 @@ namespace StardewModdingAPI.Web.Framework.ConfigModels
/// <summary>The number of minutes failed update checks should be cached before refetching them.</summary>
public int ErrorCacheMinutes { get; set; }
+
+ /// <summary>Update-check metadata to override.</summary>
+ public ModOverrideConfig[] ModOverrides { get; set; }
}
}
diff --git a/src/SMAPI.Web/appsettings.json b/src/SMAPI.Web/appsettings.json
index caeb381f..e1316c97 100644
--- a/src/SMAPI.Web/appsettings.json
+++ b/src/SMAPI.Web/appsettings.json
@@ -64,6 +64,13 @@
"ModUpdateCheck": {
"SuccessCacheMinutes": 60,
- "ErrorCacheMinutes": 5
+ "ErrorCacheMinutes": 5,
+ "ModOverrides": [
+ {
+ "ID": "Pathoschild.SMAPI",
+ "AllowNonStandardVersions": true,
+ "SetUrl": "https://smapi.io"
+ }
+ ]
}
}