fix incorrect link URLs in some cases

This commit is contained in:
Jesse Plamondon-Willard 2019-12-01 22:24:01 -05:00
parent 5f532c259d
commit 8a11d5c0d9
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
10 changed files with 61 additions and 26 deletions

View File

@ -151,7 +151,7 @@ namespace StardewModdingAPI.Web.Controllers
return this.View("Index", new JsonValidatorModel(result.ID, schemaName, this.SchemaFormats).SetUploadError($"Pastebin error: {result.Error ?? "unknown error"}")); return this.View("Index", new JsonValidatorModel(result.ID, schemaName, this.SchemaFormats).SetUploadError($"Pastebin error: {result.Error ?? "unknown error"}"));
// redirect to view // redirect to view
return this.Redirect(this.Url.Action("Index", "LogParser", new { schemaName = schemaName, id = result.ID })); return this.Redirect(this.Url.PlainAction("Index", "LogParser", new { schemaName = schemaName, id = result.ID }));
} }

View File

@ -98,7 +98,7 @@ namespace StardewModdingAPI.Web.Controllers
return this.View("Index", this.GetModel(null, uploadError: uploadResult.UploadError)); return this.View("Index", this.GetModel(null, uploadError: uploadResult.UploadError));
// redirect to view // redirect to view
return this.Redirect(this.Url.Action("Index", "LogParser", new { id = uploadResult.ID })); return this.Redirect(this.Url.PlainAction("Index", "LogParser", new { id = uploadResult.ID }));
} }

View File

@ -11,6 +11,7 @@ using StardewModdingAPI.Toolkit.Framework.Clients.WebApi;
using StardewModdingAPI.Toolkit.Framework.Clients.Wiki; using StardewModdingAPI.Toolkit.Framework.Clients.Wiki;
using StardewModdingAPI.Toolkit.Framework.ModData; using StardewModdingAPI.Toolkit.Framework.ModData;
using StardewModdingAPI.Toolkit.Framework.UpdateData; using StardewModdingAPI.Toolkit.Framework.UpdateData;
using StardewModdingAPI.Web.Framework;
using StardewModdingAPI.Web.Framework.Caching.Mods; using StardewModdingAPI.Web.Framework.Caching.Mods;
using StardewModdingAPI.Web.Framework.Caching.Wiki; using StardewModdingAPI.Web.Framework.Caching.Wiki;
using StardewModdingAPI.Web.Framework.Clients.Chucklefish; using StardewModdingAPI.Web.Framework.Clients.Chucklefish;
@ -201,7 +202,7 @@ namespace StardewModdingAPI.Web.Controllers
// get unofficial version // get unofficial version
if (wikiEntry?.Compatibility.UnofficialVersion != null && this.IsNewer(wikiEntry.Compatibility.UnofficialVersion, main?.Version) && this.IsNewer(wikiEntry.Compatibility.UnofficialVersion, optional?.Version)) if (wikiEntry?.Compatibility.UnofficialVersion != null && this.IsNewer(wikiEntry.Compatibility.UnofficialVersion, main?.Version) && this.IsNewer(wikiEntry.Compatibility.UnofficialVersion, optional?.Version))
unofficial = new ModEntryVersionModel(wikiEntry.Compatibility.UnofficialVersion, $"{this.Url.Action("Index", "Mods")}#{wikiEntry.Anchor}"); unofficial = new ModEntryVersionModel(wikiEntry.Compatibility.UnofficialVersion, $"{this.Url.PlainAction("Index", "Mods")}#{wikiEntry.Anchor}");
// get unofficial version for beta // get unofficial version for beta
if (wikiEntry?.HasBetaInfo == true) if (wikiEntry?.HasBetaInfo == true)
@ -211,7 +212,7 @@ namespace StardewModdingAPI.Web.Controllers
if (wikiEntry.BetaCompatibility.UnofficialVersion != null) if (wikiEntry.BetaCompatibility.UnofficialVersion != null)
{ {
unofficialForBeta = (wikiEntry.BetaCompatibility.UnofficialVersion != null && this.IsNewer(wikiEntry.BetaCompatibility.UnofficialVersion, main?.Version) && this.IsNewer(wikiEntry.BetaCompatibility.UnofficialVersion, optional?.Version)) unofficialForBeta = (wikiEntry.BetaCompatibility.UnofficialVersion != null && this.IsNewer(wikiEntry.BetaCompatibility.UnofficialVersion, main?.Version) && this.IsNewer(wikiEntry.BetaCompatibility.UnofficialVersion, optional?.Version))
? new ModEntryVersionModel(wikiEntry.BetaCompatibility.UnofficialVersion, $"{this.Url.Action("Index", "Mods")}#{wikiEntry.Anchor}") ? new ModEntryVersionModel(wikiEntry.BetaCompatibility.UnofficialVersion, $"{this.Url.PlainAction("Index", "Mods")}#{wikiEntry.Anchor}")
: null; : null;
} }
else else

