Compare commits

..

3 Commits

Author SHA1 Message Date
cake
6bff57e8da Added null parameter 2025-10-26 18:57:44 +01:00
cake
3a9446f9ae Fixed update on image 2025-10-26 18:57:22 +01:00
cake
ae09d79577 fix image results 2025-10-26 17:43:49 +01:00
3 changed files with 13 additions and 21 deletions

View File

@@ -211,8 +211,7 @@ public partial class LightlessHub
if (isOwnerResult.ReferredGroup == null) return (false, null); if (isOwnerResult.ReferredGroup == null) return (false, null);
var groupPairSelf = await DbContext.GroupPairs.SingleOrDefaultAsync( var groupPairSelf = await DbContext.GroupPairs.SingleOrDefaultAsync(g => g.GroupGID == gid || g.Group.Alias == gid && g.GroupUserUID == UserUID).ConfigureAwait(false);
g => (g.GroupGID == gid || g.Group.Alias == gid) && g.GroupUserUID == UserUID).ConfigureAwait(false);
if (groupPairSelf == null || !groupPairSelf.IsModerator) return (false, null); if (groupPairSelf == null || !groupPairSelf.IsModerator) return (false, null);
return (true, isOwnerResult.ReferredGroup); return (true, isOwnerResult.ReferredGroup);

View File

@@ -799,12 +799,12 @@ public partial class LightlessHub
if (!hasRights) return; if (!hasRights) return;
var groupProfileDb = await DbContext.GroupProfiles var groupProfileDb = await DbContext.GroupProfiles
.Include(g => g.Group) .FirstOrDefaultAsync(g => g.Group.GID == dto.Group.GID || g.Group.Alias == dto.Group.GID,
.FirstOrDefaultAsync(g => g.GroupGID == dto.Group.GID, cancellationToken) cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
ImageCheckService.ImageLoadResult profileResult = null; ImageCheckService.ImageLoadResult profileResult = new();
ImageCheckService.ImageLoadResult bannerResult = null; ImageCheckService.ImageLoadResult bannerResult = new();
//Avatar image validation //Avatar image validation
if (!string.IsNullOrEmpty(dto.PictureBase64)) if (!string.IsNullOrEmpty(dto.PictureBase64))
@@ -830,33 +830,27 @@ public partial class LightlessHub
} }
} }
var sanitizedProfileImage = profileResult?.Base64Image;
var sanitizedBannerImage = bannerResult?.Base64Image;
if (groupProfileDb == null) if (groupProfileDb == null)
{ {
groupProfileDb = new GroupProfile groupProfileDb = new GroupProfile
{ {
GroupGID = dto.Group.GID, GroupGID = dto.Group.GID,
Group = group,
ProfileDisabled = false, ProfileDisabled = false,
IsNSFW = dto.IsNsfw ?? false, IsNSFW = dto.IsNsfw ?? false,
}; };
groupProfileDb.UpdateProfileFromDto(dto, sanitizedProfileImage, sanitizedBannerImage); groupProfileDb.UpdateProfileFromDto(dto, profileResult?.Base64Image, bannerResult?.Base64Image);
await DbContext.GroupProfiles.AddAsync(groupProfileDb, cancellationToken).ConfigureAwait(false); await DbContext.GroupProfiles.AddAsync(groupProfileDb, cancellationToken).ConfigureAwait(false);
} }
else else
{ {
groupProfileDb.Group ??= group;
if (groupProfileDb?.ProfileDisabled ?? false) if (groupProfileDb?.ProfileDisabled ?? false)
{ {
await Clients.Caller.Client_ReceiveServerMessage(MessageSeverity.Error, "Your profile was permanently disabled and cannot be edited").ConfigureAwait(false); await Clients.Caller.Client_ReceiveServerMessage(MessageSeverity.Error, "Your profile was permanently disabled and cannot be edited").ConfigureAwait(false);
return; return;
} }
groupProfileDb.UpdateProfileFromDto(dto, sanitizedProfileImage, sanitizedBannerImage); groupProfileDb.UpdateProfileFromDto(dto, profileResult?.Base64Image, bannerResult?.Base64Image);
var userIds = await DbContext.GroupPairs var userIds = await DbContext.GroupPairs
.Where(p => p.GroupGID == groupProfileDb.GroupGID) .Where(p => p.GroupGID == groupProfileDb.GroupGID)

View File

@@ -17,22 +17,22 @@ public static class Extensions
if (profile == null || dto == null) return; if (profile == null || dto == null) return;
profile.Base64GroupProfileImage = string.IsNullOrWhiteSpace(base64PictureString) ? null : base64PictureString; if (base64PictureString != null) profile.Base64GroupProfileImage = base64PictureString;
profile.Base64GroupBannerImage = string.IsNullOrWhiteSpace(base64BannerString) ? null : base64BannerString; if (base64BannerString != null) profile.Base64GroupBannerImage = base64BannerString;
if (dto.Tags != null) profile.Tags = dto.Tags; if (dto.Tags != null) profile.Tags = dto.Tags;
if (dto.Description != null) profile.Description = dto.Description; if (dto.Description != null) profile.Description = dto.Description;
if (dto.IsNsfw.HasValue) profile.IsNSFW = dto.IsNsfw.Value; if (dto.IsNsfw.HasValue) profile.IsNSFW = dto.IsNsfw.Value;
} }
public static void UpdateProfileFromDto(this UserProfileData profile, UserProfileDto dto, string? base64PictureString, string? base64BannerString = null) public static void UpdateProfileFromDto(this UserProfileData profile, UserProfileDto dto, string? base64PictureString = null, string? base64BannerString = null)
{ {
ArgumentNullException.ThrowIfNull(profile); ArgumentNullException.ThrowIfNull(profile);
ArgumentNullException.ThrowIfNull(dto); ArgumentNullException.ThrowIfNull(dto);
if (profile == null || dto == null) return; if (profile == null || dto == null) return;
profile.Base64ProfileImage = string.IsNullOrWhiteSpace(base64PictureString) ? null : base64PictureString; if (base64PictureString != null) profile.Base64ProfileImage = base64PictureString;
profile.Base64BannerImage = string.IsNullOrWhiteSpace(base64BannerString) ? null : base64BannerString; if (base64BannerString != null) profile.Base64BannerImage = base64BannerString;
if (dto.Tags != null) profile.Tags = dto.Tags; if (dto.Tags != null) profile.Tags = dto.Tags;
if (dto.Description != null) profile.UserDescription = dto.Description; if (dto.Description != null) profile.UserDescription = dto.Description;
if (dto.IsNSFW.HasValue) profile.IsNSFW = dto.IsNSFW.Value; if (dto.IsNSFW.HasValue) profile.IsNSFW = dto.IsNSFW.Value;
@@ -45,8 +45,7 @@ public static class Extensions
return new GroupProfileDto(Group: null, Description: null, Tags: null, PictureBase64: null, BannerBase64: null, IsNsfw: false, IsDisabled: false); return new GroupProfileDto(Group: null, Description: null, Tags: null, PictureBase64: null, BannerBase64: null, IsNsfw: false, IsDisabled: false);
} }
var groupData = groupProfile.Group?.ToGroupData() var groupData = groupProfile.Group?.ToGroupData();
?? (!string.IsNullOrWhiteSpace(groupProfile.GroupGID) ? new GroupData(groupProfile.GroupGID) : null);
return new GroupProfileDto( return new GroupProfileDto(
groupData, groupData,