mirror of
https://github.com/JustArchiNET/ArchiSteamFarm
synced 2024-11-10 07:04:27 +00:00
Remove support for IPC localization (#2545)
This commit is contained in:
parent
b681b74ee6
commit
7118185ac5
5 changed files with 0 additions and 130 deletions
|
@ -33,7 +33,6 @@
|
|||
<PackageReference Include="Microsoft.AspNetCore.Cors" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.HttpOverrides" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Localization" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.ResponseCaching" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.ResponseCompression" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" />
|
||||
|
|
|
@ -1,84 +0,0 @@
|
|||
// _ _ _ ____ _ _____
|
||||
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
|
||||
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
|
||||
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
|
||||
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
|
||||
// |
|
||||
// Copyright 2015-2022 Łukasz "JustArchi" Domeradzki
|
||||
// Contact: JustArchi@JustArchi.net
|
||||
// |
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// |
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// |
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Headers;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
namespace ArchiSteamFarm.IPC.Integration;
|
||||
|
||||
[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")]
|
||||
internal sealed class LocalizationMiddleware {
|
||||
private static readonly ImmutableDictionary<string, string> CultureConversions = new Dictionary<string, string>(2, StringComparer.OrdinalIgnoreCase) {
|
||||
{ "lol-US", SharedInfo.LolcatCultureName },
|
||||
{ "sr-CS", "sr-Latn" }
|
||||
}.ToImmutableDictionary(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
private readonly RequestDelegate Next;
|
||||
|
||||
public LocalizationMiddleware(RequestDelegate next) => Next = next ?? throw new ArgumentNullException(nameof(next));
|
||||
|
||||
[UsedImplicitly]
|
||||
public async Task InvokeAsync(HttpContext context) {
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
|
||||
RequestHeaders headers = context.Request.GetTypedHeaders();
|
||||
|
||||
IList<StringWithQualityHeaderValue> acceptLanguageHeader = headers.AcceptLanguage;
|
||||
|
||||
if (acceptLanguageHeader.Count == 0) {
|
||||
await Next(context).ConfigureAwait(false);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool valuesChanged = false;
|
||||
|
||||
for (int i = 0; i < acceptLanguageHeader.Count; i++) {
|
||||
StringSegment language = acceptLanguageHeader[i].Value;
|
||||
|
||||
if (!language.HasValue || string.IsNullOrEmpty(language.Value)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!CultureConversions.TryGetValue(language.Value, out string? replacement) || string.IsNullOrEmpty(replacement)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
acceptLanguageHeader[i] = StringWithQualityHeaderValue.Parse(replacement);
|
||||
valuesChanged = true;
|
||||
}
|
||||
|
||||
if (valuesChanged) {
|
||||
// The getter returns a temporary collection; To make sure our changes are persisted, we need to assign it back
|
||||
headers.AcceptLanguage = acceptLanguageHeader;
|
||||
}
|
||||
|
||||
await Next(context).ConfigureAwait(false);
|
||||
}
|
||||
}
|
|
@ -30,7 +30,6 @@ using System.Collections.Generic;
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using ArchiSteamFarm.Core;
|
||||
|
@ -44,7 +43,6 @@ using Microsoft.AspNetCore.Hosting;
|
|||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Headers;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.AspNetCore.Localization;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
@ -136,12 +134,6 @@ internal sealed class Startup {
|
|||
}
|
||||
);
|
||||
|
||||
// Add support for additional localization mappings
|
||||
app.UseMiddleware<LocalizationMiddleware>();
|
||||
|
||||
// Add support for localization
|
||||
app.UseRequestLocalization();
|
||||
|
||||
// Use routing for our API controllers, this should be called once we're done with all the static files mess
|
||||
#if !NETFRAMEWORK
|
||||
app.UseRouting();
|
||||
|
@ -233,29 +225,6 @@ internal sealed class Startup {
|
|||
// Add support for response compression
|
||||
services.AddResponseCompression();
|
||||
|
||||
// Add support for localization
|
||||
services.AddLocalization();
|
||||
|
||||
services.AddRequestLocalization(
|
||||
static options => {
|
||||
// We do not set the DefaultRequestCulture here, because it will default to Thread.CurrentThread.CurrentCulture in this case, which is set when loading GlobalConfig
|
||||
|
||||
try {
|
||||
CultureInfo lolcatCulture = CultureInfo.CreateSpecificCulture(SharedInfo.LolcatCultureName);
|
||||
|
||||
options.SupportedCultures = options.SupportedUICultures = CultureInfo.GetCultures(CultureTypes.AllCultures).Append(lolcatCulture).ToList();
|
||||
} catch (Exception e) {
|
||||
// Fallback for platforms that do not support qps-Ploc culture
|
||||
ASF.ArchiLogger.LogGenericDebuggingException(e);
|
||||
|
||||
options.SupportedCultures = options.SupportedUICultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
|
||||
}
|
||||
|
||||
// The default checks the URI and cookies and only then for headers; ASFs IPC does not use either of the higher priority mechanisms anywhere else and we don't want to start here.
|
||||
options.RequestCultureProviders = new List<IRequestCultureProvider>(1) { new AcceptLanguageHeaderRequestCultureProvider() };
|
||||
}
|
||||
);
|
||||
|
||||
string? ipcPassword = ASF.GlobalConfig != null ? ASF.GlobalConfig.IPCPassword : GlobalConfig.DefaultIPCPassword;
|
||||
|
||||
if (!string.IsNullOrEmpty(ipcPassword)) {
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
// limitations under the License.
|
||||
|
||||
#if NETFRAMEWORK
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
#endif
|
||||
|
@ -61,18 +60,6 @@ internal static class WebUtilities {
|
|||
|
||||
return mvc;
|
||||
}
|
||||
|
||||
internal static IServiceCollection AddRequestLocalization(this IServiceCollection services, Action<RequestLocalizationOptions> action) {
|
||||
if (services == null) {
|
||||
throw new ArgumentNullException(nameof(services));
|
||||
}
|
||||
|
||||
if (action == null) {
|
||||
throw new ArgumentNullException(nameof(action));
|
||||
}
|
||||
|
||||
return services.Configure(action);
|
||||
}
|
||||
#endif
|
||||
|
||||
internal static string? GetUnifiedName(this Type type) {
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
<PackageVersion Include="Microsoft.AspNetCore.Cors" Version="2.2.0" />
|
||||
<PackageVersion Include="Microsoft.AspNetCore.Diagnostics" Version="2.2.0" />
|
||||
<PackageVersion Include="Microsoft.AspNetCore.HttpOverrides" Version="2.2.0" />
|
||||
<PackageVersion Include="Microsoft.AspNetCore.Localization" Version="2.2.0" />
|
||||
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
|
||||
<PackageVersion Include="Microsoft.AspNetCore.ResponseCaching" Version="2.2.0" />
|
||||
<PackageVersion Include="Microsoft.AspNetCore.ResponseCompression" Version="2.2.0" />
|
||||
|
|
Loading…
Reference in a new issue