View File

@ -0,0 +1,28 @@
using JetBrains.Annotations;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
namespace StardewModdingAPI.Web.Framework
{
/// <summary>Provides extensions on ASP.NET Core types.</summary>
public static class Extensions
{
/// <summary>Get a URL with the absolute path for an action method. Unlike <see cref="IUrlHelper.Action"/>, only the specified <paramref name="values"/> are added to the URL without merging values from the current HTTP request.</summary>
/// <param name="helper">The URL helper to extend.</param>
/// <param name="action">The name of the action method.</param>
/// <param name="controller">The name of the controller.</param>
/// <param name="values">An object that contains route values.</param>
/// <returns>The generated URL.</returns>
public static string PlainAction(this IUrlHelper helper, [AspMvcAction] string action, [AspMvcController] string controller, object values = null)
{
RouteValueDictionary valuesDict = new RouteValueDictionary(values);
foreach (var value in helper.ActionContext.RouteData.Values)
{
if (!valuesDict.ContainsKey(value.Key))
valuesDict[value.Key] = null; // explicitly remove it from the URL
}
return helper.Action(action, controller, valuesDict);
}
}
}

View File

@ -17,6 +17,7 @@
<PackageReference Include="Hangfire.Mongo" Version="0.6.5" /> <PackageReference Include="Hangfire.Mongo" Version="0.6.5" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.16" /> <PackageReference Include="HtmlAgilityPack" Version="1.11.16" />
<PackageReference Include="Humanizer.Core" Version="2.7.9" /> <PackageReference Include="Humanizer.Core" Version="2.7.9" />
<PackageReference Include="JetBrains.Annotations" Version="2019.1.3" />
<PackageReference Include="Markdig" Version="0.18.0" /> <PackageReference Include="Markdig" Version="0.18.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" /> <PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" /> <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />

View File

