diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-10-27 19:39:13 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-10-27 19:39:13 -0400 |
commit | ad5bb5b49af49c4668fd30fb2a0e606dcefe4ec0 (patch) | |
tree | e0bdd32fbfe91f7ab5e6cd3446a75b32d6e10e5c /src/SMAPI.Web/Controllers | |
parent | acbea9bfa33655048673a2292350aedb1d05a09a (diff) | |
download | SMAPI-ad5bb5b49af49c4668fd30fb2a0e606dcefe4ec0.tar.gz SMAPI-ad5bb5b49af49c4668fd30fb2a0e606dcefe4ec0.tar.bz2 SMAPI-ad5bb5b49af49c4668fd30fb2a0e606dcefe4ec0.zip |
proxy Pastebin requests through our API instead of third parties, improve error-handling (#358)
Diffstat (limited to 'src/SMAPI.Web/Controllers')
-rw-r--r-- | src/SMAPI.Web/Controllers/LogParserController.cs | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/src/SMAPI.Web/Controllers/LogParserController.cs b/src/SMAPI.Web/Controllers/LogParserController.cs index 4ed8898a..893d9a52 100644 --- a/src/SMAPI.Web/Controllers/LogParserController.cs +++ b/src/SMAPI.Web/Controllers/LogParserController.cs @@ -1,19 +1,69 @@ +using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; +using StardewModdingAPI.Web.Framework; +using StardewModdingAPI.Web.Framework.ConfigModels; +using StardewModdingAPI.Web.Framework.LogParser; namespace StardewModdingAPI.Web.Controllers { /// <summary>Provides a web UI and API for parsing SMAPI log files.</summary> - [Route("log")] internal class LogParserController : Controller { /********* + ** Properties + *********/ + /// <summary>The underlying Pastebin client.</summary> + private readonly PastebinClient PastebinClient; + + + /********* ** Public methods *********/ - /// <summary>Render the web UI to upload a log file.</summary> + /*** + ** Constructor + ***/ + /// <summary>Construct an instance.</summary> + /// <param name="configProvider">The log parser config settings.</param> + public LogParserController(IOptions<LogParserConfig> configProvider) + { + // init Pastebin client + LogParserConfig config = configProvider.Value; + string version = this.GetType().Assembly.GetName().Version.ToString(3); + string userAgent = string.Format(config.PastebinUserAgent, version); + this.PastebinClient = new PastebinClient(config.PastebinBaseUrl, userAgent, config.PastebinDevKey); + } + + /*** + ** Web UI + ***/ + /// <summary>Render the log parser UI.</summary> [HttpGet] + [Route("log")] public ViewResult Index() { return this.View("Index"); } + + /*** + ** JSON + ***/ + /// <summary>Fetch raw text from Pastebin.</summary> + /// <param name="id">The Pastebin paste ID.</param> + [HttpGet, Produces("application/json")] + [Route("log/fetch/{id}")] + public async Task<GetPasteResponse> GetAsync(string id) + { + return await this.PastebinClient.GetAsync(id); + } + + /// <summary>Save raw log data.</summary> + /// <param name="content">The log content to save.</param> + [HttpPost, Produces("application/json"), AllowLargePosts] + [Route("log/save")] + public async Task<SavePasteResponse> PostAsync([FromBody] string content) + { + return await this.PastebinClient.PostAsync(content); + } } } |