summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2018-03-04 18:46:05 -0500
committerJesse Plamondon-Willard <github@jplamondonw.com>2018-03-04 18:46:05 -0500
commit99023f94871e1f9bad5ee5f5db0ff041a02e9ed5 (patch)
treeed5a44b3199cd6c8dc1a20781dd6b071b4254900 /src/SMAPI.Web
parent90c8593ba9a0828a4d3f563c6f08fc90933cd2ff (diff)
downloadSMAPI-99023f94871e1f9bad5ee5f5db0ff041a02e9ed5.tar.gz
SMAPI-99023f94871e1f9bad5ee5f5db0ff041a02e9ed5.tar.bz2
SMAPI-99023f94871e1f9bad5ee5f5db0ff041a02e9ed5.zip
add support for mapping non-semantic remote mod versions
Diffstat (limited to 'src/SMAPI.Web')
-rw-r--r--src/SMAPI.Web/Controllers/ModsApiController.cs24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/SMAPI.Web/Controllers/ModsApiController.cs b/src/SMAPI.Web/Controllers/ModsApiController.cs
index dcb4ec52..abae7db7 100644
--- a/src/SMAPI.Web/Controllers/ModsApiController.cs
+++ b/src/SMAPI.Web/Controllers/ModsApiController.cs
@@ -64,14 +64,15 @@ namespace StardewModdingAPI.Web.Controllers
/// <summary>Fetch version metadata for the given mods.</summary>
/// <param name="modKeys">The namespaced mod keys to search as a comma-delimited array.</param>
+ /// <param name="allowInvalidVersions">Whether to allow non-semantic versions, instead of returning an error for those.</param>
[HttpGet]
- public async Task<IDictionary<string, ModInfoModel>> GetAsync(string modKeys)
+ public async Task<IDictionary<string, ModInfoModel>> GetAsync(string modKeys, bool allowInvalidVersions = false)
{
string[] modKeysArray = modKeys?.Split(',').ToArray();
if (modKeysArray == null || !modKeysArray.Any())
return new Dictionary<string, ModInfoModel>();
- return await this.PostAsync(new ModSearchModel(modKeysArray));
+ return await this.PostAsync(new ModSearchModel(modKeysArray, allowInvalidVersions));
}
/// <summary>Fetch version metadata for the given mods.</summary>
@@ -79,7 +80,8 @@ namespace StardewModdingAPI.Web.Controllers
[HttpPost]
public async Task<IDictionary<string, ModInfoModel>> PostAsync([FromBody] ModSearchModel search)
{
- // sort & filter keys
+ // parse model
+ bool allowInvalidVersions = search?.AllowInvalidVersions ?? false;
string[] modKeys = (search?.ModKeys?.ToArray() ?? new string[0])
.Distinct(StringComparer.CurrentCultureIgnoreCase)
.OrderBy(p => p, StringComparer.CurrentCultureIgnoreCase)
@@ -106,12 +108,20 @@ namespace StardewModdingAPI.Web.Controllers
// fetch mod info
result[modKey] = await this.Cache.GetOrCreateAsync($"{repository.VendorKey}:{modID}".ToLower(), async entry =>
{
- entry.AbsoluteExpiration = DateTimeOffset.UtcNow.AddMinutes(this.CacheMinutes);
-
+ // fetch info
ModInfoModel info = await repository.GetModInfoAsync(modID);
- if (info.Error == null && (info.Version == null || !Regex.IsMatch(info.Version, this.VersionRegex, RegexOptions.CultureInvariant | RegexOptions.IgnoreCase)))
- info = new ModInfoModel(info.Name, info.Version, info.Url, info.Version == null ? "Mod has no version number." : $"Mod has invalid semantic version '{info.Version}'.");
+ // validate
+ if (info.Error == null)
+ {
+ if (info.Version == null)
+ info = new ModInfoModel(info.Name, info.Version, info.Url, "Mod has no version number.");
+ if (!allowInvalidVersions && !Regex.IsMatch(info.Version, this.VersionRegex, RegexOptions.CultureInvariant | RegexOptions.IgnoreCase))
+ info = new ModInfoModel(info.Name, info.Version, info.Url, $"Mod has invalid semantic version '{info.Version}'.");
+ }
+
+ // cache & return
+ entry.AbsoluteExpiration = DateTimeOffset.UtcNow.AddMinutes(this.CacheMinutes);
return info;
});
}