Compare commits
11 Commits
sql-thing
...
lodestone-
| Author | SHA1 | Date | |
|---|---|---|---|
| 0f95f26c1c | |||
| 8e36b062fd | |||
| ee69df8081 | |||
| f29c874515 | |||
|
|
b84d6c35d6 | ||
| bd03fa6762 | |||
|
|
8cde3b4933 | ||
|
|
0c357aaf7c | ||
|
|
ae09d79577 | ||
|
|
cc24dc067e | ||
| 6ac56d38c0 |
@@ -211,7 +211,8 @@ public partial class LightlessHub
|
||||
|
||||
if (isOwnerResult.ReferredGroup == null) return (false, null);
|
||||
|
||||
var groupPairSelf = await DbContext.GroupPairs.SingleOrDefaultAsync(g => g.GroupGID == gid || g.Group.Alias == gid && g.GroupUserUID == UserUID).ConfigureAwait(false);
|
||||
var groupPairSelf = await DbContext.GroupPairs.SingleOrDefaultAsync(
|
||||
g => (g.GroupGID == gid || g.Group.Alias == gid) && g.GroupUserUID == UserUID).ConfigureAwait(false);
|
||||
if (groupPairSelf == null || !groupPairSelf.IsModerator) return (false, null);
|
||||
|
||||
return (true, isOwnerResult.ReferredGroup);
|
||||
|
||||
@@ -799,12 +799,12 @@ public partial class LightlessHub
|
||||
if (!hasRights) return;
|
||||
|
||||
var groupProfileDb = await DbContext.GroupProfiles
|
||||
.FirstOrDefaultAsync(g => g.Group.GID == dto.Group.GID || g.Group.Alias == dto.Group.GID,
|
||||
cancellationToken)
|
||||
.Include(g => g.Group)
|
||||
.FirstOrDefaultAsync(g => g.GroupGID == dto.Group.GID, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
ImageCheckService.ImageLoadResult profileResult = null;
|
||||
ImageCheckService.ImageLoadResult bannerResult = null;
|
||||
ImageCheckService.ImageLoadResult profileResult = new();
|
||||
ImageCheckService.ImageLoadResult bannerResult = new();
|
||||
|
||||
//Avatar image validation
|
||||
if (!string.IsNullOrEmpty(dto.PictureBase64))
|
||||
@@ -830,40 +830,46 @@ public partial class LightlessHub
|
||||
}
|
||||
}
|
||||
|
||||
var sanitizedProfileImage = profileResult?.Base64Image;
|
||||
var sanitizedBannerImage = bannerResult?.Base64Image;
|
||||
|
||||
if (groupProfileDb == null)
|
||||
{
|
||||
groupProfileDb = new GroupProfile
|
||||
{
|
||||
GroupGID = dto.Group.GID,
|
||||
Group = group,
|
||||
ProfileDisabled = false,
|
||||
IsNSFW = dto.IsNsfw ?? false,
|
||||
};
|
||||
|
||||
groupProfileDb.UpdateProfileFromDto(dto, profileResult.Base64Image, bannerResult.Base64Image);
|
||||
groupProfileDb.UpdateProfileFromDto(dto, sanitizedProfileImage, sanitizedBannerImage);
|
||||
await DbContext.GroupProfiles.AddAsync(groupProfileDb, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
groupProfileDb.Group ??= group;
|
||||
|
||||
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, profileResult.Base64Image, bannerResult.Base64Image);
|
||||
groupProfileDb.UpdateProfileFromDto(dto, sanitizedProfileImage, sanitizedBannerImage);
|
||||
}
|
||||
|
||||
var userIds = await DbContext.GroupPairs
|
||||
.Where(p => p.GroupGID == groupProfileDb.GroupGID)
|
||||
.Select(p => p.GroupUserUID)
|
||||
.ToListAsync(cancellationToken)
|
||||
var userIds = await DbContext.GroupPairs
|
||||
.Where(p => p.GroupGID == groupProfileDb.GroupGID)
|
||||
.Select(p => p.GroupUserUID)
|
||||
.ToListAsync(cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (userIds.Count > 0)
|
||||
{
|
||||
var profileDto = groupProfileDb.ToDTO();
|
||||
await Clients.Users(userIds).Client_GroupSendProfile(profileDto)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (userIds.Count > 0)
|
||||
{
|
||||
var profileDto = groupProfileDb.ToDTO();
|
||||
await Clients.Users(userIds).Client_GroupSendProfile(profileDto)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
await DbContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
@@ -1128,7 +1128,7 @@ public partial class LightlessHub
|
||||
|
||||
if (!string.Equals(dto.User.UID, UserUID, StringComparison.Ordinal)) throw new HubException("Cannot modify profile data for anyone but yourself");
|
||||
|
||||
var existingData = await DbContext.UserProfileData.SingleOrDefaultAsync(u => u.UserUID == dto.User.UID, cancellationToken: RequestAbortedToken).ConfigureAwait(false);
|
||||
var profileData = await DbContext.UserProfileData.SingleOrDefaultAsync(u => u.UserUID == dto.User.UID, cancellationToken: RequestAbortedToken).ConfigureAwait(false);
|
||||
|
||||
ImageCheckService.ImageLoadResult profileResult = new();
|
||||
ImageCheckService.ImageLoadResult bannerResult = new();
|
||||
@@ -1157,35 +1157,33 @@ public partial class LightlessHub
|
||||
}
|
||||
}
|
||||
|
||||
if (existingData != null)
|
||||
if (profileData != null)
|
||||
{
|
||||
if (existingData.FlaggedForReport)
|
||||
if (profileData.FlaggedForReport)
|
||||
{
|
||||
await Clients.Caller.Client_ReceiveServerMessage(MessageSeverity.Error, "Your profile is currently flagged for report and cannot be edited").ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (existingData.ProfileDisabled)
|
||||
if (profileData.ProfileDisabled)
|
||||
{
|
||||
await Clients.Caller.Client_ReceiveServerMessage(MessageSeverity.Error, "Your profile was permanently disabled and cannot be edited").ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
existingData.UpdateProfileFromDto(dto, profileResult.Base64Image, bannerResult.Base64Image);
|
||||
profileData.UpdateProfileFromDto(dto, profileResult.Base64Image, bannerResult.Base64Image);
|
||||
}
|
||||
else
|
||||
{
|
||||
UserProfileData newUserProfileData = new()
|
||||
profileData = new()
|
||||
{
|
||||
UserUID = dto.User.UID,
|
||||
Base64ProfileImage = dto.ProfilePictureBase64 ?? null,
|
||||
UserDescription = dto.Description ?? null,
|
||||
IsNSFW = dto.IsNSFW ?? false,
|
||||
};
|
||||
|
||||
existingData.UpdateProfileFromDto(dto, profileResult.Base64Image, bannerResult.Base64Image);
|
||||
profileData.UpdateProfileFromDto(dto, profileResult.Base64Image, bannerResult.Base64Image);
|
||||
|
||||
await DbContext.UserProfileData.AddAsync(newUserProfileData, cancellationToken).ConfigureAwait(false);
|
||||
await DbContext.UserProfileData.AddAsync(profileData, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,22 +17,22 @@ public static class Extensions
|
||||
|
||||
if (profile == null || dto == null) return;
|
||||
|
||||
profile.Base64GroupProfileImage = string.IsNullOrWhiteSpace(base64PictureString) ? null : base64PictureString;
|
||||
profile.Base64GroupBannerImage = string.IsNullOrWhiteSpace(base64BannerString) ? null : base64BannerString;
|
||||
if (base64PictureString != null) profile.Base64GroupProfileImage = base64PictureString;
|
||||
if (base64BannerString != null) profile.Base64GroupBannerImage = base64BannerString;
|
||||
if (dto.Tags != null) profile.Tags = dto.Tags;
|
||||
if (dto.Description != null) profile.Description = dto.Description;
|
||||
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(dto);
|
||||
|
||||
if (profile == null || dto == null) return;
|
||||
|
||||
profile.Base64ProfileImage = string.IsNullOrWhiteSpace(base64PictureString) ? null : base64PictureString;
|
||||
profile.Base64BannerImage = string.IsNullOrWhiteSpace(base64BannerString) ? null : base64BannerString;
|
||||
if (base64PictureString != null) profile.Base64ProfileImage = base64PictureString;
|
||||
if (base64BannerString != null) profile.Base64BannerImage = base64BannerString;
|
||||
if (dto.Tags != null) profile.Tags = dto.Tags;
|
||||
if (dto.Description != null) profile.UserDescription = dto.Description;
|
||||
if (dto.IsNSFW.HasValue) profile.IsNSFW = dto.IsNSFW.Value;
|
||||
@@ -45,7 +45,8 @@ public static class Extensions
|
||||
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(
|
||||
groupData,
|
||||
|
||||
@@ -329,13 +329,12 @@ public partial class LightlessWizardModule : InteractionModuleBase
|
||||
|
||||
private int? ParseCharacterIdFromLodestoneUrl(string lodestoneUrl)
|
||||
{
|
||||
var regex = new Regex(@"https:\/\/(na|eu|de|fr|jp)\.finalfantasyxiv\.com\/lodestone\/character\/\d+");
|
||||
var regex = new Regex(@"^https:\/\/(na|eu|de|fr|jp)\.finalfantasyxiv\.com\/lodestone\/character\/(\d{8})/?$");
|
||||
var matches = regex.Match(lodestoneUrl);
|
||||
var isLodestoneUrl = matches.Success;
|
||||
if (!isLodestoneUrl || matches.Groups.Count < 1) return null;
|
||||
var stringId = matches.Groups[2].ToString();
|
||||
|
||||
lodestoneUrl = matches.Groups[0].ToString();
|
||||
var stringId = lodestoneUrl.Split('/', StringSplitOptions.RemoveEmptyEntries).Last();
|
||||
if (!int.TryParse(stringId, out int lodestoneId))
|
||||
{
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user