Skip to content

Commit

Permalink
#2.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Eternal-ll committed Jan 5, 2023
1 parent 05561db commit 2d0ec0c
Show file tree
Hide file tree
Showing 78 changed files with 3,414 additions and 1,115 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,11 @@ ASALocalRun/
/Ethereal.FAF.UI.Client/appsettings.json
/beta/appsettings.json
/beta/appsettings.Development.json
/Documentation
/WpfApp1
/VisualStateTests
/Tests
/MapVizualizator
/Logo
/LiveChartsSamples
/Fonts
6 changes: 3 additions & 3 deletions Ethereal.FAF.API.Client/AuthHeaderHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Ethereal.FAF.API.Client
{
class AuthHeaderHandler : DelegatingHandler
public class AuthHeaderHandler : DelegatingHandler
{
private readonly ITokenProvider TokenProvider;

Expand All @@ -14,7 +14,7 @@ public AuthHeaderHandler(ITokenProvider tenantProvider)

protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var token = TokenProvider.GetToken();
var token = await TokenProvider.GetTokenAsync(request.RequestUri.Host);

//potentially refresh token here if it has expired etc.

Expand All @@ -23,7 +23,7 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
return await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
}
}
internal class VerifyHeaderHandler : DelegatingHandler
public class VerifyHeaderHandler : DelegatingHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
Expand Down
2 changes: 1 addition & 1 deletion Ethereal.FAF.API.Client/BuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static IServiceCollection AddFafApi(this IServiceCollection services, Uri
.AddTransient<AuthHeaderHandler>()
.AddTransient<VerifyHeaderHandler>()
.AddRefitClient<IFafApiClient>()
.ConfigureHttpClient(c=>c.BaseAddress = api)
.ConfigureHttpClient(c => c.BaseAddress = api)
.Services
.AddRefitClient<IFafContentClient>()
.ConfigureHttpClient(c => c.BaseAddress = content)
Expand Down
1 change: 1 addition & 0 deletions Ethereal.FAF.API.Client/ITokenProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
public interface ITokenProvider
{
public string GetToken();
public Task<string> GetTokenAsync(string host);
}
}
23 changes: 12 additions & 11 deletions Ethereal.FAF.API.Client/Interfaces/IFafApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,20 @@ public class Pagination
}
public class Sorting
{
public ListSortDirection SortDirection { get; set; }
private string _Sort;
public ListSortDirection SortDirection;
[AliasAs("sort")]
public string Sort
{
get
{
if (string.IsNullOrWhiteSpace(Parameter) || Parameter is "None") return null;
return
SortDirection is ListSortDirection.Descending ?
"-" : string.Empty +
(SortDirection is ListSortDirection.Descending ?
"-" : string.Empty) +
Parameter;
}
set
{
_Sort = value;
}
}
public string Parameter { get; set; }
public string Parameter;
}
public class Filtration
{
Expand All @@ -48,7 +44,7 @@ public interface IFafApiClient
Task<ApiResponse<ApiUniversalResult<FeaturedModFile[]>>> GetAsync(int featuredMod, int version, [Authorize("Bearer")] string token, CancellationToken cancellationToken = default);

[Get("/data/coturnServer")]
Task<ApiResponse<ApiUniversalResult<CoturnServer[]>>> GetCoturnServersAsync([Authorize("Bearer")] string token, CancellationToken cancellationToken = default);
Task<ApiResponse<ApiUniversalResult<CoturnServer[]>>> GetCoturnServersAsync(CancellationToken cancellationToken = default);

[Get("/data/map")]
Task<ApiResponse<ApiMapsResult>> GetMapsAsync(
Expand All @@ -59,12 +55,17 @@ Task<ApiResponse<ApiMapsResult>> GetMapsAsync(
Pagination? pagination = null,
[AliasAs("include")]
[Query(CollectionFormat.Csv)]
params string[] include);
string[] include = null,
CancellationToken cancellationToken = default);
}
public interface IFafContentClient
{
[Get("/{url}")]
[QueryUriFormat(UriFormat.Unescaped)]
Task<ApiResponse<Stream>> GetFileStreamAsync(string url, [Authorize("Bearer")] string token, [Header("Verify")] string verify, CancellationToken cancellationToken = default);

[Get("/{url}")]
[QueryUriFormat(UriFormat.Unescaped)]
Task<ApiResponse<Stream>> GetFileStreamAsync(string url, CancellationToken cancellationToken = default);
}
}
45 changes: 37 additions & 8 deletions Ethereal.FAF.API.Client/Models/Base/ApiUniversalResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using beta.Models.API.MapsVault;
using beta.Models.API.Universal;
using System.Collections.Generic;
using System.Data;
using System.Text.Json.Serialization;

