summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-01-02 19:59:38 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-01-02 19:59:38 -0500
commite30e42762871af3900c47886b57e8c43287b290a (patch)
tree640bee64de4be8e369153ee45228aa60c571eacf
parent1fab386ab1ba6ae92ff934c3869f31a1660cf3b3 (diff)
downloadSMAPI-e30e42762871af3900c47886b57e8c43287b290a.tar.gz
SMAPI-e30e42762871af3900c47886b57e8c43287b290a.tar.bz2
SMAPI-e30e42762871af3900c47886b57e8c43287b290a.zip
add download option to log view
-rw-r--r--docs/release-notes.md1
-rw-r--r--src/SMAPI.Web/Controllers/LogParserController.cs33
-rw-r--r--src/SMAPI.Web/ViewModels/LogViewFormat.cs15
-rw-r--r--src/SMAPI.Web/Views/LogParser/Index.cshtml17
4 files changed, 56 insertions, 10 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md
index 8ca2e884..1df0af0e 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -13,6 +13,7 @@
* Improved translations. Thanks to ChulkyBow (added Ukrainian)!
* For the web UI:
+ * Added log download option.
* Fixed log parser not correctly handling multiple mods having the exact same name.
## 3.13.2
diff --git a/src/SMAPI.Web/Controllers/LogParserController.cs b/src/SMAPI.Web/Controllers/LogParserController.cs
index 39de4b5d..db53d942 100644
--- a/src/SMAPI.Web/Controllers/LogParserController.cs
+++ b/src/SMAPI.Web/Controllers/LogParserController.cs
@@ -1,5 +1,6 @@
using System;
using System.Linq;
+using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using StardewModdingAPI.Toolkit.Utilities;
@@ -39,24 +40,42 @@ namespace StardewModdingAPI.Web.Controllers
***/
/// <summary>Render the log parser UI.</summary>
/// <param name="id">The stored file ID.</param>
- /// <param name="raw">Whether to display the raw unparsed log.</param>
+ /// <param name="format">How to render the log view.</param>
/// <param name="renew">Whether to reset the log expiry.</param>
[HttpGet]
[Route("log")]
[Route("log/{id}")]
- public async Task<ViewResult> Index(string id = null, bool raw = false, bool renew = false)
+ public async Task<ActionResult> Index(string id = null, LogViewFormat format = LogViewFormat.Default, bool renew = false)
{
// fresh page
if (string.IsNullOrWhiteSpace(id))
return this.View("Index", this.GetModel(id));
- // log page
+ // fetch log
StoredFileInfo file = await this.Storage.GetAsync(id, renew);
- ParsedLog log = file.Success
- ? new LogParser().Parse(file.Content)
- : new ParsedLog { IsValid = false, Error = file.Error };
- return this.View("Index", this.GetModel(id, uploadWarning: file.Warning, expiry: file.Expiry).SetResult(log, raw));
+ // render view
+ switch (format)
+ {
+ case LogViewFormat.Default:
+ case LogViewFormat.RawView:
+ {
+ ParsedLog log = file.Success
+ ? new LogParser().Parse(file.Content)
+ : new ParsedLog { IsValid = false, Error = file.Error };
+
+ return this.View("Index", this.GetModel(id, uploadWarning: file.Warning, expiry: file.Expiry).SetResult(log, showRaw: format == LogViewFormat.RawView));
+ }
+
+ case LogViewFormat.RawDownload:
+ {
+ string content = file.Error ?? file.Content;
+ return this.File(Encoding.UTF8.GetBytes(content), "plain/text", $"SMAPI log ({id}).txt");
+ }
+
+ default:
+ throw new InvalidOperationException($"Unknown log view format '{format}'.");
+ }
}
/***
diff --git a/src/SMAPI.Web/ViewModels/LogViewFormat.cs b/src/SMAPI.Web/ViewModels/LogViewFormat.cs
new file mode 100644
index 00000000..7ef79319
--- /dev/null
+++ b/src/SMAPI.Web/ViewModels/LogViewFormat.cs
@@ -0,0 +1,15 @@
+namespace StardewModdingAPI.Web.ViewModels
+{
+ /// <summary>How a log file should be displayed.</summary>
+ public enum LogViewFormat
+ {
+ /// <summary>Render a parsed log and metadata.</summary>
+ Default,
+
+ /// <summary>Render a raw log with parsed metadata.</summary>
+ RawView,
+
+ /// <summary>Render directly as a text file.</summary>
+ RawDownload
+ }
+}
diff --git a/src/SMAPI.Web/Views/LogParser/Index.cshtml b/src/SMAPI.Web/Views/LogParser/Index.cshtml
index 06d46c9e..eeff776c 100644
--- a/src/SMAPI.Web/Views/LogParser/Index.cshtml
+++ b/src/SMAPI.Web/Views/LogParser/Index.cshtml
@@ -2,6 +2,7 @@
@using StardewModdingAPI.Toolkit.Utilities
@using StardewModdingAPI.Web.Framework
@using StardewModdingAPI.Web.Framework.LogParsing.Models
+@using StardewModdingAPI.Web.ViewModels
@model StardewModdingAPI.Web.ViewModels.LogParserModel
@{
@@ -338,14 +339,24 @@ else if (Model.ParsedLog?.IsValid == true)
}
}
</table>
-
- <small><a href="@this.Url.PlainAction("Index", "LogParser", new { id = Model.PasteID, raw = true })">view raw log</a></small>
}
else
{
<pre v-pre>@Model.ParsedLog.RawText</pre>
- <small><a href="@this.Url.PlainAction("Index", "LogParser", new { id = Model.PasteID })">view parsed log</a></small>
}
+
+ <small>
+ @if (Model.ShowRaw)
+ {
+ <a href="@this.Url.PlainAction("Index", "LogParser", new { id = Model.PasteID })">view parsed log</a>
+ }
+ else
+ {
+ <a href="@this.Url.PlainAction("Index", "LogParser", new { id = Model.PasteID, format = LogViewFormat.RawView })">view raw log</a>
+ }
+
+ | <a href="@this.Url.PlainAction("Index", "LogParser", new { id = Model.PasteID, format = LogViewFormat.RawDownload })" download>download</a>
+ </small>
</div>
}
else if (Model.ParsedLog?.IsValid == false)