✈️ Better migration to new cloud files reference system

This commit is contained in:
2025-06-02 00:49:19 +08:00
parent 00229fd406
commit 3c52a6d787
22 changed files with 562 additions and 190 deletions

View File

@ -69,6 +69,10 @@ public class Profile : ModelBase
(Experience - Leveling.ExperiencePerLevel[Level]) * 100.0 /
(Leveling.ExperiencePerLevel[Level + 1] - Leveling.ExperiencePerLevel[Level]);
// Outdated fields, for backward compability
[MaxLength(32)] public string? PictureId { get; set; }
[MaxLength(32)] public string? BackgroundId { get; set; }
[Column(TypeName = "jsonb")] public CloudFileReferenceObject? Picture { get; set; }
[Column(TypeName = "jsonb")] public CloudFileReferenceObject? Background { get; set; }

View File

@ -21,8 +21,6 @@ public class AccountCurrentController(
AuthService auth
) : ControllerBase
{
private const string ProfilePictureFileUsageIdentifier = "profile";
[HttpGet]
[ProducesResponseType<Account>(StatusCodes.Status200OK)]
public async Task<ActionResult<Account>> GetCurrentIdentity()
@ -98,7 +96,7 @@ public class AccountCurrentController(
// Remove old references for the profile picture
if (profile.Picture is not null) {
var oldPictureRefs = await fileRefService.GetResourceReferencesAsync(profileResourceId, ProfilePictureFileUsageIdentifier);
var oldPictureRefs = await fileRefService.GetResourceReferencesAsync(profileResourceId, "profile.picture");
foreach (var oldRef in oldPictureRefs)
{
await fileRefService.DeleteReferenceAsync(oldRef.Id);
@ -110,7 +108,7 @@ public class AccountCurrentController(
// Create new reference
await fileRefService.CreateReferenceAsync(
picture.Id,
ProfilePictureFileUsageIdentifier,
"profile.picture",
profileResourceId
);
}
@ -124,7 +122,7 @@ public class AccountCurrentController(
// Remove old references for the profile background
if (profile.Background is not null) {
var oldBackgroundRefs = await fileRefService.GetResourceReferencesAsync(profileResourceId, ProfilePictureFileUsageIdentifier);
var oldBackgroundRefs = await fileRefService.GetResourceReferencesAsync(profileResourceId, "profile.background");
foreach (var oldRef in oldBackgroundRefs)
{
await fileRefService.DeleteReferenceAsync(oldRef.Id);
@ -136,7 +134,7 @@ public class AccountCurrentController(
// Create new reference
await fileRefService.CreateReferenceAsync(
background.Id,
ProfilePictureFileUsageIdentifier,
"profile.background",
profileResourceId
);
}

View File

@ -28,7 +28,7 @@ public class NotificationService(
{
var existingSubscription = await db.NotificationPushSubscriptions
.Where(s => s.AccountId == account.Id)
.Where(s => (s.DeviceId == deviceId || s.DeviceToken == deviceToken) && s.Provider == provider)
.Where(s => s.DeviceId == deviceId || s.DeviceToken == deviceToken)
.FirstOrDefaultAsync();
if (existingSubscription is not null)