namespace beta.Models.API.Base
Expand All @@ -20,26 +21,51 @@ public class ApiUniversalResult<T> where T : class
[JsonPropertyName("meta")]
public ApiVaultMeta Meta { get; set; }

public virtual void ParseIncluded() { }
public virtual void ParseIncluded()
{

}
public virtual void ParseIncluded(out SortedDictionary<string, string[]> entityProperties)
{
entityProperties = null;
}
}
public class ApiMapsResult : ApiUniversalResult<ApiMapModel[]>
{
public override void ParseIncluded()
{
this.ParseIncluded(out var data);
}
public override void ParseIncluded(out SortedDictionary<string, string[]> entityProperties)
{
entityProperties = null;
var included = Included;
var data = Data;
if (included is null || data is null) return;
if (included.Length == 0 || data.Length == 0) return;

entityProperties = new();
var first = data.FirstOrDefault();
if (first is not null)
{
entityProperties.Add("map", first.Attributes.Keys.ToArray());
}
foreach (var map in data)
{
try
{
var relations = map.GetRelations();
foreach (var relation in relations)
if (map.Relations is null) continue;
foreach (var relation in map.Relations)
{
var entity = ApiUniversalTools.GetDataFromIncluded(included, relation.Key, relation.Value);
switch (relation.Key)
if (relation.Value.Data is null) continue;
if (relation.Value.Data.Count == 0) continue;
var entity = ApiUniversalTools.GetDataFromIncluded(included, relation.Value.Data[0].Type, relation.Value.Data[0].Id);
if (entity is null) continue;
if (entity is not null)
{
entityProperties.TryAdd(relation.Key, entity.Attributes.Keys.ToArray());
}

switch (relation.Value.Data[0].Type)
{
case ApiDataType.mapVersion:
map.LatestVersion = entity.CastTo<MapVersionModel>();
Expand All @@ -49,10 +75,13 @@ public override void ParseIncluded()
//}
continue;
case ApiDataType.player:
map.Author = entity.Attributes["login"];
map.Author = entity?.Attributes["login"];
continue;
case ApiDataType.mapReviewsSummary:
map.ReviewsSummary = entity.CastTo<ApiUniversalSummary>();
map.ReviewsSummary = entity?.CastTo<ApiUniversalSummary>();
continue;
case ApiDataType.mapStatistics:
map.StatisticsSummary = entity.CastTo<ApiUniversalStatistics>();
continue;
}
}
Expand Down
93 changes: 92 additions & 1 deletion Ethereal.FAF.API.Client/Models/CoturnServer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace beta.Models.API
using System.Text.Json.Serialization;

namespace beta.Models.API
{
public class CoturnServer : Base.ApiUniversalData
{
Expand All @@ -8,4 +10,93 @@ public class CoturnServer : Base.ApiUniversalData
public int Port => int.Parse(Attributes["port"]);
public string Region => Attributes["region"];
}
public partial class DownlordClientConfiguration
{
[JsonPropertyName("gitHubRepo")]
public GitHubRepo GitHubRepo { get; set; }

[JsonPropertyName("latestRelease")]
public LatestRelease LatestRelease { get; set; }

//[JsonPropertyName("recommendedMaps")]
//public object[] RecommendedMaps { get; set; }

[JsonPropertyName("endpoints")]
public Endpoint[] Endpoints { get; set; }
}

public partial class Endpoint
{
[JsonPropertyName("name")]
public string Name { get; set; }

[JsonPropertyName("lobby")]
public Irc Lobby { get; set; }

[JsonPropertyName("irc")]
public Irc Irc { get; set; }

[JsonPropertyName("liveReplay")]
public Irc LiveReplay { get; set; }

[JsonPropertyName("api")]
public Api Api { get; set; }

[JsonPropertyName("oauth")]
public Oauth Oauth { get; set; }
}

public partial class Api
{
[JsonPropertyName("url")]
public Uri Url { get; set; }
}

public partial class Irc
{
[JsonPropertyName("host")]
public string Host { get; set; }

[JsonPropertyName("port")]
public int Port { get; set; }
}

public partial class Oauth
{
[JsonPropertyName("url")]
public Uri Url { get; set; }

[JsonPropertyName("redirectUris")]
public Uri[] RedirectUris { get; set; }
}

public partial class GitHubRepo
{
[JsonPropertyName("apiUrl")]
public Uri ApiUrl { get; set; }
}

public partial class LatestRelease
{
[JsonPropertyName("version")]
public string Version { get; set; }

[JsonPropertyName("minimumVersion")]
public string MinimumVersion { get; set; }

[JsonPropertyName("windowsUrl")]
public Uri WindowsUrl { get; set; }

[JsonPropertyName("linuxUrl")]
public Uri LinuxUrl { get; set; }

[JsonPropertyName("releaseNotesUrl")]
public Uri ReleaseNotesUrl { get; set; }

[JsonPropertyName("mandatory")]
public bool Mandatory { get; set; }

[JsonPropertyName("message")]
public string Message { get; set; }
}
}
11 changes: 8 additions & 3 deletions Ethereal.FAF.API.Client/Models/MapsVault/ApiMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ public class ApiMapPoolAssignment : Base.ApiUniversalData
}
public class ApiMapModel : ApiMap
{
public string Author { get; set; }
public string Author { get; set; } = "Unknown";

public string SmallPreviewUrl => LatestVersion is null ?
$"https://via.placeholder.com/468x60?text={DisplayedName}.png" :
LatestVersion.ThumbnailUrlLarge.Replace("faforever.ru", "content.faforever.ru");


public ApiUniversalStatistics StatisticsSummary { get; set; }
public ApiUniversalSummary ReviewsSummary { get; set; }
public MapVersionModel LatestVersion { get; set; }
Expand Down Expand Up @@ -78,8 +84,7 @@ public Dictionary<ApiDataType, int> GetRelations()
var data = relation.Value.Data;
if (data is null) continue;
if (data.Count == 0) continue;
if (dic.ContainsKey(data[0].Type)) continue;
dic.Add(data[0].Type, data[0].Id);
dic.TryAdd(data[0].Type, data[0].Id);
}
}
return dic;
Expand Down
3 changes: 2 additions & 1 deletion Ethereal.FAF.API.Client/Models/MapsVault/ApiMapVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class MapVersionModel : ApiMapVersion
// FolderName.ToUpper());

public bool IsLatestVersion { get; set; }

/// <summary>
/// Local state of map <see cref="LocalMapState"/>
/// </summary>
Expand Down Expand Up @@ -70,6 +70,7 @@ public class MapVersionModel : ApiMapVersion
/////
///// </summary>
//public ImageSource MapLargePreview => _MapLargePreview ??= ImageTools.InitializeLazyBitmapImage(ThumbnailUrlLarge);
public string IsRankedLabel => IsRanked ? "Ranked" : "Not ranked";
/// <summary>
/// <seealso cref="Tools.CalculateMapSizeToPixels(int)"/>
/// </summary>
Expand Down
18 changes: 13 additions & 5 deletions Ethereal.FAF.API.Client/Models/Universal/ApiUniversalReview.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FAF.Domain.LobbyServer;
using System.Globalization;

namespace beta.Models.API.Universal
{
Expand Down Expand Up @@ -31,12 +32,19 @@ public override void ParseIncluded()
}
public class ApiUniversalSummary : Base.ApiUniversalData
{
public double LowerBound => double.Parse(Attributes["lowerBound"].Replace('.',','));
public double Negative => double.Parse(Attributes["negative"].Replace('.', ','));
public double Positive => double.Parse(Attributes["positive"].Replace('.', ','));
public int ReviewsCount => int.Parse(Attributes["reviews"]);
public double Score => double.Parse(Attributes["score"].Replace('.', ','));
public double LowerBound => double.Parse(Attributes["lowerBound"], CultureInfo.InvariantCulture);
public double Negative => double.Parse(Attributes["negative"], CultureInfo.InvariantCulture);
public double Positive => double.Parse(Attributes["positive"], CultureInfo.InvariantCulture);
public int ReviewsCount => int.Parse(Attributes["reviews"], CultureInfo.InvariantCulture);
public double Score => double.Parse(Attributes["score"], CultureInfo.InvariantCulture);
public double Average => Score / ReviewsCount;
public double AverageRounded => Math.Round(Average);
private static double WilsonAlgorithm(double positive, double negative)
{
return ((positive + 1.9208) / (positive + negative) -
1.96 * Math.Sqrt((positive * negative) / (positive + negative) + 0.9604) /
(positive + negative)) / (1 + 3.8416 / (positive + negative));
}
}
public class ApiUniversalStatistics : Base.ApiUniversalData
{
Expand Down
1 change: 1 addition & 0 deletions Ethereal.FAF.UI.Client/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<cmd:NagivateUriCommand x:Key="NagivateUriCommand"/>
<cmd:NavigateViewCommand x:Key="NavigateViewCommand"/>
<cmd:NavigateRootViewCommand x:Key="NavigateRootViewCommand"/>
<cmd:CopyCommand x:Key="CopyCommand"/>

<cmd:GenerateGameMapCommand x:Key="GenerateGameMapCommand"/>
Expand Down
Loading

0 comments on commit 2d0ec0c

Please sign in to comment.