Hero-admin: schakelaar Actief, destructieve knoppen rood, slide-kopjes, juiste voorvertoning in het focusvenster, status per foto

- Schakelaar (role=switch) Actief / Niet actief bij de knoppen, gedimde rij; 'Verberg voor schermlezers'; veld 'Beschrijving' binnen een groep 'Slide N'
- Alle foto's zonder complete set tonen 'Wordt verwerkt' (voortgang bij de foto die bezig is, 'in de wachtrij' bij de rest); totaal bovenaan telt ook nog niet opgeslagen foto's
- Per foto 'Verwerking afgerond' (zelfde weergave voor een hergebruikte foto), foto direct bruikbaar; niet-opgeslagen foto's worden zelf ververst (GET /hero/images/{id}), ook in een achtergrondtab
- Focusvenster toont de hele foto (full-preview in elke set, achtergrond-aanvulling voor oude sets) in plaats van de uitgesneden wide-variant (vervorming)
- Prullenbak en 'Wijzigingen weggooien' in de destructieve stijl
- upload-respons: reused (intern)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 23:26:47 +01:00
co-authored by Claude Sonnet 5.5
parent 9f07934f9e
commit 6999f5b2ba
25 changed files with 794 additions and 73 deletions
@@ -43,6 +43,9 @@ 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>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);
/// <summary>True when the background renderer gave up on the image after a few failed tries (until a retry or a restart).</summary>
bool IsRenderFailed(Guid imageId);
@@ -90,7 +93,7 @@ public class HeroImageService(
// The same photo again also gives up the failed state: the renderer tries it again when it is still pending.
signal?.Reset(existing.Id);
signal?.Notify();
return HeroMapping.ToImageDto(existing);
return HeroMapping.ToImageDto(existing) with { Reused = true };
}
await EnsureRoomAsync(admitted.Bytes.Length, cancellationToken);
@@ -161,6 +164,19 @@ public class HeroImageService(
public void NotifyPending() => signal?.Notify();
public async Task<HeroImageDto?> GetImageAsync(Guid imageId, CancellationToken cancellationToken)
{
var image = await repository.GetImageFreshAsync(imageId, cancellationToken);
if (image is null)
{
return null;
}
var failed = IsRenderFailed(imageId);
var progress = RenderProgress(imageId);
return HeroMapping.ToImageDto(image) with { Failed = failed, RenderDone = progress?.Done, RenderTotal = progress?.Total };
}
public bool IsRenderFailed(Guid imageId) => signal?.IsGivenUp(imageId) ?? false;
public (int Done, int Total)? RenderProgress(Guid imageId) => signal?.GetProgress(imageId);
@@ -177,7 +193,9 @@ public class HeroImageService(
var image = (await repository.GetImagesNeedingRenderAsync(cancellationToken)).FirstOrDefault(i => !skip.Contains(i.Id));
if (image is null)
{
return null;
// Nothing to cut: add the full-frame preview to complete sets that were made before it existed.
var old = (await repository.GetImagesNeedingPreviewAsync(cancellationToken)).FirstOrDefault(i => !skip.Contains(i.Id));
return old is null ? null : await AddPreviewAsync(old, cancellationToken);
}
try
@@ -195,6 +213,40 @@ public class HeroImageService(
}
}
/// <summary>Makes only the preview file of a complete set (one decode, one resize) and adds it to the set where it already is.</summary>
private async Task<Guid?> AddPreviewAsync(HeroImage image, CancellationToken cancellationToken)
{
try
{
using (await gate.EnterAsync(cancellationToken))
{
var file = await store.OpenReadAsync(image.OriginalKey, cancellationToken)
?? throw new ImageRejectedException(ImageRejection.Unavailable, "The stored original is missing.");
using var memory = new MemoryStream();
await using (file.Content)
{
await file.Content.CopyToAsync(memory, cancellationToken);
}
var storedFormat = ImageFormatExtensions.FromExtension(Path.GetExtension(image.OriginalKey).TrimStart('.'));
var spec = VariantPlanner.Preview(image.Width, image.Height, processor.SupportedOutput);
var rendered = (await processor.RenderSetAsync(memory.ToArray(), storedFormat, [spec], null, cancellationToken))[0];
var name = MediaPaths.FileName(spec.Ratio.Name, spec.Width, spec.Format);
await store.PutAsync($"{HeroMapping.Area}/{image.SetHash}/{name}", rendered.Bytes, cancellationToken);
image.Variants = [.. image.Variants, new HeroVariant(spec.Ratio.Name, rendered.Width, rendered.Height, spec.Format.MimeType(), name, rendered.Bytes.LongLength)];
}
await repository.SaveChangesAsync(cancellationToken);
logger.LogInformation("Hero image {ImageId}: the full-frame preview was added to its set.", image.Id);
return image.Id;
}
catch (Exception exception) when (exception is not OperationCanceledException)
{
logger.LogError(exception, "Hero image {ImageId}: adding the preview failed.", image.Id);
throw new HeroImageRenderException(image.Id, exception);
}
}
private async Task<Guid?> RenderAsync(HeroImage image, CancellationToken cancellationToken)
{
@@ -283,7 +335,9 @@ public class HeroImageService(
var ratios = new[] { Ratio.Wide, Ratio.Tall }
.Select(r => new RatioPlan(r, image.FocusFor(r.Name), VariantPlanner.DefaultWidths(r)))
.ToList();
var specs = VariantPlanner.Plan(image.Width, image.Height, ratios, processor.SupportedOutput);
var specs = VariantPlanner.Plan(image.Width, image.Height, ratios, processor.SupportedOutput).ToList();
// The whole picture, for the focus dialog of the admin (never published to a website).
specs.Add(VariantPlanner.Preview(image.Width, image.Height, processor.SupportedOutput));
progress?.Invoke(0, specs.Count);
var rendered = await processor.RenderSetAsync(original, storedFormat, specs, progress, cancellationToken);