diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-06-28 20:59:39 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-06-28 20:59:39 -0400 |
commit | 583cb91f4a3429549b8e56081737e6a410ebd1a4 (patch) | |
tree | a02618352046c8082cb23811bb01765aa4357792 /src | |
parent | db7247f36d11c870ec7b54bf6ea8b5b036065288 (diff) | |
download | SMAPI-583cb91f4a3429549b8e56081737e6a410ebd1a4.tar.gz SMAPI-583cb91f4a3429549b8e56081737e6a410ebd1a4.tar.bz2 SMAPI-583cb91f4a3429549b8e56081737e6a410ebd1a4.zip |
use mod DB in web API to get default update keys for mod IDs (#532)
Diffstat (limited to 'src')
-rw-r--r-- | src/SMAPI.Web/Controllers/ModsApiController.cs | 22 | ||||
-rw-r--r-- | src/SMAPI.Web/StardewModdingAPI.Web.csproj | 5 | ||||
-rw-r--r-- | src/SMAPI.Web/wwwroot/StardewModdingAPI.metadata.json (renamed from src/SMAPI/StardewModdingAPI.metadata.json) | 0 | ||||
-rw-r--r-- | src/SMAPI/StardewModdingAPI.csproj | 7 |
4 files changed, 29 insertions, 5 deletions
diff --git a/src/SMAPI.Web/Controllers/ModsApiController.cs b/src/SMAPI.Web/Controllers/ModsApiController.cs index c5a1705d..960602f4 100644 --- a/src/SMAPI.Web/Controllers/ModsApiController.cs +++ b/src/SMAPI.Web/Controllers/ModsApiController.cs @@ -1,13 +1,16 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Options; using StardewModdingAPI.Toolkit; using StardewModdingAPI.Toolkit.Framework.Clients.WebApi; +using StardewModdingAPI.Toolkit.Framework.ModData; using StardewModdingAPI.Web.Framework.Clients.Chucklefish; using StardewModdingAPI.Web.Framework.Clients.GitHub; using StardewModdingAPI.Web.Framework.Clients.Nexus; @@ -39,18 +42,23 @@ namespace StardewModdingAPI.Web.Controllers /// <summary>A regex which matches SMAPI-style semantic version.</summary> private readonly string VersionRegex; + /// <summary>The internal mod metadata list.</summary> + private readonly ModDatabase ModDatabase; + /********* ** Public methods *********/ /// <summary>Construct an instance.</summary> + /// <param name="environment">The web hosting environment.</param> /// <param name="cache">The cache in which to store mod metadata.</param> /// <param name="configProvider">The config settings for mod update checks.</param> /// <param name="chucklefish">The Chucklefish API client.</param> /// <param name="github">The GitHub API client.</param> /// <param name="nexus">The Nexus API client.</param> - public ModsApiController(IMemoryCache cache, IOptions<ModUpdateCheckConfig> configProvider, IChucklefishClient chucklefish, IGitHubClient github, INexusClient nexus) + public ModsApiController(IHostingEnvironment environment, IMemoryCache cache, IOptions<ModUpdateCheckConfig> configProvider, IChucklefishClient chucklefish, IGitHubClient github, INexusClient nexus) { + this.ModDatabase = new ModToolkit().GetModDatabase(Path.Combine(environment.WebRootPath, "StardewModdingAPI.metadata.json")); ModUpdateCheckConfig config = configProvider.Value; this.Cache = cache; @@ -79,10 +87,20 @@ namespace StardewModdingAPI.Web.Controllers if (string.IsNullOrWhiteSpace(mod.ID)) continue; + // resolve update keys + var updateKeys = new HashSet<string>(mod.UpdateKeys ?? new string[0], StringComparer.InvariantCultureIgnoreCase); + ModDataRecord record = this.ModDatabase.Get(mod.ID); + if (record?.Fields != null) + { + string defaultUpdateKey = record.Fields.FirstOrDefault(p => p.Key == ModDataFieldKey.UpdateKey && p.IsDefault)?.Value; + if (!string.IsNullOrWhiteSpace(defaultUpdateKey)) + updateKeys.Add(defaultUpdateKey); + } + // get latest versions ModEntryModel result = new ModEntryModel { ID = mod.ID }; IList<string> errors = new List<string>(); - foreach (string updateKey in mod.UpdateKeys ?? new string[0]) + foreach (string updateKey in updateKeys) { // fetch data ModInfoModel data = await this.GetInfoForUpdateKeyAsync(updateKey); diff --git a/src/SMAPI.Web/StardewModdingAPI.Web.csproj b/src/SMAPI.Web/StardewModdingAPI.Web.csproj index a409e6eb..6761c7ad 100644 --- a/src/SMAPI.Web/StardewModdingAPI.Web.csproj +++ b/src/SMAPI.Web/StardewModdingAPI.Web.csproj @@ -26,5 +26,10 @@ <ItemGroup> <ProjectReference Include="..\StardewModdingAPI.Toolkit\StardewModdingAPI.Toolkit.csproj" /> </ItemGroup> + <ItemGroup> + <Content Update="wwwroot\StardewModdingAPI.metadata.json"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Content> + </ItemGroup> </Project> diff --git a/src/SMAPI/StardewModdingAPI.metadata.json b/src/SMAPI.Web/wwwroot/StardewModdingAPI.metadata.json index 343257f1..343257f1 100644 --- a/src/SMAPI/StardewModdingAPI.metadata.json +++ b/src/SMAPI.Web/wwwroot/StardewModdingAPI.metadata.json diff --git a/src/SMAPI/StardewModdingAPI.csproj b/src/SMAPI/StardewModdingAPI.csproj index f849ee53..c13f5e30 100644 --- a/src/SMAPI/StardewModdingAPI.csproj +++ b/src/SMAPI/StardewModdingAPI.csproj @@ -293,16 +293,17 @@ <SubType>Designer</SubType> </None> <Content Include="StardewModdingAPI.config.json"> - <CopyToOutputDirectory>Always</CopyToOutputDirectory> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> - <Content Include="StardewModdingAPI.metadata.json"> + <Content Include="..\SMAPI.Web\wwwroot\StardewModdingAPI.metadata.json"> + <Link>StardewModdingAPI.metadata.json</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> </ItemGroup> <ItemGroup> <Content Include="icon.ico" /> <Content Include="steam_appid.txt"> - <CopyToOutputDirectory>Always</CopyToOutputDirectory> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> </ItemGroup> <ItemGroup> |