@ -1,4 +1,5 @@
@using Microsoft.Extensions.Options @using Microsoft.Extensions.Options
@using StardewModdingAPI.Web.Framework
@using StardewModdingAPI.Web.Framework.ConfigModels @using StardewModdingAPI.Web.Framework.ConfigModels
@inject IOptions<SiteConfig> SiteConfig @inject IOptions<SiteConfig> SiteConfig
@model StardewModdingAPI.Web.ViewModels.IndexModel @model StardewModdingAPI.Web.ViewModels.IndexModel
@ -44,14 +45,14 @@
} }
<div><a href="https://stardewvalleywiki.com/Modding:Player_Guide" class="secondary-cta">Player guide</a></div> <div><a href="https://stardewvalleywiki.com/Modding:Player_Guide" class="secondary-cta">Player guide</a></div>
<div class="sublinks"> <div class="sublinks">
<a href="https://github.com/Pathoschild/SMAPI">source code</a> | <a href="@Url.Action("Privacy", "Index")">privacy</a> <a href="https://github.com/Pathoschild/SMAPI">source code</a> | <a href="@Url.PlainAction("Privacy", "Index")">privacy</a>
</div> </div>
<img id="pufferchick" src="Content/images/pufferchick.png" /> <img id="pufferchick" src="Content/images/pufferchick.png" />
</div> </div>
<h2 id="help">Get help</h2> <h2 id="help">Get help</h2>
<ul> <ul>
<li><a href="@Url.Action("Index", "Mods")">Mod compatibility list</a></li> <li><a href="@Url.PlainAction("Index", "Mods")">Mod compatibility list</a></li>
<li>Get help <a href="https://smapi.io/community">on Discord or in the forums</a></li> <li>Get help <a href="https://smapi.io/community">on Discord or in the forums</a></li>
</ul> </ul>
@ -61,7 +62,7 @@
<div class="github-description"> <div class="github-description">
@Html.Raw(Markdig.Markdown.ToHtml(Model.StableVersion.Description)) @Html.Raw(Markdig.Markdown.ToHtml(Model.StableVersion.Description))
</div> </div>
<p>See the <a href="https://github.com/Pathoschild/SMAPI/blob/develop/docs/release-notes.md#release-notes">release notes</a> and <a href="@Url.Action("Index", "Mods")">mod compatibility list</a> for more info.</p> <p>See the <a href="https://github.com/Pathoschild/SMAPI/blob/develop/docs/release-notes.md#release-notes">release notes</a> and <a href="@Url.PlainAction("Index", "Mods")">mod compatibility list</a> for more info.</p>
} }
else else
{ {
@ -70,13 +71,13 @@ else
<div class="github-description"> <div class="github-description">
@Html.Raw(Markdig.Markdown.ToHtml(Model.StableVersion.Description)) @Html.Raw(Markdig.Markdown.ToHtml(Model.StableVersion.Description))
</div> </div>
<p>See the <a href="https://github.com/Pathoschild/SMAPI/blob/develop/docs/release-notes.md#release-notes">release notes</a> and <a href="@Url.Action("Index", "Mods")">mod compatibility list</a> for more info.</p> <p>See the <a href="https://github.com/Pathoschild/SMAPI/blob/develop/docs/release-notes.md#release-notes">release notes</a> and <a href="@Url.PlainAction("Index", "Mods")">mod compatibility list</a> for more info.</p>
<h3>SMAPI @Model.BetaVersion.Version?</h3> <h3>SMAPI @Model.BetaVersion.Version?</h3>
<div class="github-description"> <div class="github-description">
@Html.Raw(Markdig.Markdown.ToHtml(Model.BetaVersion.Description)) @Html.Raw(Markdig.Markdown.ToHtml(Model.BetaVersion.Description))
</div> </div>
<p>See the <a href="https://github.com/Pathoschild/SMAPI/blob/develop/docs/release-notes.md#release-notes">release notes</a> and <a href="@Url.Action("Index", "Mods")">mod compatibility list</a> for more info.</p> <p>See the <a href="https://github.com/Pathoschild/SMAPI/blob/develop/docs/release-notes.md#release-notes">release notes</a> and <a href="@Url.PlainAction("Index", "Mods")">mod compatibility list</a> for more info.</p>
} }
<h2 id="donate">Support SMAPI ♥</h2> <h2 id="donate">Support SMAPI ♥</h2>

View File

@ -1,4 +1,5 @@
@using Microsoft.Extensions.Options @using Microsoft.Extensions.Options
@using StardewModdingAPI.Web.Framework
@using StardewModdingAPI.Web.Framework.ConfigModels @using StardewModdingAPI.Web.Framework.ConfigModels
@inject IOptions<SiteConfig> SiteConfig @inject IOptions<SiteConfig> SiteConfig
@{ @{
@ -8,7 +9,7 @@
<link rel="stylesheet" href="~/Content/css/privacy.css" /> <link rel="stylesheet" href="~/Content/css/privacy.css" />
} }
&larr; <a href="@Url.Action("Index", "Index")">back to SMAPI page</a> &larr; <a href="@Url.PlainAction("Index", "Index")">back to SMAPI page</a>
<p>SMAPI is an <a href="https://github.com/Pathoschild/SMAPI">open-source</a> and non-profit project. Your privacy is important, so this page explains what information SMAPI uses and transmits. <strong>This page is informational only, it's not a legal document.</strong></p> <p>SMAPI is an <a href="https://github.com/Pathoschild/SMAPI">open-source</a> and non-profit project. Your privacy is important, so this page explains what information SMAPI uses and transmits. <strong>This page is informational only, it's not a legal document.</strong></p>

View File

