summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/Framework/Clients/ModDrop
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI.Web/Framework/Clients/ModDrop')
-rw-r--r--src/SMAPI.Web/Framework/Clients/ModDrop/IModDropClient.cs12
-rw-r--r--src/SMAPI.Web/Framework/Clients/ModDrop/ModDropClient.cs63
-rw-r--r--src/SMAPI.Web/Framework/Clients/ModDrop/ModDropMod.cs21
-rw-r--r--src/SMAPI.Web/Framework/Clients/ModDrop/ResponseModels/FileDataModel.cs16
4 files changed, 42 insertions, 70 deletions
diff --git a/src/SMAPI.Web/Framework/Clients/ModDrop/IModDropClient.cs b/src/SMAPI.Web/Framework/Clients/ModDrop/IModDropClient.cs
index 3ede46e2..468b72b1 100644
--- a/src/SMAPI.Web/Framework/Clients/ModDrop/IModDropClient.cs
+++ b/src/SMAPI.Web/Framework/Clients/ModDrop/IModDropClient.cs
@@ -1,17 +1,7 @@
using System;
-using System.Threading.Tasks;
namespace StardewModdingAPI.Web.Framework.Clients.ModDrop
{
/// <summary>An HTTP client for fetching mod metadata from the ModDrop API.</summary>
- internal interface IModDropClient : IDisposable
- {
- /*********
- ** Methods
- *********/
- /// <summary>Get metadata about a mod.</summary>
- /// <param name="id">The ModDrop mod ID.</param>
- /// <returns>Returns the mod info if found, else <c>null</c>.</returns>
- Task<ModDropMod> GetModAsync(long id);
- }
+ internal interface IModDropClient : IDisposable, IModSiteClient { }
}
diff --git a/src/SMAPI.Web/Framework/Clients/ModDrop/ModDropClient.cs b/src/SMAPI.Web/Framework/Clients/ModDrop/ModDropClient.cs
index 5ad2d2f8..3a1c5b9d 100644
--- a/src/SMAPI.Web/Framework/Clients/ModDrop/ModDropClient.cs
+++ b/src/SMAPI.Web/Framework/Clients/ModDrop/ModDropClient.cs
@@ -1,6 +1,7 @@
+using System.Collections.Generic;
using System.Threading.Tasks;
using Pathoschild.Http.Client;
-using StardewModdingAPI.Toolkit;
+using StardewModdingAPI.Toolkit.Framework.UpdateData;
using StardewModdingAPI.Web.Framework.Clients.ModDrop.ResponseModels;
namespace StardewModdingAPI.Web.Framework.Clients.ModDrop
@@ -19,6 +20,13 @@ namespace StardewModdingAPI.Web.Framework.Clients.ModDrop
/*********
+ ** Accessors
+ *********/
+ /// <summary>The unique key for the mod site.</summary>
+ public ModSiteKey SiteKey => ModSiteKey.ModDrop;
+
+
+ /*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
@@ -31,60 +39,45 @@ namespace StardewModdingAPI.Web.Framework.Clients.ModDrop
this.ModUrlFormat = modUrlFormat;
}
- /// <summary>Get metadata about a mod.</summary>
- /// <param name="id">The ModDrop mod ID.</param>
- /// <returns>Returns the mod info if found, else <c>null</c>.</returns>
- public async Task<ModDropMod> GetModAsync(long id)
+ /// <summary>Get update check info about a mod.</summary>
+ /// <param name="id">The mod ID.</param>
+ public async Task<IModPage> GetModData(string id)
{
+ var page = new GenericModPage(this.SiteKey, id);
+
+ if (!long.TryParse(id, out long parsedId))
+ return page.SetError(RemoteModStatus.DoesNotExist, $"The value '{id}' isn't a valid ModDrop mod ID, must be an integer ID.");
+
// get raw data
ModListModel response = await this.Client
.PostAsync("")
.WithBody(new
{
- ModIDs = new[] { id },
+ ModIDs = new[] { parsedId },
Files = true,
Mods = true
})
.As<ModListModel>();
- ModModel mod = response.Mods[id];
+ ModModel mod = response.Mods[parsedId];
if (mod.Mod?.Title == null || mod.Mod.ErrorCode.HasValue)
return null;
- // get latest versions
- ISemanticVersion latest = null;
- ISemanticVersion optional = null;
+ // get files
+ var downloads = new List<IModDownload>();
foreach (FileDataModel file in mod.Files)
{
if (file.IsOld || file.IsDeleted || file.IsHidden)
continue;
- if (!SemanticVersion.TryParse(file.Version, out ISemanticVersion version))
- continue;
-
- if (file.IsDefault)
- {
- if (latest == null || version.IsNewerThan(latest))
- latest = version;
- }
- else if (optional == null || version.IsNewerThan(optional))
- optional = version;
+ downloads.Add(
+ new GenericModDownload(file.Name, file.Description, file.Version)
+ );
}
- if (latest == null)
- {
- latest = optional;
- optional = null;
- }
- if (optional != null && latest.IsNewerThan(optional))
- optional = null;
- // generate result
- return new ModDropMod
- {
- Name = mod.Mod?.Title,
- LatestDefaultVersion = latest,
- LatestOptionalVersion = optional,
- Url = string.Format(this.ModUrlFormat, id)
- };
+ // return info
+ string name = mod.Mod?.Title;
+ string url = string.Format(this.ModUrlFormat, id);
+ return page.SetInfo(name: name, version: null, url: url, downloads: downloads);
}
/// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
diff --git a/src/SMAPI.Web/Framework/Clients/ModDrop/ModDropMod.cs b/src/SMAPI.Web/Framework/Clients/ModDrop/ModDropMod.cs
deleted file mode 100644
index def79106..00000000
--- a/src/SMAPI.Web/Framework/Clients/ModDrop/ModDropMod.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-namespace StardewModdingAPI.Web.Framework.Clients.ModDrop
-{
- /// <summary>Mod metadata from the ModDrop API.</summary>
- internal class ModDropMod
- {
- /*********
- ** Accessors
- *********/
- /// <summary>The mod name.</summary>
- public string Name { get; set; }
-
- /// <summary>The latest default file version.</summary>
- public ISemanticVersion LatestDefaultVersion { get; set; }
-
- /// <summary>The latest optional file version.</summary>
- public ISemanticVersion LatestOptionalVersion { get; set; }
-
- /// <summary>The mod's web URL.</summary>
- public string Url { get; set; }
- }
-}
diff --git a/src/SMAPI.Web/Framework/Clients/ModDrop/ResponseModels/FileDataModel.cs b/src/SMAPI.Web/Framework/Clients/ModDrop/ResponseModels/FileDataModel.cs
index fa84b287..b01196f4 100644
--- a/src/SMAPI.Web/Framework/Clients/ModDrop/ResponseModels/FileDataModel.cs
+++ b/src/SMAPI.Web/Framework/Clients/ModDrop/ResponseModels/FileDataModel.cs
@@ -1,8 +1,21 @@
+using Newtonsoft.Json;
+
namespace StardewModdingAPI.Web.Framework.Clients.ModDrop.ResponseModels
{
/// <summary>Metadata from the ModDrop API about a mod file.</summary>
public class FileDataModel
{
+ /// <summary>The file title.</summary>
+ [JsonProperty("title")]
+ public string Name { get; set; }
+
+ /// <summary>The file description.</summary>
+ [JsonProperty("desc")]
+ public string Description { get; set; }
+
+ /// <summary>The file version.</summary>
+ public string Version { get; set; }
+
/// <summary>Whether the file is deleted.</summary>
public bool IsDeleted { get; set; }
@@ -14,8 +27,5 @@ namespace StardewModdingAPI.Web.Framework.Clients.ModDrop.ResponseModels
/// <summary>Whether this is an archived file.</summary>
public bool IsOld { get; set; }
-
- /// <summary>The file version.</summary>
- public string Version { get; set; }
}
}