Added new jwt claim for country, Moved models to correct folder instead of inside Lightlesshub.Groups
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using LightlessSync.API.Data;
|
||||
using LightlessSync.API.Dto.Group;
|
||||
using LightlessSyncServer.Models;
|
||||
using LightlessSyncServer.Utils;
|
||||
using LightlessSyncShared.Metrics;
|
||||
using LightlessSyncShared.Models;
|
||||
@@ -8,7 +9,6 @@ using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using StackExchange.Redis;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
|
||||
namespace LightlessSyncServer.Hubs;
|
||||
|
||||
@@ -20,6 +20,8 @@ public partial class LightlessHub
|
||||
|
||||
public string Continent => Context.User?.Claims?.SingleOrDefault(c => string.Equals(c.Type, LightlessClaimTypes.Continent, StringComparison.Ordinal))?.Value ?? "UNK";
|
||||
|
||||
public string Country => Context.User?.Claims?.SingleOrDefault(c => string.Equals(c.Type, LightlessClaimTypes.Country, StringComparison.Ordinal))?.Value ?? "UNK";
|
||||
|
||||
private async Task DeleteUser(User user)
|
||||
{
|
||||
var ownPairData = await DbContext.ClientPairs.Where(u => u.User.UID == user.UID).ToListAsync().ConfigureAwait(false);
|
||||
|
||||
@@ -3,6 +3,7 @@ using LightlessSync.API.Data.Enum;
|
||||
using LightlessSync.API.Data.Extensions;
|
||||
using LightlessSync.API.Dto.Group;
|
||||
using LightlessSync.API.Dto.User;
|
||||
using LightlessSyncServer.Models;
|
||||
using LightlessSyncServer.Utils;
|
||||
using LightlessSyncShared.Models;
|
||||
using LightlessSyncShared.Utils;
|
||||
|
||||
@@ -3,6 +3,7 @@ using LightlessSync.API.Data.Enum;
|
||||
using LightlessSync.API.Data.Extensions;
|
||||
using LightlessSync.API.Dto.Group;
|
||||
using LightlessSync.API.Dto.User;
|
||||
using LightlessSyncServer.Models;
|
||||
using LightlessSyncServer.Utils;
|
||||
using LightlessSyncShared.Metrics;
|
||||
using LightlessSyncShared.Models;
|
||||
@@ -204,8 +205,8 @@ public partial class LightlessHub
|
||||
return;
|
||||
}
|
||||
|
||||
var sender = await _pairService.TryAddPairAsync(UserUID, payload.UID);
|
||||
var receiver = await _pairService.TryAddPairAsync(payload.UID, UserUID);
|
||||
var sender = await _pairService.TryAddPairAsync(UserUID, payload.UID).ConfigureAwait(false);
|
||||
var receiver = await _pairService.TryAddPairAsync(payload.UID, UserUID).ConfigureAwait(false);
|
||||
|
||||
var user = await DbContext.Users.SingleAsync(u => u.UID == UserUID).ConfigureAwait(false);
|
||||
var otherUser = await DbContext.Users.SingleAsync(u => u.UID == payload.UID).ConfigureAwait(false);
|
||||
@@ -304,7 +305,6 @@ public partial class LightlessHub
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private async Task NotifyBroadcastOwnerOfPairRequest(string targetHashedCid)
|
||||
{
|
||||
var myHashedCid = UserCharaIdent;
|
||||
@@ -360,23 +360,6 @@ public partial class LightlessHub
|
||||
|
||||
await Clients.User(entry.OwnerUID).Client_ReceiveBroadcastPairRequest(dto).ConfigureAwait(false);
|
||||
}
|
||||
private class PairingPayload
|
||||
{
|
||||
public string UID { get; set; } = string.Empty;
|
||||
public string HashedCid { get; set; } = string.Empty;
|
||||
public DateTime Timestamp { get; set; }
|
||||
}
|
||||
|
||||
public class BroadcastRedisEntry
|
||||
{
|
||||
public string HashedCID { get; set; } = string.Empty;
|
||||
public string OwnerUID { get; set; } = string.Empty;
|
||||
public string? GID { get; set; }
|
||||
|
||||
public bool OwnedBy(string userUid) => !string.IsNullOrEmpty(userUid) && string.Equals(OwnerUID, userUid, StringComparison.Ordinal);
|
||||
|
||||
public bool HasOwner() => !string.IsNullOrEmpty(OwnerUID);
|
||||
}
|
||||
|
||||
[Authorize(Policy = "Identified")]
|
||||
public async Task SetBroadcastStatus(bool enabled, GroupBroadcastRequestDto? groupDto = null)
|
||||
|
||||
@@ -162,7 +162,7 @@ public partial class LightlessHub : Hub<ILightlessHub>, ILightlessHub
|
||||
else
|
||||
{
|
||||
_lightlessMetrics.IncGaugeWithLabels(MetricsAPI.GaugeConnections, labels: Continent);
|
||||
|
||||
_lightlessMetrics.IncGaugeWithLabels(MetricsAPI.GaugeConnections, labels: Country);
|
||||
try
|
||||
{
|
||||
_logger.LogCallInfo(LightlessHubLogger.Args(_contextAccessor.GetIpAddress(), Context.ConnectionId, UserCharaIdent));
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace LightlessSyncServer.Models;
|
||||
|
||||
public class BroadcastRedisEntry()
|
||||
{
|
||||
public string? GID { get; set; }
|
||||
public string HashedCID { get; set; } = string.Empty;
|
||||
public string OwnerUID { get; set; } = string.Empty;
|
||||
|
||||
public bool OwnedBy(string userUid) => !string.IsNullOrEmpty(userUid) && string.Equals(OwnerUID, userUid, StringComparison.Ordinal);
|
||||
|
||||
public bool HasOwner() => !string.IsNullOrEmpty(OwnerUID);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace LightlessSyncServer.Models;
|
||||
|
||||
public class PairingPayload
|
||||
{
|
||||
public string UID { get; set; } = string.Empty;
|
||||
public string HashedCid { get; set; } = string.Empty;
|
||||
public DateTime Timestamp { get; set; }
|
||||
}
|
||||
@@ -41,7 +41,6 @@ public class Program
|
||||
metrics.SetGaugeTo(MetricsAPI.GaugeUsersRegistered, context.Users.AsNoTracking().Count());
|
||||
metrics.SetGaugeTo(MetricsAPI.GaugePairs, context.ClientPairs.AsNoTracking().Count());
|
||||
metrics.SetGaugeTo(MetricsAPI.GaugePairsPaused, context.Permissions.AsNoTracking().Where(p=>p.IsPaused).Count());
|
||||
|
||||
}
|
||||
|
||||
if (args.Length == 0 || !string.Equals(args[0], "dry", StringComparison.Ordinal))
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
using LightlessSync.API.Dto;
|
||||
using LightlessSync.API.SignalR;
|
||||
using LightlessSyncServer.Hubs;
|
||||
using LightlessSyncServer.Models;
|
||||
using LightlessSyncShared.Data;
|
||||
using LightlessSyncShared.Metrics;
|
||||
using LightlessSyncShared.Services;
|
||||
using LightlessSyncShared.Utils.Configuration;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using StackExchange.Redis;
|
||||
using StackExchange.Redis.Extensions.Core.Abstractions;
|
||||
using static LightlessSyncServer.Hubs.LightlessHub;
|
||||
|
||||
namespace LightlessSyncServer.Services;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user