@ -1,10 +1,11 @@
@using StardewModdingAPI.Web.Framework
@using StardewModdingAPI.Web.ViewModels.JsonValidator @using StardewModdingAPI.Web.ViewModels.JsonValidator
@model JsonValidatorModel @model JsonValidatorModel
@{ @{
// get view data // get view data
string curPageUrl = this.Url.Action("Index", "JsonValidator", new { schemaName = Model.SchemaName, id = Model.PasteID }); string curPageUrl = this.Url.PlainAction("Index", "JsonValidator", new { schemaName = Model.SchemaName, id = Model.PasteID });
string newUploadUrl = this.Url.Action("Index", "JsonValidator", new { schemaName = Model.SchemaName }); string newUploadUrl = this.Url.PlainAction("Index", "JsonValidator", new { schemaName = Model.SchemaName });
string schemaDisplayName = null; string schemaDisplayName = null;
bool isValidSchema = Model.SchemaName != null && Model.SchemaFormats.TryGetValue(Model.SchemaName, out schemaDisplayName) && schemaDisplayName != "None"; bool isValidSchema = Model.SchemaName != null && Model.SchemaFormats.TryGetValue(Model.SchemaName, out schemaDisplayName) && schemaDisplayName != "None";
@ -35,7 +36,7 @@
<script src="~/Content/js/json-validator.js"></script> <script src="~/Content/js/json-validator.js"></script>
<script> <script>
$(function() { $(function() {
smapi.jsonValidator(@Json.Serialize(this.Url.Action("Index", "JsonValidator")), @Json.Serialize(Model.PasteID)); smapi.jsonValidator(@Json.Serialize(this.Url.PlainAction("Index", "JsonValidator", values: null)), @Json.Serialize(Model.PasteID));
}); });
</script> </script>
} }
@ -70,7 +71,7 @@ else if (Model.PasteID != null)
@if (Model.Content == null) @if (Model.Content == null)
{ {
<h2>Upload a JSON file</h2> <h2>Upload a JSON file</h2>
<form action="@this.Url.Action("PostAsync", "JsonValidator")" method="post"> <form action="@this.Url.PlainAction("PostAsync", "JsonValidator")" method="post">
<ol> <ol>
<li> <li>
Choose the JSON format:<br /> Choose the JSON format:<br />

View File

@ -1,6 +1,7 @@
@using Humanizer @using Humanizer
@using Newtonsoft.Json @using Newtonsoft.Json
@using StardewModdingAPI.Toolkit.Utilities @using StardewModdingAPI.Toolkit.Utilities
@using StardewModdingAPI.Web.Framework
@using StardewModdingAPI.Web.Framework.LogParsing.Models @using StardewModdingAPI.Web.Framework.LogParsing.Models
@model StardewModdingAPI.Web.ViewModels.LogParserModel @model StardewModdingAPI.Web.ViewModels.LogParserModel
@ -32,7 +33,7 @@
showSections: @Json.Serialize(Enum.GetNames(typeof(LogSection)).ToDictionary(section => section, section => false), noFormatting), showSections: @Json.Serialize(Enum.GetNames(typeof(LogSection)).ToDictionary(section => section, section => false), noFormatting),
showLevels: @Json.Serialize(defaultFilters, noFormatting), showLevels: @Json.Serialize(defaultFilters, noFormatting),
enableFilters: @Json.Serialize(!Model.ShowRaw) enableFilters: @Json.Serialize(!Model.ShowRaw)
}, '@this.Url.Action("Index", "LogParser")'); }, '@this.Url.PlainAction("Index", "LogParser", values: null)');
}); });
</script> </script>
} }
@ -49,8 +50,8 @@ else if (Model.ParseError != null)
{ {
<div class="banner error" v-pre> <div class="banner error" v-pre>
<strong>Oops, couldn't parse that log. (Make sure you upload the log file, not the console text.)</strong><br /> <strong>Oops, couldn't parse that log. (Make sure you upload the log file, not the console text.)</strong><br />
Share this URL when asking for help: <code>https://@this.Context.Request.Host.ToUriComponent()@this.Url.Action("Index", "LogParser", new { id = Model.PasteID }))</code><br /> Share this URL when asking for help: <code>https://@this.Context.Request.Host.ToUriComponent()@this.Url.PlainAction("Index", "LogParser", new { id = Model.PasteID }))</code><br />
(Or <a href="@this.Url.Action("Index", "LogParser")">upload a new log</a>.)<br /> (Or <a href="@this.Url.PlainAction("Index", "LogParser", values: null)">upload a new log</a>.)<br />
<br /> <br />
<small v-pre>Error details: @Model.ParseError</small> <small v-pre>Error details: @Model.ParseError</small>
</div> </div>
@ -58,8 +59,8 @@ else if (Model.ParseError != null)
else if (Model.ParsedLog?.IsValid == true) else if (Model.ParsedLog?.IsValid == true)
{ {
<div class="banner success" v-pre> <div class="banner success" v-pre>
<strong>Share this link to let someone else see the log:</strong> <code>https://@this.Context.Request.Host.ToUriComponent()@this.Url.Action("Index", "LogParser", new { id = Model.PasteID })</code><br /> <strong>Share this link to let someone else see the log:</strong> <code>https://@this.Context.Request.Host.ToUriComponent()@this.Url.PlainAction("Index", "LogParser", new { id = Model.PasteID })</code><br />
(Or <a href="@this.Url.Action("Index", "LogParser")">upload a new log</a>.) (Or <a href="@this.Url.PlainAction("Index", "LogParser", values: null)">upload a new log</a>.)
</div> </div>
} }
@ -127,7 +128,7 @@ else if (Model.ParsedLog?.IsValid == true)
</div> </div>
<h2>How do I share my log?</h2> <h2>How do I share my log?</h2>
<form action="@this.Url.Action("PostAsync", "LogParser")" method="post"> <form action="@this.Url.PlainAction("PostAsync", "LogParser")" method="post">
<ol> <ol>
<li> <li>
Drag the file onto this textbox (or paste the text in):<br /> Drag the file onto this textbox (or paste the text in):<br />
@ -322,12 +323,12 @@ else if (Model.ParsedLog?.IsValid == true)
} }
</table> </table>
<small><a href="@this.Url.Action("Index", "LogParser", new { id = Model.PasteID })?raw=true">view raw log</a></small> <small><a href="@this.Url.PlainAction("Index", "LogParser", new { id = Model.PasteID, raw = true })">view raw log</a></small>
} }
else else
{ {
<pre v-pre>@Model.ParsedLog.RawText</pre> <pre v-pre>@Model.ParsedLog.RawText</pre>
<small><a href="@this.Url.Action("Index", "LogParser", new { id = Model.PasteID })">view parsed log</a></small> <small><a href="@this.Url.PlainAction("Index", "LogParser", new { id = Model.PasteID })">view parsed log</a></small>
} }
</div> </div>
} }

View File

@ -1,4 +1,5 @@
@using Microsoft.Extensions.Options @using Microsoft.Extensions.Options
@using StardewModdingAPI.Web.Framework
@using StardewModdingAPI.Web.Framework.ConfigModels @using StardewModdingAPI.Web.Framework.ConfigModels
@inject IOptions<SiteConfig> SiteConfig @inject IOptions<SiteConfig> SiteConfig
@ -15,15 +16,15 @@
<div id="sidebar"> <div id="sidebar">
<h4>SMAPI</h4> <h4>SMAPI</h4>
<ul> <ul>
<li><a href="@Url.Action("Index", "Index")">About SMAPI</a></li> <li><a href="@Url.PlainAction("Index", "Index")">About SMAPI</a></li>
<li><a href="https://stardewvalleywiki.com/Modding:Index">Modding docs</a></li> <li><a href="https://stardewvalleywiki.com/Modding:Index">Modding docs</a></li>
</ul> </ul>
<h4>Tools</h4> <h4>Tools</h4>
<ul> <ul>
<li><a href="@Url.Action("Index", "Mods")">Mod compatibility</a></li> <li><a href="@Url.PlainAction("Index", "Mods")">Mod compatibility</a></li>
<li><a href="@Url.Action("Index", "LogParser")">Log parser</a></li> <li><a href="@Url.PlainAction("Index", "LogParser", values: null)">Log parser</a></li>
<li><a href="@Url.Action("Index", "JsonValidator")">JSON validator</a></li> <li><a href="@Url.PlainAction("Index", "JsonValidator", values: null)">JSON validator</a></li>
</ul> </ul>
</div> </div>
<div id="content-column"> <div id="content-column">