summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-12-01 21:55:20 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-12-02 20:14:07 -0500
commit5f532c259d5d3050bd6a053659067617db136d57 (patch)
tree06b8bf7ac63ccab8be27908002612a53d5975075
parent8766a79408ce79bd632c1fe1c9b17ab0a7a6a976 (diff)
downloadSMAPI-5f532c259d5d3050bd6a053659067617db136d57.tar.gz
SMAPI-5f532c259d5d3050bd6a053659067617db136d57.tar.bz2
SMAPI-5f532c259d5d3050bd6a053659067617db136d57.zip
migrate from AWS to Azure
This commit migrates from subdomains to paths (due to the cost of a wildcard HTTPS certificate on Azure), adds a web project to redirect the old subdomains from AWS to Azure, and removes AWS-specific hacks.
-rw-r--r--.github/ISSUE_TEMPLATE/bug_report.md2
-rw-r--r--.gitignore5
-rw-r--r--build/prepare-install-package.targets2
-rw-r--r--docs/release-notes.md22
-rw-r--r--docs/technical/web.md12
-rw-r--r--src/SMAPI.Web.LegacyRedirects/Controllers/ModsApiController.cs33
-rw-r--r--src/SMAPI.Web.LegacyRedirects/Framework/LambdaRewriteRule.cs37
-rw-r--r--src/SMAPI.Web.LegacyRedirects/Program.cs23
-rw-r--r--src/SMAPI.Web.LegacyRedirects/Properties/launchSettings.json29
-rw-r--r--src/SMAPI.Web.LegacyRedirects/SMAPI.Web.LegacyRedirects.csproj21
-rw-r--r--src/SMAPI.Web.LegacyRedirects/Startup.cs94
-rw-r--r--src/SMAPI.Web/Controllers/JsonValidatorController.cs24
-rw-r--r--src/SMAPI.Web/Controllers/LogParserController.cs14
-rw-r--r--src/SMAPI.Web/Controllers/ModsApiController.cs8
-rw-r--r--src/SMAPI.Web/Framework/BeanstalkEnvPropsConfigProvider.cs54
-rw-r--r--src/SMAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs3
-rw-r--r--src/SMAPI.Web/Framework/ConfigModels/SiteConfig.cs12
-rw-r--r--src/SMAPI.Web/Framework/RewriteRules/ConditionalRewriteSubdomainRule.cs48
-rw-r--r--src/SMAPI.Web/Startup.cs17
-rw-r--r--src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs7
-rw-r--r--src/SMAPI.Web/ViewModels/LogParserModel.cs7
-rw-r--r--src/SMAPI.Web/Views/Index/Index.cshtml10
-rw-r--r--src/SMAPI.Web/Views/Index/Privacy.cshtml4
-rw-r--r--src/SMAPI.Web/Views/JsonValidator/Index.cshtml10
-rw-r--r--src/SMAPI.Web/Views/LogParser/Index.cshtml16
-rw-r--r--src/SMAPI.Web/Views/Shared/_Layout.cshtml8
-rw-r--r--src/SMAPI.Web/appsettings.Development.json4
-rw-r--r--src/SMAPI.Web/appsettings.json7
-rw-r--r--src/SMAPI.sln6
-rw-r--r--src/SMAPI/Framework/ModLoading/ModResolver.cs2
-rw-r--r--src/SMAPI/Framework/Models/SConfig.cs2
-rw-r--r--src/SMAPI/Framework/SCore.cs4
-rw-r--r--src/SMAPI/SMAPI.config.json2
33 files changed, 311 insertions, 238 deletions
diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
index 74954cf4..c51d164b 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.md
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -24,7 +24,7 @@ Exact steps which reproduce the bug, if possible. For example:
4. Error occurs.
**Log file**
-Upload your SMAPI log to https://log.smapi.io and post a link here.
+Upload your SMAPI log to https://smapi.io/log and post a link here.
**Screenshots**
If applicable, add screenshots to help explain your problem.
diff --git a/.gitignore b/.gitignore
index 7080a8fc..65695211 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,4 +28,7 @@ _ReSharper*/
appsettings.Development.json
# AWS generated files
-src/SMAPI.Web/aws-beanstalk-tools-defaults.json
+src/SMAPI.Web.LegacyRedirects/aws-beanstalk-tools-defaults.json
+
+# Azure generated files
+src/SMAPI.Web/Properties/PublishProfiles/smapi-web-release - Web Deploy.pubxml
diff --git a/build/prepare-install-package.targets b/build/prepare-install-package.targets
index e5286bf5..4297756d 100644
--- a/build/prepare-install-package.targets
+++ b/build/prepare-install-package.targets
@@ -63,7 +63,7 @@
<Copy SourceFiles="$(CompiledModsPath)\SaveBackup\SaveBackup.pdb" DestinationFolder="$(PackagePath)\bundle\Mods\SaveBackup" />
<Copy SourceFiles="$(CompiledModsPath)\SaveBackup\manifest.json" DestinationFolder="$(PackagePath)\bundle\Mods\SaveBackup" />
- <!-- fix errors on Linux/Mac (sample: https://log.smapi.io/mMdFUpgB) -->
+ <!-- fix errors on Linux/Mac (sample: https://smapi.io/log/mMdFUpgB) -->
<Copy Condition="$(OS) != 'Windows_NT'" SourceFiles="$(RootPath)\build\lib\System.Numerics.dll" DestinationFolder="$(PackagePath)\bundle\smapi-internal" />
<Copy Condition="$(OS) != 'Windows_NT'" SourceFiles="$(RootPath)\build\lib\System.Runtime.Caching.dll" DestinationFolder="$(PackagePath)\bundle\smapi-internal" />
diff --git a/docs/release-notes.md b/docs/release-notes.md
index c3840148..dcce70c9 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -110,7 +110,7 @@ For modders:
* Clicking a mod link now automatically adds it to the visible mods if the list is filtered.
* JSON validator:
- * Added JSON validator at [json.smapi.io](https://json.smapi.io), which lets you validate a JSON file against predefined mod formats.
+ * Added JSON validator at [smapi.io/json](https://smapi.io/json), which lets you validate a JSON file against predefined mod formats.
* Added support for the `manifest.json` format.
* Added support for the Content Patcher format (thanks to TehPers!).
* Added support for referencing a schema in a JSON Schema-compatible text editor.
@@ -373,7 +373,7 @@ Released 19 November 2018 for Stardew Valley 1.3.32.
* Updated compatibility list.
* For the web UI:
- * Added a [mod compatibility page](https://mods.smapi.io) and [privacy page](https://smapi.io/privacy).
+ * Added a [mod compatibility page](https://smapi.io/mods) and [privacy page](https://smapi.io/privacy).
* The log parser now has a separate filter for game messages.
* The log parser now shows content pack authors (thanks to danvolchek!).
* Tweaked log parser UI (thanks to danvolchek!).
@@ -557,7 +557,7 @@ Released 11 April 2018 for Stardew Valley 1.2.30–1.2.33.
* Fixed error when two content packs use different capitalization for the same required mod ID.
* Fixed rare crash if the game duplicates an item.
-* For the [log parser](https://log.smapi.io):
+* For the [log parser](https://smapi.io/log):
* Tweaked UI.
## 2.5.4
@@ -569,7 +569,7 @@ Released 26 March 2018 for Stardew Valley 1.2.30–1.2.33.
* Fixed error when mods remove an asset editor/loader.
* Fixed minimum game version incorrectly increased in SMAPI 2.5.3.
-* For the [log parser](https://log.smapi.io):
+* For the [log parser](https://smapi.io/log):
* Fixed error when log text contains certain tokens.
* For modders:
@@ -591,7 +591,7 @@ Released 13 March 2018 for Stardew Valley ~~1.2.30~~–1.2.33.
* Fixed Linux ["magic number is wrong" errors](https://github.com/mono/mono/issues/6752) by changing default terminal order.
* Updated compatibility list and added update checks for more mods.
-* For the [log parser](https://log.smapi.io):
+* For the [log parser](https://smapi.io/log):
* Fixed incorrect filtering in some cases.
* Fixed error if mods have duplicate names.
* Fixed parse bugs if a mod has no author name.
@@ -605,7 +605,7 @@ Released 25 February 2018 for Stardew Valley 1.2.30–1.2.33.
* For modders:
* Fixed issue where replacing an asset through `asset.AsImage()` or `asset.AsDictionary()` didn't take effect.
-* For the [log parser](https://log.smapi.io):
+* For the [log parser](https://smapi.io/log):
* Fixed blank page after uploading a log in some cases.
## 2.5.1
@@ -636,7 +636,7 @@ Released 24 February 2018 for Stardew Valley 1.2.30–1.2.33.
* Fixed unhelpful error when a translation file has duplicate keys due to case-insensitivity.
* Fixed some JSON field names being case-sensitive.
-* For the [log parser](https://log.smapi.io):
+* For the [log parser](https://smapi.io/log):
* Added support for SMAPI 2.5 content packs.
* Reduced download size when viewing a parsed log with repeated errors.
* Improved parse error handling.
@@ -657,7 +657,7 @@ Released 24 January 2018 for Stardew Valley 1.2.30–1.2.33.
* Fixed intermittent errors (e.g. 'collection has been modified') with some mods when loading a save.
* Fixed compatibility with Linux Terminator terminal.
-* For the [log parser](https://log.smapi.io):
+* For the [log parser](https://smapi.io/log):
* Fixed error parsing logs with zero installed mods.
* For modders:
@@ -692,7 +692,7 @@ Released 26 December 2017 for Stardew Valley 1.2.30–1.2.33.
* Fixed issue where a mod could change the cursor position reported to other mods.
* Updated compatibility list.
-* For the [log parser](https://log.smapi.io):
+* For the [log parser](https://smapi.io/log):
* Fixed broken favicon.
## 2.2
@@ -706,7 +706,7 @@ Released 02 December 2017 for Stardew Valley 1.2.30–1.2.33.
* Improved error when a mod has an invalid `EntryDLL` filename format.
* Updated compatibility list.
-* For the [log parser](https://log.smapi.io):
+* For the [log parser](https://smapi.io/log):
* Logs no longer expire after a week.
* Fixed error when uploading very large logs.
* Slightly improved the UI.
@@ -721,7 +721,7 @@ Released 02 December 2017 for Stardew Valley 1.2.30–1.2.33.
Released 01 November 2017 for Stardew Valley 1.2.30–1.2.33.
* For players:
- * Added a [log parser](https://log.smapi.io) site.
+ * Added a [log parser](https://smapi.io/log) site.
* Added better Steam instructions to the SMAPI installer.
* Renamed the bundled _TrainerMod_ to _ConsoleCommands_ to make its purpose clearer.
* Removed the game's test messages from the console log.
diff --git a/docs/technical/web.md b/docs/technical/web.md
index 78d93625..97e0704a 100644
--- a/docs/technical/web.md
+++ b/docs/technical/web.md
@@ -14,13 +14,13 @@ and update check API.
## Log parser
The log parser provides a web UI for uploading, parsing, and sharing SMAPI logs. The logs are
-persisted in a compressed form to Pastebin. The log parser lives at https://log.smapi.io.
+persisted in a compressed form to Pastebin. The log parser lives at https://smapi.io/log.
## JSON validator
### Overview
The JSON validator provides a web UI for uploading and sharing JSON files, and validating them as
plain JSON or against a predefined format like `manifest.json` or Content Patcher's `content.json`.
-The JSON validator lives at https://json.smapi.io.
+The JSON validator lives at https://smapi.io/json.
### Schema file format
Schema files are defined in `wwwroot/schemas` using the [JSON Schema](https://json-schema.org/)
@@ -111,7 +111,7 @@ format | schema URL
## Web API
### Overview
-SMAPI provides a web API at `api.smapi.io` for use by SMAPI and external tools. The URL includes a
+SMAPI provides a web API at `smapi.io/api` for use by SMAPI and external tools. The URL includes a
`{version}` token, which is the SMAPI version for backwards compatibility. This API is publicly
accessible but not officially released; it may change at any time.
@@ -184,7 +184,7 @@ may be useful to external tools.
Example request:
```js
-POST https://api.smapi.io/v3.0/mods
+POST https://smapi.io/api/v3.0/mods
{
"mods": [
{
@@ -350,8 +350,7 @@ To launch the environment:
mongod --dbpath C:\dev\smapi-cache
```
2. Launch `SMAPI.Web` from Visual Studio to run a local version of the site.
- <small>(Local URLs will use HTTP instead of HTTPS, and subdomains will become routes, like
- `log.smapi.io` &rarr; `localhost:59482/log`.)</small>
+ <small>(Local URLs will use HTTP instead of HTTPS.)</small>
### Production environment
A production environment includes the web servers and cache database hosted online for public
@@ -367,7 +366,6 @@ Initial setup:
------------------------------- | -----------------
`LogParser:PastebinDevKey` | The [Pastebin developer key](https://pastebin.com/api#1) used to authenticate with the Pastebin API.
`LogParser:PastebinUserKey` | The [Pastebin user key](https://pastebin.com/api#8) used to authenticate with the Pastebin API. Can be left blank to post anonymously.
- `LogParser:SectionUrl` | The root URL of the log page, like `https://log.smapi.io/`.
`ModUpdateCheck:GitHubPassword` | The password with which to authenticate to GitHub when fetching release info.
`ModUpdateCheck:GitHubUsername` | The username with which to authenticate to GitHub when fetching release info.
`MongoDB:Host` | The hostname for the MongoDB instance.
diff --git a/src/SMAPI.Web.LegacyRedirects/Controllers/ModsApiController.cs b/src/SMAPI.Web.LegacyRedirects/Controllers/ModsApiController.cs
new file mode 100644
index 00000000..44ed0b6b
--- /dev/null
+++ b/src/SMAPI.Web.LegacyRedirects/Controllers/ModsApiController.cs
@@ -0,0 +1,33 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Mvc;
+using Pathoschild.Http.Client;
+using StardewModdingAPI.Toolkit.Framework.Clients.WebApi;
+
+namespace SMAPI.Web.LegacyRedirects.Controllers
+{
+ /// <summary>Provides an API to perform mod update checks.</summary>
+ [ApiController]
+ [Produces("application/json")]
+ [Route("api/v{version}/mods")]
+ public class ModsApiController : Controller
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Fetch version metadata for the given mods.</summary>
+ /// <param name="model">The mod search criteria.</param>
+ [HttpPost]
+ public async Task<IEnumerable<ModEntryModel>> PostAsync([FromBody] ModSearchModel model)
+ {
+ using IClient client = new FluentClient("https://smapi.io/api");
+
+ Startup.ConfigureJsonNet(client.Formatters.JsonFormatter.SerializerSettings);
+
+ return await client
+ .PostAsync(this.Request.Path)
+ .WithBody(model)
+ .AsArray<ModEntryModel>();
+ }
+ }
+}
diff --git a/src/SMAPI.Web.LegacyRedirects/Framework/LambdaRewriteRule.cs b/src/SMAPI.Web.LegacyRedirects/Framework/LambdaRewriteRule.cs
new file mode 100644
index 00000000..e5138e5c
--- /dev/null
+++ b/src/SMAPI.Web.LegacyRedirects/Framework/LambdaRewriteRule.cs
@@ -0,0 +1,37 @@
+using System;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Rewrite;
+
+namespace SMAPI.Web.LegacyRedirects.Framework
+{
+ /// <summary>Rewrite requests to prepend the subdomain portion (if any) to the path.</summary>
+ /// <remarks>Derived from <a href="https://stackoverflow.com/a/44526747/262123" />.</remarks>
+ internal class LambdaRewriteRule : IRule
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>Rewrite an HTTP request if needed.</summary>
+ private readonly Action<RewriteContext, HttpRequest, HttpResponse> Rewrite;
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="rewrite">Rewrite an HTTP request if needed.</param>
+ public LambdaRewriteRule(Action<RewriteContext, HttpRequest, HttpResponse> rewrite)
+ {
+ this.Rewrite = rewrite ?? throw new ArgumentNullException(nameof(rewrite));
+ }
+
+ /// <summary>Applies the rule. Implementations of ApplyRule should set the value for <see cref="RewriteContext.Result" /> (defaults to RuleResult.ContinueRules).</summary>
+ /// <param name="context">The rewrite context.</param>
+ public void ApplyRule(RewriteContext context)
+ {
+ HttpRequest request = context.HttpContext.Request;
+ HttpResponse response = context.HttpContext.Response;
+ this.Rewrite(context, request, response);
+ }
+ }
+}
diff --git a/src/SMAPI.Web.LegacyRedirects/Program.cs b/src/SMAPI.Web.LegacyRedirects/Program.cs
new file mode 100644
index 00000000..6adee877
--- /dev/null
+++ b/src/SMAPI.Web.LegacyRedirects/Program.cs
@@ -0,0 +1,23 @@
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.Hosting;
+
+namespace SMAPI.Web.LegacyRedirects
+{
+ /// <summary>The main app entry point.</summary>
+ public class Program
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>The main app entry point.</summary>
+ /// <param name="args">The command-line arguments.</param>
+ public static void Main(string[] args)
+ {
+ Host
+ .CreateDefaultBuilder(args)
+ .ConfigureWebHostDefaults(builder => builder.UseStartup<Startup>())
+ .Build()
+ .Run();
+ }
+ }
+}
diff --git a/src/SMAPI.Web.LegacyRedirects/Properties/launchSettings.json b/src/SMAPI.Web.LegacyRedirects/Properties/launchSettings.json
new file mode 100644
index 00000000..e9a1b210
--- /dev/null
+++ b/src/SMAPI.Web.LegacyRedirects/Properties/launchSettings.json
@@ -0,0 +1,29 @@
+{
+ "iisSettings": {
+ "windowsAuthentication": false,
+ "anonymousAuthentication": true,
+ "iisExpress": {
+ "applicationUrl": "http://localhost:52756",
+ "sslPort": 0
+ }
+ },
+ "$schema": "http://json.schemastore.org/launchsettings.json",
+ "profiles": {
+ "IIS Express": {
+ "commandName": "IISExpress",
+ "launchBrowser": true,
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ }
+ },
+ "SMAPI.Web.LegacyRedirects": {
+ "commandName": "Project",
+ "launchBrowser": true,
+ "launchUrl": "/",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ },
+ "applicationUrl": "https://localhost:5001;http://localhost:5000"
+ }
+ }
+} \ No newline at end of file
diff --git a/src/SMAPI.Web.LegacyRedirects/SMAPI.Web.LegacyRedirects.csproj b/src/SMAPI.Web.LegacyRedirects/SMAPI.Web.LegacyRedirects.csproj
new file mode 100644
index 00000000..a3d5c2b6
--- /dev/null
+++ b/src/SMAPI.Web.LegacyRedirects/SMAPI.Web.LegacyRedirects.csproj
@@ -0,0 +1,21 @@
+<Project Sdk="Microsoft.NET.Sdk.Web">
+
+ <PropertyGroup>
+ <TargetFramework>netcoreapp3.0</TargetFramework>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <Content Remove="aws-beanstalk-tools-defaults.json" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />
+ <PackageReference Include="Pathoschild.Http.FluentClient" Version="3.3.1" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\SMAPI.Toolkit.CoreInterfaces\SMAPI.Toolkit.CoreInterfaces.csproj" />
+ <ProjectReference Include="..\SMAPI.Toolkit\SMAPI.Toolkit.csproj" />
+ </ItemGroup>
+
+</Project>
diff --git a/src/SMAPI.Web.LegacyRedirects/Startup.cs b/src/SMAPI.Web.LegacyRedirects/Startup.cs
new file mode 100644
index 00000000..4af51575
--- /dev/null
+++ b/src/SMAPI.Web.LegacyRedirects/Startup.cs
@@ -0,0 +1,94 @@
+using System.Net;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore.Rewrite;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
+using Newtonsoft.Json;
+using SMAPI.Web.LegacyRedirects.Framework;
+using StardewModdingAPI.Toolkit.Serialization;
+
+namespace SMAPI.Web.LegacyRedirects
+{
+ /// <summary>The web app startup configuration.</summary>
+ public class Startup
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>The method called by the runtime to add services to the container.</summary>
+ /// <param name="services">The service injection container.</param>
+ public void ConfigureServices(IServiceCollection services)
+ {
+ services
+ .AddControllers()
+ .AddNewtonsoftJson(options => Startup.ConfigureJsonNet(options.SerializerSettings));
+ }
+
+ /// <summary>The method called by the runtime to configure the HTTP request pipeline.</summary>
+ /// <param name="app">The application builder.</param>
+ /// <param name="env">The hosting environment.</param>
+ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
+ {
+ if (env.IsDevelopment())
+ app.UseDeveloperExceptionPage();
+
+ app
+ .UseRewriter(this.GetRedirectRules())
+ .UseRouting()
+ .UseAuthorization()
+ .UseEndpoints(endpoints => endpoints.MapControllers());
+ }
+
+ /// <summary>Configure a Json.NET serializer.</summary>
+ /// <param name="settings">The serializer settings to edit.</param>
+ internal static void ConfigureJsonNet(JsonSerializerSettings settings)
+ {
+ foreach (JsonConverter converter in new JsonHelper().JsonSettings.Converters)
+ settings.Converters.Add(converter);
+
+ settings.Formatting = Formatting.Indented;
+ settings.NullValueHandling = NullValueHandling.Ignore;
+ }
+
+
+ /*********
+ ** Private methods
+ *********/
+ /// <summary>Get the redirect rules to apply.</summary>
+ private RewriteOptions GetRedirectRules()
+ {
+ var redirects = new RewriteOptions();
+
+ redirects.Add(
+ new LambdaRewriteRule((context, request, response) =>
+ {
+ string host = request.Host.Host;
+
+ // map API requests to proxy
+ // This is needed because the low-level HTTP client SMAPI uses for Linux/Mac compatibility doesn't support redirects.
+ if (host == "api.smapi.io")
+ {
+ request.Path = $"/api{request.Path}";
+ return;
+ }
+
+ // redirect other requests to Azure
+ string newRoot = host switch
+ {
+ "api.smapi.io" => "smapi.io/api",
+ "json.smapi.io" => "smapi.io/json",
+ "log.smapi.io" => "smapi.io/log",
+ "mods.smapi.io" => "smapi.io/mods",
+ _ => "smapi.io"
+ };
+ response.StatusCode = (int)HttpStatusCode.PermanentRedirect;
+ response.Headers["Location"] = $"{(request.IsHttps ? "https" : "http")}://{newRoot}{request.PathBase}{request.Path}{request.QueryString}";
+ context.Result = RuleResult.EndResponse;
+ })
+ );
+
+ return redirects;
+ }
+ }
+}
diff --git a/src/SMAPI.Web/Controllers/JsonValidatorController.cs b/src/SMAPI.Web/Controllers/JsonValidatorController.cs
index b2eb9a87..c32fb084 100644
--- a/src/SMAPI.Web/Controllers/JsonValidatorController.cs
+++ b/src/SMAPI.Web/Controllers/JsonValidatorController.cs
@@ -5,14 +5,12 @@ using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
-using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Schema;
using StardewModdingAPI.Web.Framework;
using StardewModdingAPI.Web.Framework.Clients.Pastebin;
using StardewModdingAPI.Web.Framework.Compression;
-using StardewModdingAPI.Web.Framework.ConfigModels;
using StardewModdingAPI.Web.ViewModels.JsonValidator;
namespace StardewModdingAPI.Web.Controllers
@@ -23,18 +21,12 @@ namespace StardewModdingAPI.Web.Controllers
/*********
** Fields
*********/
- /// <summary>The site config settings.</summary>
- private readonly SiteConfig Config;
-
/// <summary>The underlying Pastebin client.</summary>
private readonly IPastebinClient Pastebin;
/// <summary>The underlying text compression helper.</summary>
private readonly IGzipHelper GzipHelper;
- /// <summary>The section URL for the schema validator.</summary>
- private string SectionUrl => this.Config.JsonValidatorUrl;
-
/// <summary>The supported JSON schemas (names indexed by ID).</summary>
private readonly IDictionary<string, string> SchemaFormats = new Dictionary<string, string>
{
@@ -57,12 +49,10 @@ namespace StardewModdingAPI.Web.Controllers
** Constructor
***/
/// <summary>Construct an instance.</summary>
- /// <param name="siteConfig">The context config settings.</param>
/// <param name="pastebin">The Pastebin API client.</param>
/// <param name="gzipHelper">The underlying text compression helper.</param>
- public JsonValidatorController(IOptions<SiteConfig> siteConfig, IPastebinClient pastebin, IGzipHelper gzipHelper)
+ public JsonValidatorController(IPastebinClient pastebin, IGzipHelper gzipHelper)
{
- this.Config = siteConfig.Value;
this.Pastebin = pastebin;
this.GzipHelper = gzipHelper;
}
@@ -81,7 +71,7 @@ namespace StardewModdingAPI.Web.Controllers
{
schemaName = this.NormalizeSchemaName(schemaName);
- var result = new JsonValidatorModel(this.SectionUrl, id, schemaName, this.SchemaFormats);
+ var result = new JsonValidatorModel(id, schemaName, this.SchemaFormats);
if (string.IsNullOrWhiteSpace(id))
return this.View("Index", result);
@@ -142,7 +132,7 @@ namespace StardewModdingAPI.Web.Controllers
public async Task<ActionResult> PostAsync(JsonValidatorRequestModel request)
{
if (request == null)
- return this.View("Index", new JsonValidatorModel(this.SectionUrl, null, null, this.SchemaFormats).SetUploadError("The request seems to be invalid."));
+ return this.View("Index", new JsonValidatorModel(null, null, this.SchemaFormats).SetUploadError("The request seems to be invalid."));
// normalize schema name
string schemaName = this.NormalizeSchemaName(request.SchemaName);
@@ -150,7 +140,7 @@ namespace StardewModdingAPI.Web.Controllers
// get raw log text
string input = request.Content;
if (string.IsNullOrWhiteSpace(input))
- return this.View("Index", new JsonValidatorModel(this.SectionUrl, null, schemaName, this.SchemaFormats).SetUploadError("The JSON file seems to be empty."));
+ return this.View("Index", new JsonValidatorModel(null, schemaName, this.SchemaFormats).SetUploadError("The JSON file seems to be empty."));
// upload log
input = this.GzipHelper.CompressString(input);
@@ -158,12 +148,10 @@ namespace StardewModdingAPI.Web.Controllers
// handle errors
if (!result.Success)
- return this.View("Index", new JsonValidatorModel(this.SectionUrl, 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
- UriBuilder uri = new UriBuilder(new Uri(this.SectionUrl));
- uri.Path = $"{uri.Path.TrimEnd('/')}/{schemaName}/{result.ID}";
- return this.Redirect(uri.Uri.ToString());
+ return this.Redirect(this.Url.Action("Index", "LogParser", new { schemaName = schemaName, id = result.ID }));
}
diff --git a/src/SMAPI.Web/Controllers/LogParserController.cs b/src/SMAPI.Web/Controllers/LogParserController.cs
index 32c45038..2ced5a05 100644
--- a/src/SMAPI.Web/Controllers/LogParserController.cs
+++ b/src/SMAPI.Web/Controllers/LogParserController.cs
@@ -27,9 +27,6 @@ namespace StardewModdingAPI.Web.Controllers
/*********
** Fields
*********/
- /// <summary>The site config settings.</summary>
- private readonly SiteConfig SiteConfig;
-
/// <summary>The API client settings.</summary>
private readonly ApiClientsConfig ClientsConfig;
@@ -47,13 +44,11 @@ namespace StardewModdingAPI.Web.Controllers
** Constructor
***/
/// <summary>Construct an instance.</summary>
- /// <param name="siteConfig">The context config settings.</param>
/// <param name="clientsConfig">The API client settings.</param>
/// <param name="pastebin">The Pastebin API client.</param>
/// <param name="gzipHelper">The underlying text compression helper.</param>
- public LogParserController(IOptions<SiteConfig> siteConfig, IOptions<ApiClientsConfig> clientsConfig, IPastebinClient pastebin, IGzipHelper gzipHelper)
+ public LogParserController(IOptions<ApiClientsConfig> clientsConfig, IPastebinClient pastebin, IGzipHelper gzipHelper)
{
- this.SiteConfig = siteConfig.Value;
this.ClientsConfig = clientsConfig.Value;
this.Pastebin = pastebin;
this.GzipHelper = gzipHelper;
@@ -103,9 +98,7 @@ namespace StardewModdingAPI.Web.Controllers
return this.View("Index", this.GetModel(null, uploadError: uploadResult.UploadError));
// redirect to view
- UriBuilder uri = new UriBuilder(new Uri(this.SiteConfig.LogParserUrl));
- uri.Path = $"{uri.Path.TrimEnd('/')}/{uploadResult.ID}";
- return this.Redirect(uri.Uri.ToString());
+ return this.Redirect(this.Url.Action("Index", "LogParser", new { id = uploadResult.ID }));
}
@@ -217,10 +210,9 @@ namespace StardewModdingAPI.Web.Controllers
/// <param name="uploadError">An error which occurred while uploading the log.</param>
private LogParserModel GetModel(string pasteID, DateTime? expiry = null, string uploadWarning = null, string uploadError = null)
{
- string sectionUrl = this.SiteConfig.LogParserUrl;
Platform? platform = this.DetectClientPlatform();
- return new LogParserModel(sectionUrl, pasteID, platform)
+ return new LogParserModel(pasteID, platform)
{
UploadWarning = uploadWarning,
UploadError = uploadError,
diff --git a/src/SMAPI.Web/Controllers/ModsApiController.cs b/src/SMAPI.Web/Controllers/ModsApiController.cs
index fe220eb5..f10e0067 100644
--- a/src/SMAPI.Web/Controllers/ModsApiController.cs
+++ b/src/SMAPI.Web/Controllers/ModsApiController.cs
@@ -49,9 +49,6 @@ namespace StardewModdingAPI.Web.Controllers
/// <summary>The internal mod metadata list.</summary>
private readonly ModDatabase ModDatabase;
- /// <summary>The web URL for the