diff --git a/Wave/Components/Account/Pages/Manage/Index.razor b/Wave/Components/Account/Pages/Manage/Index.razor index 068ae13..2e4de2c 100644 --- a/Wave/Components/Account/Pages/Manage/Index.razor +++ b/Wave/Components/Account/Pages/Manage/Index.razor @@ -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); } } diff --git a/Wave/Components/FileUploadComponent.razor b/Wave/Components/FileUploadComponent.razor index e65623a..5a0ce2e 100644 --- a/Wave/Components/FileUploadComponent.razor +++ b/Wave/Components/FileUploadComponent.razor @@ -30,7 +30,8 @@ try { string tempPath = await FileUtilities.StoreTemporary(args.File.OpenReadStream(MaxFileSize)); await FileUploadedCallback.InvokeAsync(tempPath); - Message = string.Empty; + Message = string.Empty; + File.Delete(tempPath); } catch (Exception ex) { Message = "File upload failed: " + ex.Message; } finally { diff --git a/Wave/Services/ImageService.cs b/Wave/Services/ImageService.cs index e9d9a8d..cbd5331 100644 --- a/Wave/Services/ImageService.cs +++ b/Wave/Services/ImageService.cs @@ -1,4 +1,5 @@ using ImageMagick; +using static System.Net.Mime.MediaTypeNames; namespace Wave.Services; @@ -47,4 +48,9 @@ public class ImageService(ILogger logger) { return null; } } + + public void Delete(Guid imageId) { + string path = Path.Combine(BasePath, imageId + ImageExtension); + File.Delete(path); + } } \ No newline at end of file