summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/Controllers
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2018-02-24 17:54:31 -0500
committerJesse Plamondon-Willard <github@jplamondonw.com>2018-02-24 17:54:31 -0500
commit414cf5c197b5b59776d3dda914eb15710efb0868 (patch)
tree0393a95194ad78cf4440c68657b0488b7db6d68b /src/SMAPI.Web/Controllers
parent5da8b707385b9851ff3f6442de58519125f5c96f (diff)
parentf2e8450706d1971d774f870081deffdb0c6b92eb (diff)
downloadSMAPI-414cf5c197b5b59776d3dda914eb15710efb0868.tar.gz
SMAPI-414cf5c197b5b59776d3dda914eb15710efb0868.tar.bz2
SMAPI-414cf5c197b5b59776d3dda914eb15710efb0868.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI.Web/Controllers')
-rw-r--r--src/SMAPI.Web/Controllers/LogParserController.cs35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/SMAPI.Web/Controllers/LogParserController.cs b/src/SMAPI.Web/Controllers/LogParserController.cs
index 04a11a82..62547deb 100644
--- a/src/SMAPI.Web/Controllers/LogParserController.cs
+++ b/src/SMAPI.Web/Controllers/LogParserController.cs
@@ -8,6 +8,8 @@ using Microsoft.Extensions.Options;
using StardewModdingAPI.Web.Framework;
using StardewModdingAPI.Web.Framework.Clients.Pastebin;
using StardewModdingAPI.Web.Framework.ConfigModels;
+using StardewModdingAPI.Web.Framework.LogParsing;
+using StardewModdingAPI.Web.Framework.LogParsing.Models;
using StardewModdingAPI.Web.ViewModels;
namespace StardewModdingAPI.Web.Controllers
@@ -52,25 +54,23 @@ namespace StardewModdingAPI.Web.Controllers
[HttpGet]
[Route("log")]
[Route("log/{id}")]
- public ViewResult Index(string id = null)
+ public async Task<ViewResult> Index(string id = null)
{
- return this.View("Index", new LogParserModel(this.Config.LogParserUrl, id));
+ // fresh page
+ if (string.IsNullOrWhiteSpace(id))
+ return this.View("Index", new LogParserModel(this.Config.LogParserUrl, id, null));
+
+ // log page
+ PasteInfo paste = await this.GetAsync(id);
+ ParsedLog log = paste.Success
+ ? new LogParser().Parse(paste.Content)
+ : new ParsedLog { IsValid = false, Error = "Pastebin error: " + paste.Error };
+ return this.View("Index", new LogParserModel(this.Config.LogParserUrl, id, log));
}
/***
** 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<PasteInfo> GetAsync(string id)
- {
- PasteInfo response = await this.Pastebin.GetAsync(id);
- response.Content = this.DecompressString(response.Content);
- return response;
- }
-
/// <summary>Save raw log data.</summary>
/// <param name="content">The log content to save.</param>
[HttpPost, Produces("application/json"), AllowLargePosts]
@@ -85,6 +85,15 @@ namespace StardewModdingAPI.Web.Controllers
/*********
** Private methods
*********/
+ /// <summary>Fetch raw text from Pastebin.</summary>
+ /// <param name="id">The Pastebin paste ID.</param>
+ private async Task<PasteInfo> GetAsync(string id)
+ {
+ PasteInfo response = await this.Pastebin.GetAsync(id);
+ response.Content = this.DecompressString(response.Content);
+ return response;
+ }
+
/// <summary>Compress a string.</summary>
/// <param name="text">The text to compress.</param>
/// <remarks>Derived from <a href="https://stackoverflow.com/a/17993002/262123"/>.</remarks>