Optimized image storage
This commit is contained in:
parent
6e0b4f75b7
commit
cc8efee25f
|
@ -60,8 +60,10 @@
|
|||
var guid = await ImageService.StoreImageAsync(tempFilePath);
|
||||
if (!guid.HasValue) throw new ApplicationException("Processing Image failed.");
|
||||
|
||||
Guid? imageToDelete = null;
|
||||
await using var context = await ContextFactory.CreateDbContextAsync();
|
||||
if (User.ProfilePicture is not null) {
|
||||
imageToDelete = User.ProfilePicture.ImageId;
|
||||
context.Remove(User.ProfilePicture);
|
||||
}
|
||||
|
||||
|
@ -72,7 +74,9 @@
|
|||
context.Update(User);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
// TODO notify changed pfp
|
||||
if (imageToDelete is not null)
|
||||
ImageService.Delete(imageToDelete.Value);
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
string tempPath = await FileUtilities.StoreTemporary(args.File.OpenReadStream(MaxFileSize));
|
||||
await FileUploadedCallback.InvokeAsync(tempPath);
|
||||
Message = string.Empty;
|
||||
File.Delete(tempPath);
|
||||
} catch (Exception ex) {
|
||||
Message = "File upload failed: " + ex.Message;
|
||||
} finally {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using ImageMagick;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
|
||||
namespace Wave.Services;
|
||||
|
||||
|
@ -47,4 +48,9 @@ public class ImageService(ILogger<ImageService> logger) {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Delete(Guid imageId) {
|
||||
string path = Path.Combine(BasePath, imageId + ImageExtension);
|
||||
File.Delete(path);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue