[backend/api] Fix edge case where GetAvatar and GetBanner can be both IsAvatar and IsBanner

This commit is contained in:
pancakes 2025-01-30 22:26:39 +10:00 committed by Laura Hausmann
parent 6322d5fb91
commit 16a0a76528
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -117,6 +117,8 @@ public class ProfileController(
var user = HttpContext.GetUserOrFail(); var user = HttpContext.GetUserOrFail();
var file = await db.DriveFiles var file = await db.DriveFiles
.Include(p => p.UserAvatar)
.Include(p => p.UserBanner)
.FirstOrDefaultAsync(p => p.UserId == user.Id && p.UserAvatar != null) .FirstOrDefaultAsync(p => p.UserId == user.Id && p.UserAvatar != null)
?? throw GracefulException.RecordNotFound(); ?? throw GracefulException.RecordNotFound();
@ -129,8 +131,8 @@ public class ProfileController(
ContentType = file.Type, ContentType = file.Type,
Sensitive = file.IsSensitive, Sensitive = file.IsSensitive,
Description = file.Comment, Description = file.Comment,
IsAvatar = true, IsAvatar = file.UserAvatar != null,
IsBanner = false IsBanner = file.UserBanner != null
}; };
} }
@ -189,6 +191,8 @@ public class ProfileController(
var user = HttpContext.GetUserOrFail(); var user = HttpContext.GetUserOrFail();
var file = await db.DriveFiles var file = await db.DriveFiles
.Include(p => p.UserAvatar)
.Include(p => p.UserBanner)
.FirstOrDefaultAsync(p => p.UserId == user.Id && p.UserBanner != null) .FirstOrDefaultAsync(p => p.UserId == user.Id && p.UserBanner != null)
?? throw GracefulException.RecordNotFound(); ?? throw GracefulException.RecordNotFound();
@ -201,8 +205,8 @@ public class ProfileController(
ContentType = file.Type, ContentType = file.Type,
Sensitive = file.IsSensitive, Sensitive = file.IsSensitive,
Description = file.Comment, Description = file.Comment,
IsAvatar = false, IsAvatar = file.UserAvatar != null,
IsBanner = true IsBanner = file.UserBanner != null
}; };
} }