diff options
5 files changed, 33 insertions, 28 deletions
diff --git a/src/SMAPI.Web/Framework/Clients/UpdateManifest/ResponseModels/UpdateManifestModModel.cs b/src/SMAPI.Web/Framework/Clients/UpdateManifest/ResponseModels/UpdateManifestModModel.cs index ee1fbeb6..418fb26b 100644 --- a/src/SMAPI.Web/Framework/Clients/UpdateManifest/ResponseModels/UpdateManifestModModel.cs +++ b/src/SMAPI.Web/Framework/Clients/UpdateManifest/ResponseModels/UpdateManifestModModel.cs @@ -1,4 +1,6 @@ // Copyright 2022 Jamie Taylor +using System; + namespace StardewModdingAPI.Web.Framework.Clients.UpdateManifest.ResponseModels { /// <summary>The data model for a mod in an update manifest file.</summary> @@ -11,10 +13,10 @@ namespace StardewModdingAPI.Web.Framework.Clients.UpdateManifest.ResponseModels public string? Name { get; } /// <summary>The mod page URL from which to download updates.</summary> - public string? Url { get; } + public string? ModPageUrl { get; } /// <summary>The available versions for this mod.</summary> - public UpdateManifestVersionModel[]? Versions { get; } + public UpdateManifestVersionModel[] Versions { get; } /********* @@ -22,13 +24,13 @@ namespace StardewModdingAPI.Web.Framework.Clients.UpdateManifest.ResponseModels *********/ /// <summary>Construct an instance.</summary> /// <param name="name">The mod's name.</param> - /// <param name="url">The mod page URL from which to download updates.</param> + /// <param name="modPageUrl">The mod page URL from which to download updates.</param> /// <param name="versions">The available versions for this mod.</param> - public UpdateManifestModModel(string? name, string? url, UpdateManifestVersionModel[]? versions) + public UpdateManifestModModel(string? name, string? modPageUrl, UpdateManifestVersionModel[]? versions) { this.Name = name; - this.Url = url; - this.Versions = versions; + this.ModPageUrl = modPageUrl; + this.Versions = versions ?? Array.Empty<UpdateManifestVersionModel>(); } } } diff --git a/src/SMAPI.Web/Framework/Clients/UpdateManifest/ResponseModels/UpdateManifestModel.cs b/src/SMAPI.Web/Framework/Clients/UpdateManifest/ResponseModels/UpdateManifestModel.cs index ff3dccbc..3b930ff3 100644 --- a/src/SMAPI.Web/Framework/Clients/UpdateManifest/ResponseModels/UpdateManifestModel.cs +++ b/src/SMAPI.Web/Framework/Clients/UpdateManifest/ResponseModels/UpdateManifestModel.cs @@ -13,7 +13,7 @@ namespace StardewModdingAPI.Web.Framework.Clients.UpdateManifest.ResponseModels public string Format { get; } /// <summary>The mod info in this update manifest.</summary> - public IDictionary<string, UpdateManifestModModel>? Mods { get; } + public IDictionary<string, UpdateManifestModModel> Mods { get; } /********* @@ -22,10 +22,10 @@ namespace StardewModdingAPI.Web.Framework.Clients.UpdateManifest.ResponseModels /// <summary>Construct an instance.</summary> /// <param name="format">The manifest format version.</param> /// <param name="mods">The mod info in this update manifest.</param> - public UpdateManifestModel(string format, IDictionary<string, UpdateManifestModModel> mods) + public UpdateManifestModel(string format, IDictionary<string, UpdateManifestModModel>? mods) { this.Format = format; - this.Mods = mods; + this.Mods = mods ?? new Dictionary<string, UpdateManifestModModel>(); } } } diff --git a/src/SMAPI.Web/Framework/Clients/UpdateManifest/ResponseModels/UpdateManifestVersionModel.cs b/src/SMAPI.Web/Framework/Clients/UpdateManifest/ResponseModels/UpdateManifestVersionModel.cs index 1e84501f..7cfb0cfc 100644 --- a/src/SMAPI.Web/Framework/Clients/UpdateManifest/ResponseModels/UpdateManifestVersionModel.cs +++ b/src/SMAPI.Web/Framework/Clients/UpdateManifest/ResponseModels/UpdateManifestVersionModel.cs @@ -10,11 +10,8 @@ namespace StardewModdingAPI.Web.Framework.Clients.UpdateManifest.ResponseModels /// <summary>The mod's semantic version.</summary> public string? Version { get; } - /// <summary>The URL for this version's download page (if any).</summary> - public string? DownloadPageUrl { get; } - - /// <summary>The URL for this version's direct file download (if any).</summary> - public string? DownloadFileUrl { get; } + /// <summary>The mod page URL from which to download updates, if different from <see cref="UpdateManifestModModel.ModPageUrl"/>.</summary> + public string? ModPageUrl { get; } /********* @@ -22,13 +19,11 @@ namespace StardewModdingAPI.Web.Framework.Clients.UpdateManifest.ResponseModels *********/ /// <summary>Construct an instance.</summary> /// <param name="version">The mod's semantic version.</param> - /// <param name="downloadPageUrl">This version's download page URL, if any.</param> - /// <param name="downloadFileUrl">This version's direct file download URL, if any.</param> - public UpdateManifestVersionModel(string version, string? downloadPageUrl, string? downloadFileUrl) + /// <param name="modPageUrl">The mod page URL from which to download updates, if different from <see cref="UpdateManifestModModel.ModPageUrl"/>.</param> + public UpdateManifestVersionModel(string version, string? modPageUrl) { this.Version = version; - this.DownloadPageUrl = downloadPageUrl; - this.DownloadFileUrl = downloadFileUrl; + this.ModPageUrl = modPageUrl; } } } diff --git a/src/SMAPI.Web/Framework/Clients/UpdateManifest/UpdateManifestClient.cs b/src/SMAPI.Web/Framework/Clients/UpdateManifest/UpdateManifestClient.cs index cd102ec5..9a2887c2 100644 --- a/src/SMAPI.Web/Framework/Clients/UpdateManifest/UpdateManifestClient.cs +++ b/src/SMAPI.Web/Framework/Clients/UpdateManifest/UpdateManifestClient.cs @@ -72,6 +72,17 @@ namespace StardewModdingAPI.Web.Framework.Clients.UpdateManifest // 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}'"); + foreach ((string modKey, UpdateManifestModModel mod) in manifest.Mods) + { + if (string.IsNullOrWhiteSpace(mod.ModPageUrl)) + { + foreach (UpdateManifestVersionModel download in mod.Versions) + { + if (string.IsNullOrWhiteSpace(download.ModPageUrl)) + return new GenericModPage(this.SiteKey, id).SetError(RemoteModStatus.InvalidData, $"The update manifest at {id} is invalid (all mod downloads must have a mod page URL)"); + } + } + } // build model return new UpdateManifestModPage(id, manifest); diff --git a/src/SMAPI.Web/Framework/Clients/UpdateManifest/UpdateManifestModPage.cs b/src/SMAPI.Web/Framework/Clients/UpdateManifest/UpdateManifestModPage.cs index 251ed9ec..f4ad0500 100644 --- a/src/SMAPI.Web/Framework/Clients/UpdateManifest/UpdateManifestModPage.cs +++ b/src/SMAPI.Web/Framework/Clients/UpdateManifest/UpdateManifestModPage.cs @@ -26,7 +26,7 @@ namespace StardewModdingAPI.Web.Framework.Clients.UpdateManifest : base(ModSiteKey.UpdateManifest, url) { this.RequireSubkey = true; - this.Mods = manifest.Mods ?? new Dictionary<string, UpdateManifestModModel>(); + this.Mods = manifest.Mods; this.SetInfo(name: url, url: url, version: null, downloads: this.ParseDownloads(manifest.Mods).ToArray()); } @@ -35,8 +35,8 @@ namespace StardewModdingAPI.Web.Framework.Clients.UpdateManifest /// <returns>The mod name for the given subkey, or <see langword="null"/> if this manifest does not contain the given subkey.</returns> public override string? GetName(string? subkey) { - return subkey is not null && this.Mods.TryGetValue(subkey.TrimStart('@'), out UpdateManifestModModel? modModel) - ? modModel.Name + return subkey is not null && this.Mods.TryGetValue(subkey.TrimStart('@'), out UpdateManifestModModel? mod) + ? mod.Name : null; } @@ -45,8 +45,8 @@ namespace StardewModdingAPI.Web.Framework.Clients.UpdateManifest /// <returns>The mod URL for the given subkey, or <see langword="null"/> if this manifest does not contain the given subkey.</returns> public override string? GetUrl(string? subkey) { - return subkey is not null && this.Mods.TryGetValue(subkey.TrimStart('@'), out UpdateManifestModModel? modModel) - ? modModel.Url + return subkey is not null && this.Mods.TryGetValue(subkey.TrimStart('@'), out UpdateManifestModModel? mod) + ? mod.ModPageUrl : null; } @@ -63,11 +63,8 @@ namespace StardewModdingAPI.Web.Framework.Clients.UpdateManifest foreach ((string modKey, UpdateManifestModModel mod) in mods) { - if (mod.Versions is null) - continue; - foreach (UpdateManifestVersionModel version in mod.Versions) - yield return new UpdateManifestModDownload(modKey, mod.Name ?? modKey, version.Version, version.DownloadFileUrl ?? version.DownloadPageUrl); + yield return new UpdateManifestModDownload(modKey, mod.Name ?? modKey, version.Version, version.ModPageUrl); } } |