Implemented default avatar

This commit is contained in:
Mia Rose Winter 2024-02-26 15:14:54 +01:00
parent a158bec075
commit 4b1b9ccd80
Signed by: miawinter
GPG key ID: 4B6F6A83178F595E

View file

@ -24,11 +24,13 @@ public class UserController(ImageService imageService, IDbContextFactory<Applica
var user = await context.Users.Include(u => u.ProfilePicture).FirstOrDefaultAsync(u => u.Id == userId); var user = await context.Users.Include(u => u.ProfilePicture).FirstOrDefaultAsync(u => u.Id == userId);
if (user is null) return NotFound(); if (user is null) return NotFound();
if (user.ProfilePicture is null) { if (user.ProfilePicture is null) {
return StatusCode(StatusCodes.Status204NoContent); return Redirect("/img/default_avatar.jpg");
} }
string? path = ImageService.GetPath(user.ProfilePicture.ImageId); string? path = ImageService.GetPath(user.ProfilePicture.ImageId);
if (path is null) return NotFound(); if (path is null) {
return Redirect("/img/default_avatar.jpg");
}
if (size < 800) return File(await ImageService.GetResized(path, size), ImageService.ImageMimeType); if (size < 800) return File(await ImageService.GetResized(path, size), ImageService.ImageMimeType);
return File(System.IO.File.OpenRead(path), ImageService.ImageMimeType); return File(System.IO.File.OpenRead(path), ImageService.ImageMimeType);