summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI.Web/Framework')
-rw-r--r--src/SMAPI.Web/Framework/Clients/GitHub/GitHubClient.cs2
-rw-r--r--src/SMAPI.Web/Framework/Clients/GitHub/GitRelease.cs4
-rw-r--r--src/SMAPI.Web/Framework/LogParsing/LogParser.cs1
-rw-r--r--src/SMAPI.Web/Framework/LogParsing/Models/ParsedLog.cs3
-rw-r--r--src/SMAPI.Web/Framework/RewriteRules/RedirectToUrlRule.cs20
5 files changed, 17 insertions, 13 deletions
diff --git a/src/SMAPI.Web/Framework/Clients/GitHub/GitHubClient.cs b/src/SMAPI.Web/Framework/Clients/GitHub/GitHubClient.cs
index 4abe0737..2cfc6903 100644
--- a/src/SMAPI.Web/Framework/Clients/GitHub/GitHubClient.cs
+++ b/src/SMAPI.Web/Framework/Clients/GitHub/GitHubClient.cs
@@ -59,7 +59,7 @@ namespace StardewModdingAPI.Web.Framework.Clients.GitHub
GitRelease[] results = await this.Client
.GetAsync(string.Format(this.AnyReleaseUrlFormat, repo))
.AsArray<GitRelease>();
- return results.FirstOrDefault();
+ return results.FirstOrDefault(p => !p.IsDraft);
}
return await this.Client
diff --git a/src/SMAPI.Web/Framework/Clients/GitHub/GitRelease.cs b/src/SMAPI.Web/Framework/Clients/GitHub/GitRelease.cs
index 827374fb..d0db5297 100644
--- a/src/SMAPI.Web/Framework/Clients/GitHub/GitRelease.cs
+++ b/src/SMAPI.Web/Framework/Clients/GitHub/GitRelease.cs
@@ -19,6 +19,10 @@ namespace StardewModdingAPI.Web.Framework.Clients.GitHub
/// <summary>The Markdown description for the release.</summary>
public string Body { get; set; }
+ /// <summary>Whether this is a draft version.</summary>
+ [JsonProperty("draft")]
+ public bool IsDraft { get; set; }
+
/// <summary>Whether this is a prerelease version.</summary>
[JsonProperty("prerelease")]
public bool IsPrerelease { get; set; }
diff --git a/src/SMAPI.Web/Framework/LogParsing/LogParser.cs b/src/SMAPI.Web/Framework/LogParsing/LogParser.cs
index 9e44f163..f49fb05c 100644
--- a/src/SMAPI.Web/Framework/LogParsing/LogParser.cs
+++ b/src/SMAPI.Web/Framework/LogParsing/LogParser.cs
@@ -135,6 +135,7 @@ namespace StardewModdingAPI.Web.Framework.LogParsing
{
Match match = this.ModPathPattern.Match(message.Text);
log.ModPath = match.Groups["path"].Value;
+ log.GamePath = new FileInfo(log.ModPath).Directory.FullName;
}
// log UTC timestamp line
diff --git a/src/SMAPI.Web/Framework/LogParsing/Models/ParsedLog.cs b/src/SMAPI.Web/Framework/LogParsing/Models/ParsedLog.cs
index a82b6a1b..87b20eb0 100644
--- a/src/SMAPI.Web/Framework/LogParsing/Models/ParsedLog.cs
+++ b/src/SMAPI.Web/Framework/LogParsing/Models/ParsedLog.cs
@@ -32,6 +32,9 @@ namespace StardewModdingAPI.Web.Framework.LogParsing.Models
/// <summary>The player's operating system.</summary>
public string OperatingSystem { get; set; }
+ /// <summary>The game install path.</summary>
+ public string GamePath { get; set; }
+
/// <summary>The mod folder path.</summary>
public string ModPath { get; set; }
diff --git a/src/SMAPI.Web/Framework/RewriteRules/RedirectToUrlRule.cs b/src/SMAPI.Web/Framework/RewriteRules/RedirectToUrlRule.cs
index 0719e311..4bae0b4c 100644
--- a/src/SMAPI.Web/Framework/RewriteRules/RedirectToUrlRule.cs
+++ b/src/SMAPI.Web/Framework/RewriteRules/RedirectToUrlRule.cs
@@ -12,11 +12,8 @@ namespace StardewModdingAPI.Web.Framework.RewriteRules
/*********
** Properties
*********/
- /// <summary>A predicate which indicates when the rule should be applied.</summary>
- private readonly Func<HttpRequest, bool> ShouldRewrite;
-
- /// <summary>The new URL to which to redirect.</summary>
- private readonly string NewUrl;
+ /// <summary>Get the new URL to which to redirect (or <c>null</c> to skip).</summary>
+ private readonly Func<HttpRequest, string> NewUrl;
/*********
@@ -27,8 +24,7 @@ namespace StardewModdingAPI.Web.Framework.RewriteRules
/// <param name="url">The new URL to which to redirect.</param>
public RedirectToUrlRule(Func<HttpRequest, bool> shouldRewrite, string url)
{
- this.ShouldRewrite = shouldRewrite ?? (req => true);
- this.NewUrl = url;
+ this.NewUrl = req => shouldRewrite(req) ? url : null;
}
/// <summary>Construct an instance.</summary>
@@ -37,8 +33,7 @@ namespace StardewModdingAPI.Web.Framework.RewriteRules
public RedirectToUrlRule(string pathRegex, string url)
{
Regex regex = new Regex(pathRegex, RegexOptions.IgnoreCase | RegexOptions.Compiled);
- this.ShouldRewrite = req => req.Path.HasValue && regex.IsMatch(req.Path.Value);
- this.NewUrl = url;
+ this.NewUrl = req => req.Path.HasValue ? regex.Replace(req.Path.Value, url) : null;
}
/// <summary>Applies the rule. Implementations of ApplyRule should set the value for <see cref="RewriteContext.Result" /> (defaults to RuleResult.ContinueRules).</summary>
@@ -47,14 +42,15 @@ namespace StardewModdingAPI.Web.Framework.RewriteRules
{
HttpRequest request = context.HttpContext.Request;
- // check condition
- if (!this.ShouldRewrite(request))
+ // check rewrite
+ string newUrl = this.NewUrl(request);
+ if (newUrl == null || newUrl == request.Path.Value)
return;
// redirect request
HttpResponse response = context.HttpContext.Response;
response.StatusCode = (int)HttpStatusCode.Redirect;
- response.Headers["Location"] = this.NewUrl;
+ response.Headers["Location"] = newUrl;
context.Result = RuleResult.EndResponse;
}
}