WIP: bulkbalk boven de lijst, definitief verwijderen en prullenbak legen, uitsnede direct zonder opslaan, teller per batch

This commit is contained in:
2026-11-17 16:58:23 +01:00
parent 8ad071da1c
commit 1384cafa7b
28 changed files with 816 additions and 134 deletions
@@ -3,6 +3,7 @@ using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using SlpModularCms.Core.Hosting.Website;
using SlpModularCms.Core.Media;
using SlpModularCms.Core.Media.Library;
using SlpModularCms.Modules.Hero.Data.Entities;
using SlpModularCms.Modules.Hero.Models;
using SlpModularCms.Modules.Hero.Repositories;
@@ -46,6 +47,13 @@ public interface IHeroImageService
/// <summary>The variant the renderer is busy with: (done, total), or null when the image is not being cut right now.</summary>
(int Done, int Total)? RenderProgress(Guid imageId);
/// <summary>
/// Applies a new crop to an image at once, WITHOUT saving the hero (Bryan, 2026-11-17: a new crop must not need another
/// click on Save). The new set is cut in the background and the image switches to it when it is complete, so what is live
/// changes only then. Returns the image as the admin sees it now (processing), or null when there is no such image.
/// </summary>
Task<HeroImageDto?> SetFocusAsync(Guid imageId, HeroFocusRequest request, Guid callerId, CancellationToken cancellationToken);
/// <summary>One image as the admin sees it now (including whether it is still being prepared). Null when there is no such image.</summary>
Task<HeroImageDto?> GetImageAsync(Guid imageId, CancellationToken cancellationToken);
@@ -77,6 +85,12 @@ public interface IHeroImageService
/// <summary>Takes an image out of the trash again. False when it is not in the trash.</summary>
Task<bool> RestoreAsync(Guid imageId, Guid callerId, CancellationToken cancellationToken);
/// <summary>
/// Removes an image that is in the trash FOR GOOD: its original and its set (a file another image shares stays) and the
/// record. Refused when the image is not in the trash or a slide uses it after all.
/// </summary>
Task<MediaPurgeOutcome> PurgeAsync(Guid imageId, Guid callerId, CancellationToken cancellationToken);
}
public class HeroImageService(
@@ -188,6 +202,23 @@ public class HeroImageService(
public void NotifyPending() => signal?.Notify();
public async Task<HeroImageDto?> SetFocusAsync(Guid imageId, HeroFocusRequest request, Guid callerId, CancellationToken cancellationToken)
{
var image = await repository.GetImageAsync(imageId, cancellationToken);
if (image is null)
{
return null;
}
ApplyFocus(image, request);
await repository.SaveChangesAsync(cancellationToken);
signal?.Reset(imageId);
signal?.Notify();
logger.LogInformation("Hero image {ImageId} got a new crop from user {UserId}; its variants are cut in the background", imageId, callerId);
return await GetImageAsync(imageId, cancellationToken);
}
public async Task<HeroImageDto?> GetImageAsync(Guid imageId, CancellationToken cancellationToken)
{
var image = await repository.GetImageFreshAsync(imageId, cancellationToken);
@@ -369,6 +400,40 @@ public class HeroImageService(
return slides.Count;
}
public async Task<MediaPurgeOutcome> PurgeAsync(Guid imageId, Guid callerId, CancellationToken cancellationToken)
{
var image = await repository.GetImageIncludingTrashedAsync(imageId, cancellationToken);
if (image is null || image.DeletedAt is null)
{
return MediaPurgeOutcome.NotInTrash;
}
if (await repository.ImageInUseAsync(imageId, cancellationToken))
{
return MediaPurgeOutcome.InUse;
}
// The row first (nothing refers to it any more), then the files; a file another image still shares stays.
var (setShared, originalShared) = await repository.FilesSharedWithOthersAsync(imageId, image.SetHash, image.OriginalKey, cancellationToken);
var (setHash, originalKey) = (image.SetHash, image.OriginalKey);
repository.RemoveImage(image);
await repository.SaveChangesAsync(cancellationToken);
if (setHash.Length > 0 && !setShared)
{
await store.DeleteSetAsync(HeroMapping.Area, setHash, cancellationToken);
}
if (!originalShared)
{
await store.DeleteAsync(originalKey, cancellationToken);
}
indexCache?.Invalidate();
logger.LogInformation("Hero image {ImageId} removed for good by user {UserId}", imageId, callerId);
return MediaPurgeOutcome.Purged;
}
public async Task<bool> RestoreAsync(Guid imageId, Guid callerId, CancellationToken cancellationToken)
{
var image = await repository.GetImageIncludingTrashedAsync(imageId, cancellationToken);