summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/SMAPI.Web/Framework/Clients/UpdateManifest/ResponseModels/UpdateManifestModel.cs10
-rw-r--r--src/SMAPI.Web/Framework/Clients/UpdateManifest/UpdateManifestClient.cs21
2 files changed, 23 insertions, 8 deletions
diff --git a/src/SMAPI.Web/Framework/Clients/UpdateManifest/ResponseModels/UpdateManifestModel.cs b/src/SMAPI.Web/Framework/Clients/UpdateManifest/ResponseModels/UpdateManifestModel.cs
index e213fbab..ff3dccbc 100644
--- a/src/SMAPI.Web/Framework/Clients/UpdateManifest/ResponseModels/UpdateManifestModel.cs
+++ b/src/SMAPI.Web/Framework/Clients/UpdateManifest/ResponseModels/UpdateManifestModel.cs
@@ -9,8 +9,8 @@ namespace StardewModdingAPI.Web.Framework.Clients.UpdateManifest.ResponseModels
/*********
** Accessors
*********/
- /// <summary>The manifest format version.</summary>
- public string? ManifestVersion { get; }
+ /// <summary>The manifest format version. This is equivalent to the SMAPI version, and is used to parse older manifests correctly if later versions of SMAPI change the expected format.</summary>
+ public string Format { get; }
/// <summary>The mod info in this update manifest.</summary>
public IDictionary<string, UpdateManifestModModel>? Mods { get; }
@@ -20,11 +20,11 @@ namespace StardewModdingAPI.Web.Framework.Clients.UpdateManifest.ResponseModels
** Public methods
*********/
/// <summary>Construct an instance.</summary>
- /// <param name="manifestVersion">The manifest format version.</param>
+ /// <param name="format">The manifest format version.</param>
/// <param name="mods">The mod info in this update manifest.</param>
- public UpdateManifestModel(string manifestVersion, IDictionary<string, UpdateManifestModModel> mods)
+ public UpdateManifestModel(string format, IDictionary<string, UpdateManifestModModel> mods)
{
- this.ManifestVersion = manifestVersion;
+ this.Format = format;
this.Mods = mods;
}
}
diff --git a/src/SMAPI.Web/Framework/Clients/UpdateManifest/UpdateManifestClient.cs b/src/SMAPI.Web/Framework/Clients/UpdateManifest/UpdateManifestClient.cs
index 0d19900e..cd102ec5 100644
--- a/src/SMAPI.Web/Framework/Clients/UpdateManifest/UpdateManifestClient.cs
+++ b/src/SMAPI.Web/Framework/Clients/UpdateManifest/UpdateManifestClient.cs
@@ -1,8 +1,12 @@
// Copyright 2022 Jamie Taylor
+
+using System;
+using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Pathoschild.Http.Client;
+using StardewModdingAPI.Toolkit;
using StardewModdingAPI.Toolkit.Framework.UpdateData;
using StardewModdingAPI.Web.Framework.Clients.UpdateManifest.ResponseModels;
@@ -45,21 +49,32 @@ namespace StardewModdingAPI.Web.Framework.Clients.UpdateManifest
}
/// <inheritdoc/>
+ [SuppressMessage("ReSharper", "ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract", Justification = "This is the method which ensures the annotations are correct.")]
public async Task<IModPage?> GetModData(string id)
{
+ // get raw update manifest
UpdateManifestModel? manifest;
try
{
manifest = await this.Client.GetAsync(id).As<UpdateManifestModel?>();
+ if (manifest is null)
+ return new GenericModPage(this.SiteKey, id).SetError(RemoteModStatus.InvalidData, $"The update manifest at {id} is empty");
}
catch (ApiException ex) when (ex.Status == HttpStatusCode.NotFound)
{
return new GenericModPage(this.SiteKey, id).SetError(RemoteModStatus.DoesNotExist, $"No update manifest found at {id}");
}
+ catch (Exception ex)
+ {
+ return new GenericModPage(this.SiteKey, id).SetError(RemoteModStatus.InvalidData, $"The update manifest at {id} has an invalid format: {ex.Message}");
+ }
+
+ // validate
+ if (!SemanticVersion.TryParse(manifest.Format, out _))
+ return new GenericModPage(this.SiteKey, id).SetError(RemoteModStatus.InvalidData, $"The update manifest at {id} has invalid format version '{manifest.Format}'");
- return manifest is not null
- ? new UpdateManifestModPage(id, manifest)
- : new GenericModPage(this.SiteKey, id).SetError(RemoteModStatus.DoesNotExist, $"The update manifest at {id} has an invalid format");
+ // build model
+ return new UpdateManifestModPage(id, manifest);
}
}
}