From 88383c30f02be7a788840d02b2940978f587945e Mon Sep 17 00:00:00 2001 From: GMatrixGames Date: Wed, 27 Jul 2022 22:15:55 -0400 Subject: [PATCH] Move mappings and AES to Fortnite Central --- FModel/ViewModels/AesManagerViewModel.cs | 4 +- FModel/ViewModels/ApiEndpointViewModel.cs | 2 + .../ApiEndpoints/BenbotApiEndpoint.cs | 32 ------------- .../FortniteCentralApiEndpoint.cs | 47 +++++++++++++++++++ .../ApiEndpoints/Models/AesResponse.cs | 4 +- FModel/ViewModels/CUE4ParseViewModel.cs | 4 +- 6 files changed, 55 insertions(+), 38 deletions(-) create mode 100644 FModel/ViewModels/ApiEndpoints/FortniteCentralApiEndpoint.cs diff --git a/FModel/ViewModels/AesManagerViewModel.cs b/FModel/ViewModels/AesManagerViewModel.cs index e1677b1f..3b21c3dc 100644 --- a/FModel/ViewModels/AesManagerViewModel.cs +++ b/FModel/ViewModels/AesManagerViewModel.cs @@ -79,7 +79,7 @@ private void AesKeysOnItemPropertyChanged(object sender, ItemPropertyChangedEven new() { Key = key, - FileName = collection[e.CollectionIndex].Name, + Name = collection[e.CollectionIndex].Name, Guid = collection[e.CollectionIndex].Guid.ToString() } }; @@ -97,7 +97,7 @@ private void AesKeysOnItemPropertyChanged(object sender, ItemPropertyChangedEven _keysFromSettings.DynamicKeys.Add(new DynamicKey { Key = key, - FileName = collection[e.CollectionIndex].Name, + Name = collection[e.CollectionIndex].Name, Guid = collection[e.CollectionIndex].Guid.ToString() }); } diff --git a/FModel/ViewModels/ApiEndpointViewModel.cs b/FModel/ViewModels/ApiEndpointViewModel.cs index 55d5d6af..a5c8a047 100644 --- a/FModel/ViewModels/ApiEndpointViewModel.cs +++ b/FModel/ViewModels/ApiEndpointViewModel.cs @@ -17,6 +17,7 @@ public class ApiEndpointViewModel public FortniteApiEndpoint FortniteApi { get; } public ValorantApiEndpoint ValorantApi { get; } + public FortniteCentralApiEndpoint CentralApi { get; } public BenbotApiEndpoint BenbotApi { get; } public EpicApiEndpoint EpicApi { get; } public FModelApi FModelApi { get; } @@ -25,6 +26,7 @@ public ApiEndpointViewModel() { FortniteApi = new FortniteApiEndpoint(_client); ValorantApi = new ValorantApiEndpoint(_client); + CentralApi = new FortniteCentralApiEndpoint(_client); BenbotApi = new BenbotApiEndpoint(_client); EpicApi = new EpicApiEndpoint(_client); FModelApi = new FModelApi(_client); diff --git a/FModel/ViewModels/ApiEndpoints/BenbotApiEndpoint.cs b/FModel/ViewModels/ApiEndpoints/BenbotApiEndpoint.cs index ddfb971c..dbbe7886 100644 --- a/FModel/ViewModels/ApiEndpoints/BenbotApiEndpoint.cs +++ b/FModel/ViewModels/ApiEndpoints/BenbotApiEndpoint.cs @@ -15,38 +15,6 @@ public BenbotApiEndpoint(RestClient client) : base(client) { } - public async Task GetAesKeysAsync(CancellationToken token) - { - var request = new FRestRequest("https://benbot.app/api/v2/aes") - { - OnBeforeDeserialization = resp => { resp.ContentType = "application/json; charset=utf-8"; } - }; - var response = await _client.ExecuteAsync(request, token).ConfigureAwait(false); - Log.Information("[{Method}] [{Status}({StatusCode})] '{Resource}'", request.Method, response.StatusDescription, (int) response.StatusCode, response.ResponseUri?.OriginalString); - return response.Data; - } - - public AesResponse GetAesKeys(CancellationToken token) - { - return GetAesKeysAsync(token).GetAwaiter().GetResult(); - } - - public async Task GetMappingsAsync(CancellationToken token) - { - var request = new FRestRequest("https://benbot.app/api/v1/mappings") - { - OnBeforeDeserialization = resp => { resp.ContentType = "application/json; charset=utf-8"; } - }; - var response = await _client.ExecuteAsync(request, token).ConfigureAwait(false); - Log.Information("[{Method}] [{Status}({StatusCode})] '{Resource}'", request.Method, response.StatusDescription, (int) response.StatusCode, response.ResponseUri?.OriginalString); - return response.Data; - } - - public MappingsResponse[] GetMappings(CancellationToken token) - { - return GetMappingsAsync(token).GetAwaiter().GetResult(); - } - public async Task>> GetHotfixesAsync(CancellationToken token, string language = "en-US") { var request = new FRestRequest("https://benbot.app/api/v1/hotfixes") diff --git a/FModel/ViewModels/ApiEndpoints/FortniteCentralApiEndpoint.cs b/FModel/ViewModels/ApiEndpoints/FortniteCentralApiEndpoint.cs new file mode 100644 index 00000000..c13d8578 --- /dev/null +++ b/FModel/ViewModels/ApiEndpoints/FortniteCentralApiEndpoint.cs @@ -0,0 +1,47 @@ +using System.Threading; +using System.Threading.Tasks; +using FModel.Framework; +using FModel.ViewModels.ApiEndpoints.Models; +using RestSharp; +using Serilog; + +namespace FModel.ViewModels.ApiEndpoints; + +public class FortniteCentralApiEndpoint : AbstractApiProvider +{ + public FortniteCentralApiEndpoint(RestClient client) : base(client) + { + } + + public async Task GetAesKeysAsync(CancellationToken token) + { + var request = new FRestRequest("https://fortnitecentral.gmatrixgames.ga/api/v1/aes") + { + OnBeforeDeserialization = resp => { resp.ContentType = "application/json; charset=utf-8"; } + }; + var response = await _client.ExecuteAsync(request, token).ConfigureAwait(false); + Log.Information("[{Method}] [{Status}({StatusCode})] '{Resource}'", request.Method, response.StatusDescription, (int) response.StatusCode, response.ResponseUri?.OriginalString); + return response.Data; + } + + public AesResponse GetAesKeys(CancellationToken token) + { + return GetAesKeysAsync(token).GetAwaiter().GetResult(); + } + + public async Task GetMappingsAsync(CancellationToken token) + { + var request = new FRestRequest("https://fortnitecentral.gmatrixgames.ga/api/v1/mappings") + { + OnBeforeDeserialization = resp => { resp.ContentType = "application/json; charset=utf-8"; } + }; + var response = await _client.ExecuteAsync(request, token).ConfigureAwait(false); + Log.Information("[{Method}] [{Status}({StatusCode})] '{Resource}'", request.Method, response.StatusDescription, (int) response.StatusCode, response.ResponseUri?.OriginalString); + return response.Data; + } + + public MappingsResponse[] GetMappings(CancellationToken token) + { + return GetMappingsAsync(token).GetAwaiter().GetResult(); + } +} diff --git a/FModel/ViewModels/ApiEndpoints/Models/AesResponse.cs b/FModel/ViewModels/ApiEndpoints/Models/AesResponse.cs index 1dd3f68e..76e775a9 100644 --- a/FModel/ViewModels/ApiEndpoints/Models/AesResponse.cs +++ b/FModel/ViewModels/ApiEndpoints/Models/AesResponse.cs @@ -17,7 +17,7 @@ public class AesResponse [DebuggerDisplay("{" + nameof(Key) + "}")] public class DynamicKey { - [J("fileName")] public string FileName { get; set; } + [J("name")] public string Name { get; set; } [J("guid")] public string Guid { get; set; } [J("key")] public string Key { get; set; } -} \ No newline at end of file +} diff --git a/FModel/ViewModels/CUE4ParseViewModel.cs b/FModel/ViewModels/CUE4ParseViewModel.cs index 49e9dfa6..ee5b6294 100644 --- a/FModel/ViewModels/CUE4ParseViewModel.cs +++ b/FModel/ViewModels/CUE4ParseViewModel.cs @@ -296,7 +296,7 @@ public async Task RefreshAes() { await _threadWorkerView.Begin(cancellationToken => { - var aes = _apiEndpointView.BenbotApi.GetAesKeys(cancellationToken); + var aes = _apiEndpointView.CentralApi.GetAesKeys(cancellationToken); if (aes?.MainKey == null && aes?.DynamicKeys == null && aes?.Version == null) return; UserSettings.Default.AesKeys[Game] = aes; @@ -333,7 +333,7 @@ await _threadWorkerView.Begin(cancellationToken => else { var mappingsFolder = Path.Combine(UserSettings.Default.OutputDirectory, ".data"); - var mappings = _apiEndpointView.BenbotApi.GetMappings(cancellationToken); + var mappings = _apiEndpointView.CentralApi.GetMappings(cancellationToken); if (mappings is { Length: > 0 }) { foreach (var mapping in mappings)