diff --git a/src/SMAPI.Web/Controllers/LogParserController.cs b/src/SMAPI.Web/Controllers/LogParserController.cs index 0556a81e..2a071b6c 100644 --- a/src/SMAPI.Web/Controllers/LogParserController.cs +++ b/src/SMAPI.Web/Controllers/LogParserController.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; +using StardewModdingAPI.Toolkit.Utilities; using StardewModdingAPI.Web.Framework; using StardewModdingAPI.Web.Framework.Clients.Pastebin; using StardewModdingAPI.Web.Framework.Compression; @@ -59,14 +60,14 @@ namespace StardewModdingAPI.Web.Controllers { // fresh page if (string.IsNullOrWhiteSpace(id)) - return this.View("Index", new LogParserModel(this.Config.LogParserUrl, id)); + return this.View("Index", this.GetModel(id)); // 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, raw)); + return this.View("Index", this.GetModel(id).SetResult(log, raw)); } /*** @@ -80,7 +81,7 @@ namespace StardewModdingAPI.Web.Controllers // get raw log text string input = this.Request.Form["input"].FirstOrDefault(); if (string.IsNullOrWhiteSpace(input)) - return this.View("Index", new LogParserModel(this.Config.LogParserUrl, null) { UploadError = "The log file seems to be empty." }); + return this.View("Index", this.GetModel(null, uploadError: "The log file seems to be empty.")); // upload log input = this.GzipHelper.CompressString(input); @@ -88,7 +89,7 @@ namespace StardewModdingAPI.Web.Controllers // handle errors if (!result.Success) - return this.View("Index", new LogParserModel(this.Config.LogParserUrl, result.ID) { UploadError = $"Pastebin error: {result.Error ?? "unknown error"}" }); + return this.View("Index", this.GetModel(result.ID, uploadError: $"Pastebin error: {result.Error ?? "unknown error"}")); // redirect to view UriBuilder uri = new UriBuilder(new Uri(this.Config.LogParserUrl)); @@ -108,5 +109,39 @@ namespace StardewModdingAPI.Web.Controllers response.Content = this.GzipHelper.DecompressString(response.Content); return response; } + + /// Construct an instance. + /// The paste ID. + /// An error which occurred while uploading the log to Pastebin. + private LogParserModel GetModel(string pasteID, string uploadError = null) + { + string sectionUrl = this.Config.LogParserUrl; + Platform? platform = this.DetectClientPlatform(); + return new LogParserModel(sectionUrl, pasteID, platform) { UploadError = uploadError }; + } + + /// Detect the viewer's OS. + /// Returns the viewer OS if known, else null. + private Platform? DetectClientPlatform() + { + string userAgent = this.Request.Headers["User-Agent"]; + switch (userAgent) + { + case string ua when ua.Contains("Windows"): + return Platform.Windows; + + case string ua when ua.Contains("Android"): // check for Android before Linux because Android user agents also contain Linux + return Platform.Android; + + case string ua when ua.Contains("Linux"): + return Platform.Linux; + + case string ua when ua.Contains("Mac"): + return Platform.Mac; + + default: + return null; + } + } } } diff --git a/src/SMAPI.Web/Framework/ClientPlatformDetection/ClientPlatformMiddleware.cs b/src/SMAPI.Web/Framework/ClientPlatformDetection/ClientPlatformMiddleware.cs deleted file mode 100644 index 2bf23ff9..00000000 --- a/src/SMAPI.Web/Framework/ClientPlatformDetection/ClientPlatformMiddleware.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using StardewModdingAPI.Toolkit.Utilities; - -namespace StardewModdingAPI.Web.Framework.ClientPlatformDetection -{ - /// Middleware that detects the client's platform. - public class ClientPlatformMiddleware - { - /// The key used to retrieve the client's platform from . - public const string ClientPlatformKey = "ClientPlatformKey"; - - /// The next delegate in the middleware pipeline. - private readonly RequestDelegate Next; - - /// Construct an instance. - /// The next delegate in the middleware pipeline. - public ClientPlatformMiddleware(RequestDelegate next) - { - this.Next = next; - } - - /// Invoke the middleware. - /// The HTTP request context. - public async Task InvokeAsync(HttpContext context) - { - context.Items[ClientPlatformMiddleware.ClientPlatformKey] = this.DetectClientPlatform(context.Request.Headers["User-Agent"]); - - await this.Next(context); - } - - /// Detect the platform that the client is on. - /// The client's user agent. - /// The client's platform, or null if no platforms could be detected. - private Platform? DetectClientPlatform(string userAgent) - { - switch (userAgent) - { - case string ua when ua.Contains("Windows"): - return Platform.Windows; - // check for Android before Linux because Android user agents also contain Linux - case string ua when ua.Contains("Android"): - return Platform.Android; - case string ua when ua.Contains("Linux"): - return Platform.Linux; - case string ua when ua.Contains("Mac"): - return Platform.Mac; - default: - return null; - } - } - } -} diff --git a/src/SMAPI.Web/Framework/ClientPlatformDetection/ClientPlatformMiddlewareExtensions.cs b/src/SMAPI.Web/Framework/ClientPlatformDetection/ClientPlatformMiddlewareExtensions.cs deleted file mode 100644 index 274e5486..00000000 --- a/src/SMAPI.Web/Framework/ClientPlatformDetection/ClientPlatformMiddlewareExtensions.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.AspNetCore.Builder; - -namespace StardewModdingAPI.Web.Framework.ClientPlatformDetection -{ - /// Extension methods for the client platform middleware. - internal static class ClientPlatformMiddlewareExtensions - { - /// Adds client platform detection to the request pipeline. - /// The application builder. - /// The application builder with the client platform middleware enabled. - public static IApplicationBuilder UseClientPlatform(this IApplicationBuilder builder) - { - return builder.UseMiddleware(); - } - } -} diff --git a/src/SMAPI.Web/Startup.cs b/src/SMAPI.Web/Startup.cs index e12fa63b..da5c1f1b 100644 --- a/src/SMAPI.Web/Startup.cs +++ b/src/SMAPI.Web/Startup.cs @@ -15,7 +15,6 @@ using StardewModdingAPI.Web.Framework; using StardewModdingAPI.Web.Framework.Caching; using StardewModdingAPI.Web.Framework.Caching.Mods; using StardewModdingAPI.Web.Framework.Caching.Wiki; -using StardewModdingAPI.Web.Framework.ClientPlatformDetection; using StardewModdingAPI.Web.Framework.Clients.Chucklefish; using StardewModdingAPI.Web.Framework.Clients.GitHub; using StardewModdingAPI.Web.Framework.Clients.ModDrop; @@ -173,7 +172,6 @@ namespace StardewModdingAPI.Web ) .UseRewriter(this.GetRedirectRules()) .UseStaticFiles() // wwwroot folder - .UseClientPlatform() .UseMvc(); // enable Hangfire dashboard diff --git a/src/SMAPI.Web/ViewModels/LogParserModel.cs b/src/SMAPI.Web/ViewModels/LogParserModel.cs index 25493a29..f4c5214b 100644 --- a/src/SMAPI.Web/ViewModels/LogParserModel.cs +++ b/src/SMAPI.Web/ViewModels/LogParserModel.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; +using StardewModdingAPI.Toolkit.Utilities; using StardewModdingAPI.Web.Framework.LogParsing.Models; namespace StardewModdingAPI.Web.ViewModels @@ -24,6 +25,9 @@ namespace StardewModdingAPI.Web.ViewModels /// The paste ID. public string PasteID { get; set; } + /// The viewer's detected OS, if known. + public Platform? DetectedPlatform { get; set; } + /// The parsed log info. public ParsedLog ParsedLog { get; set; } @@ -46,24 +50,25 @@ namespace StardewModdingAPI.Web.ViewModels /// Construct an instance. /// The root URL for the log parser controller. /// The paste ID. - public LogParserModel(string sectionUrl, string pasteID) + /// The viewer's detected OS, if known. + public LogParserModel(string sectionUrl, string pasteID, Platform? platform) { this.SectionUrl = sectionUrl; this.PasteID = pasteID; + this.DetectedPlatform = platform; this.ParsedLog = null; this.ShowRaw = false; } - /// Construct an instance. - /// The root URL for the log parser controller. - /// The paste ID. + /// Set the log parser result. /// The parsed log info. /// Whether to show the raw unparsed log. - public LogParserModel(string sectionUrl, string pasteID, ParsedLog parsedLog, bool showRaw) - : this(sectionUrl, pasteID) + public LogParserModel SetResult(ParsedLog parsedLog, bool showRaw) { this.ParsedLog = parsedLog; this.ShowRaw = showRaw; + + return this; } /// Get all content packs in the log grouped by the mod they're for. diff --git a/src/SMAPI.Web/Views/LogParser/Index.cshtml b/src/SMAPI.Web/Views/LogParser/Index.cshtml index 42887019..9a06d85a 100644 --- a/src/SMAPI.Web/Views/LogParser/Index.cshtml +++ b/src/SMAPI.Web/Views/LogParser/Index.cshtml @@ -1,6 +1,5 @@ @using Newtonsoft.Json @using StardewModdingAPI.Toolkit.Utilities -@using StardewModdingAPI.Web.Framework.ClientPlatformDetection @using StardewModdingAPI.Web.Framework.LogParsing.Models @model StardewModdingAPI.Web.ViewModels.LogParserModel @@ -69,13 +68,13 @@ else if (Model.ParsedLog?.IsValid == true)

Where do I find my SMAPI log?

What system do you use?
On Android: