summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI.Web/Framework')
-rw-r--r--src/SMAPI.Web/Framework/ClientPlatformDetection/ClientPlatformMiddleware.cs53
-rw-r--r--src/SMAPI.Web/Framework/ClientPlatformDetection/ClientPlatformMiddlewareExtensions.cs16
2 files changed, 0 insertions, 69 deletions
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
-{
- /// <summary>Middleware that detects the client's platform.</summary>
- public class ClientPlatformMiddleware
- {
- /// <summary>The key used to retrieve the client's platform from <see cref="HttpContext.Items"/>.</summary>
- public const string ClientPlatformKey = "ClientPlatformKey";
-
- /// <summary>The next delegate in the middleware pipeline.</summary>
- private readonly RequestDelegate Next;
-
- /// <summary>Construct an instance.</summary>
- /// <param name="next">The next delegate in the middleware pipeline.</param>
- public ClientPlatformMiddleware(RequestDelegate next)
- {
- this.Next = next;
- }
-
- /// <summary>Invoke the middleware.</summary>
- /// <param name="context">The HTTP request context.</param>
- public async Task InvokeAsync(HttpContext context)
- {
- context.Items[ClientPlatformMiddleware.ClientPlatformKey] = this.DetectClientPlatform(context.Request.Headers["User-Agent"]);
-
- await this.Next(context);
- }
-
- /// <summary>Detect the platform that the client is on.</summary>
- /// <param name="userAgent">The client's user agent.</param>
- /// <returns>The client's platform, or null if no platforms could be detected.</returns>
- 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
-{
- /// <summary>Extension methods for the client platform middleware.</summary>
- internal static class ClientPlatformMiddlewareExtensions
- {
- /// <summary>Adds client platform detection to the request pipeline.</summary>
- /// <param name="builder">The application builder.</param>
- /// <returns>The application builder with the client platform middleware enabled.</returns>
- public static IApplicationBuilder UseClientPlatform(this IApplicationBuilder builder)
- {
- return builder.UseMiddleware<ClientPlatformMiddleware>();
- }
- }
-}