summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI.Web/Framework/ModRepositories
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-09-25 21:21:27 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-09-25 21:21:27 -0400
commit2c87961c9e47aeba6eb7dbfca234cc457cb02158 (patch)
treed95c1d6a0fd4ce72d7c331b2950bfe1fc84cd6f2 /src/StardewModdingAPI.Web/Framework/ModRepositories
parent5cb183e16ddc661c38f4bd9e6e740b9457b8c437 (diff)
downloadSMAPI-2c87961c9e47aeba6eb7dbfca234cc457cb02158.tar.gz
SMAPI-2c87961c9e47aeba6eb7dbfca234cc457cb02158.tar.bz2
SMAPI-2c87961c9e47aeba6eb7dbfca234cc457cb02158.zip
improve mod update-check validation & errors (#336)
Diffstat (limited to 'src/StardewModdingAPI.Web/Framework/ModRepositories')
-rw-r--r--src/StardewModdingAPI.Web/Framework/ModRepositories/ChucklefishRepository.cs5
-rw-r--r--src/StardewModdingAPI.Web/Framework/ModRepositories/GitHubRepository.cs10
-rw-r--r--src/StardewModdingAPI.Web/Framework/ModRepositories/NexusRepository.cs5
3 files changed, 20 insertions, 0 deletions
diff --git a/src/StardewModdingAPI.Web/Framework/ModRepositories/ChucklefishRepository.cs b/src/StardewModdingAPI.Web/Framework/ModRepositories/ChucklefishRepository.cs
index 4822c414..ed7bd60b 100644
--- a/src/StardewModdingAPI.Web/Framework/ModRepositories/ChucklefishRepository.cs
+++ b/src/StardewModdingAPI.Web/Framework/ModRepositories/ChucklefishRepository.cs
@@ -43,6 +43,11 @@ namespace StardewModdingAPI.Web.Framework.ModRepositories
/// <param name="id">The mod ID in this repository.</param>
public override async Task<ModInfoModel> GetModInfoAsync(string id)
{
+ // validate ID format
+ if (!uint.TryParse(id, out uint _))
+ return new ModInfoModel($"The value '{id}' isn't a valid Chucklefish mod ID, must be an integer ID.");
+
+ // fetch info
try
{
// fetch HTML
diff --git a/src/StardewModdingAPI.Web/Framework/ModRepositories/GitHubRepository.cs b/src/StardewModdingAPI.Web/Framework/ModRepositories/GitHubRepository.cs
index 7dfe9f62..174fb79a 100644
--- a/src/StardewModdingAPI.Web/Framework/ModRepositories/GitHubRepository.cs
+++ b/src/StardewModdingAPI.Web/Framework/ModRepositories/GitHubRepository.cs
@@ -1,4 +1,5 @@
using System;
+using System.Net;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Pathoschild.Http.Client;
@@ -46,6 +47,11 @@ namespace StardewModdingAPI.Web.Framework.ModRepositories
/// <param name="id">The mod ID in this repository.</param>
public override async Task<ModInfoModel> GetModInfoAsync(string id)
{
+ // validate ID format
+ if (!id.Contains("/") || id.IndexOf("/", StringComparison.InvariantCultureIgnoreCase) != id.LastIndexOf("/", StringComparison.InvariantCultureIgnoreCase))
+ return new ModInfoModel($"The value '{id}' isn't a valid GitHub mod ID, must be a username and project name like 'Pathoschild/LookupAnything'.");
+
+ // fetch info
try
{
GitRelease release = await this.Client
@@ -53,6 +59,10 @@ namespace StardewModdingAPI.Web.Framework.ModRepositories
.As<GitRelease>();
return new ModInfoModel(id, this.NormaliseVersion(release.Tag), $"https://github.com/{id}/releases");
}
+ catch (ApiException ex) when (ex.Status == HttpStatusCode.NotFound)
+ {
+ return new ModInfoModel("Found no mod with this ID.");
+ }
catch (Exception ex)
{
return new ModInfoModel(ex.ToString());
diff --git a/src/StardewModdingAPI.Web/Framework/ModRepositories/NexusRepository.cs b/src/StardewModdingAPI.Web/Framework/ModRepositories/NexusRepository.cs
index e679b977..71970bec 100644
--- a/src/StardewModdingAPI.Web/Framework/ModRepositories/NexusRepository.cs
+++ b/src/StardewModdingAPI.Web/Framework/ModRepositories/NexusRepository.cs
@@ -38,6 +38,11 @@ namespace StardewModdingAPI.Web.Framework.ModRepositories
/// <param name="id">The mod ID in this repository.</param>
public override async Task<ModInfoModel> GetModInfoAsync(string id)
{
+ // validate ID format
+ if (!uint.TryParse(id, out uint _))
+ return new ModInfoModel($"The value '{id}' isn't a valid Nexus mod ID, must be an integer ID.");
+
+ // fetch info
try
{
NexusResponseModel response = await this.Client