Added tags on call for user profile calls, added disabled on syncshell profiles. reworked the calls

This commit is contained in:
CakeAndBanana
2025-10-19 20:58:07 +02:00
parent f35c0c4c2a
commit dba7536a7f
3 changed files with 125 additions and 46 deletions

View File

@@ -9,6 +9,8 @@ using LightlessSyncShared.Utils;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.SignalR;
using Microsoft.EntityFrameworkCore;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using System.Security.Cryptography;
namespace LightlessSyncServer.Hubs;
@@ -764,6 +766,11 @@ public partial class LightlessHub
return new GroupProfileDto(dto.Group, Description: null, Tags: null, PictureBase64: null, IsNsfw: false, IsDisabled: false);
}
if (data.ProfileDisabled)
{
return new GroupProfileDto(Group: dto.Group, Description: "This profile was permanently disabled", Tags: [], PictureBase64: null, IsNsfw: false, IsDisabled: true);
}
try
{
return data.ToDTO();
@@ -792,6 +799,39 @@ public partial class LightlessHub
cancellationToken)
.ConfigureAwait(false);
if (!string.IsNullOrEmpty(dto.PictureBase64))
{
byte[] imageData;
try
{
imageData = Convert.FromBase64String(dto.PictureBase64);
}
catch (FormatException)
{
await Clients.Caller.Client_ReceiveServerMessage(MessageSeverity.Error, "The provided image is not a valid Base64 string.").ConfigureAwait(false);
return;
}
MemoryStream ms = new(imageData);
await using (ms.ConfigureAwait(false))
{
var format = await Image.DetectFormatAsync(ms, RequestAbortedToken).ConfigureAwait(false);
if (!format.FileExtensions.Contains("png", StringComparer.OrdinalIgnoreCase))
{
await Clients.Caller.Client_ReceiveServerMessage(MessageSeverity.Error, "Your provided image file is not in PNG format").ConfigureAwait(false);
return;
}
using var image = Image.Load<Rgba32>(imageData);
if (image.Width > 512 || image.Height > 512 || (imageData.Length > 2000 * 1024))
{
await Clients.Caller.Client_ReceiveServerMessage(MessageSeverity.Error, "Your provided image file is larger than 512x512 or more than 2MiB").ConfigureAwait(false);
return;
}
}
}
if (groupProfileDb == null)
{
groupProfileDb = new GroupProfile
@@ -800,11 +840,18 @@ public partial class LightlessHub
ProfileDisabled = false,
IsNSFW = dto.IsNsfw ?? false,
};
groupProfileDb.UpdateProfileFromDto(dto);
await DbContext.GroupProfiles.AddAsync(groupProfileDb, cancellationToken).ConfigureAwait(false);
}
else
{
if (groupProfileDb?.ProfileDisabled ?? false)
{
await Clients.Caller.Client_ReceiveServerMessage(MessageSeverity.Error, "Your profile was permanently disabled and cannot be edited").ConfigureAwait(false);
return;
}
groupProfileDb.UpdateProfileFromDto(dto);
var userIds = await DbContext.GroupPairs