Hero-admin: meerdere foto's tegelijk, slepen, niet-opgeslagen waarschuwing, begrijpelijke teksten, rustige wachtanimatie

- Meerdere bestanden kiezen of slepen (2 tegelijk, per bestand voortgang en reden bij falen, volgorde van kiezen), uploadlimiet standaard 100 per uur
- Volgorde ook met slepen (greepje, toetsenbord), pijltjes blijven
- Waarschuwing bij niet-opgeslagen wijzigingen (badge, beforeunload, bevestiging bij navigeren, vergelijking met laatst opgeslagen stand)
- Teksten zonder vakjargon, uitleg per onderdeel, formaten en limieten van de host (GET /hero/images/limits)
- Shimmer (CSS, reduced-motion) op foto's die nog verwerkt worden

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 21:56:10 +01:00
co-authored by Claude Sonnet 5.5
parent 49302c3228
commit 9d647bb049
20 changed files with 900 additions and 98 deletions
@@ -310,7 +310,7 @@ public static class ServiceCollectionExtensions
var key = string.IsNullOrEmpty(user) ? ClientPartitionKey.For(context) : "user:" + user;
return RateLimitPartition.GetFixedWindowLimiter(key, _ => new FixedWindowRateLimiterOptions
{
PermitLimit = settings.GetValue<int>("PermitLimit", 20),
PermitLimit = settings.GetValue<int>("PermitLimit", 100),
Window = TimeSpan.FromSeconds(settings.GetValue<int>("WindowSeconds", 3600)),
QueueLimit = 0
});
@@ -189,4 +189,17 @@ public class HeroFocusSaveTests
await act.Should().ThrowAsync<HeroImageNotFoundException>();
}
[Fact]
public void TheUploadLimits_ListTheFormatsTheHostAccepts_InPlainWords()
{
using var rig = new HeroTestRig();
var limits = HeroMapping.UploadLimits(rig.Status, rig.Media);
limits.Formats.Should().Contain(["JPEG", "PNG", "WebP"]).And.OnlyHaveUniqueItems();
limits.Formats.Should().BeEquivalentTo(rig.Status.AcceptedInput.Select(f => f == SlpModularCms.Core.Media.ImageFormat.Jpeg ? "JPEG" : f == SlpModularCms.Core.Media.ImageFormat.WebP ? "WebP" : f.ToString().ToUpperInvariant()));
limits.MaxUploadBytes.Should().Be(rig.Media.MaxUploadBytes);
limits.MaxMegapixels.Should().Be((int)(rig.Media.MaxPixels / 1_000_000));
}
}
@@ -67,7 +67,7 @@ public class HeroController(IHeroService service, IPublicHeroService publicServi
[ApiController]
[Route("hero/images")]
[Authorize(Policy = "AdminOnly")]
public class HeroImagesController(IHeroImageService service, IOptions<MediaOptions> media) : ControllerBase
public class HeroImagesController(IHeroImageService service, IOptions<MediaOptions> media, MediaStatus mediaStatus) : ControllerBase
{
/// <summary>The body limit leaves room for the multipart envelope around the file limit of <see cref="MediaOptions.MaxUploadBytes"/>.</summary>
private const long RequestLimit = 12 * 1024 * 1024;
@@ -95,6 +95,11 @@ public class HeroImagesController(IHeroImageService service, IOptions<MediaOptio
}
}
/// <summary>The formats and limits an upload has to meet on this host (what the validation uses).</summary>
[HttpGet("limits")]
[ProducesResponseType<HeroUploadLimitsDto>(StatusCodes.Status200OK)]
public ActionResult<HeroUploadLimitsDto> Limits() => HeroMapping.UploadLimits(mediaStatus, media.Value);
/// <summary>Lets the background renderer try an image it gave up on again.</summary>
[HttpPost("{id:guid}/retry")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
@@ -259,3 +259,6 @@ public static class HeroText
return builder.ToString().Trim();
}
}
/// <summary>What an upload is allowed to be on this host, for the admin to show: derived from the same sources as the validation.</summary>
public record HeroUploadLimitsDto(IReadOnlyList<string> Formats, long MaxUploadBytes, int MaxMegapixels);
@@ -33,6 +33,20 @@ public static class HeroMapping
{
public const string Area = "hero";
/// <summary>The accepted upload formats (as the host allows them right now) and limits, in the words an administrator knows.</summary>
public static HeroUploadLimitsDto UploadLimits(MediaStatus status, MediaOptions limits)
=> new(
status.AcceptedInput.OrderBy(f => f).Select(DisplayName).ToList(),
limits.MaxUploadBytes,
(int)Math.Max(1, limits.MaxPixels / 1_000_000));
private static string DisplayName(ImageFormat format) => format switch
{
ImageFormat.Jpeg => "JPEG",
ImageFormat.WebP => "WebP",
_ => format.ToString().ToUpperInvariant(),
};
/// <summary>The set hash the image should have at its current focus.</summary>
public static string TargetSetHash(HeroImage image)
=> MediaPaths.SetHash(image.OriginalSha256, [("wide", image.FocusFor("wide")), ("tall", image.FocusFor("tall"))]);
+11 -11
View File
@@ -7,41 +7,41 @@
"tooManyLines": "The title can have at most {max} lines."
},
"tagline": {
"tooLong": "The tagline can have at most {max} characters."
"tooLong": "The short text above the title can have at most {max} characters."
},
"lead": {
"tooLong": "The introduction can have at most {max} characters."
},
"display": {
"invalid": "The display must be 'single' or 'slideshow'."
"invalid": "Choose ‘Single’ or ‘Slideshow’."
},
"button": {
"incomplete": "A button needs both a label and a target.",
"labelTooLong": "The button label can have at most {max} characters.",
"targetTooLong": "The button target can have at most {max} characters.",
"targetInvalid": "Choose an #anchor, a /path or an https:// address.",
"targetInvalid": "Choose a part of the page (for example #contact), a page of the site (for example /privacy) or a full web address (https://…).",
"tooMany": "At most {max} buttons are possible."
},
"schedule": {
"endAfterStart": "The end must be after the start."
},
"slide": {
"imageRequired": "Every slide needs an image.",
"imageUnknown": "An image of a slide does not exist (any more).",
"altRequired": "Give a description (alt text) or mark the image as decorative.",
"altTooLong": "The alt text can have at most {max} characters.",
"idUnknown": "A slide does not belong to this hero."
"imageRequired": "Every image in the list needs a photo.",
"imageUnknown": "An image in the list does not exist (any more).",
"altRequired": "Give a description or choose ‘Decoration only’.",
"altTooLong": "The description can have at most {max} characters.",
"idUnknown": "An image in the list does not belong to this hero."
},
"focus": {
"invalid": "The focus point must be between 0 and 1 and the zoom between 1 and {maxZoom}."
"invalid": "The point of the subject must be inside the photo and the zoom between 1 and {maxZoom}."
}
},
"image": {
"inUse": "This image is still used by a slide.",
"inUse": "This image is still used in the hero.",
"notFound": "This image does not exist.",
"rejected": {
"tooLarge": "The image is too large (at most {max} MB).",
"unsupportedFormat": "This file type is not supported. Choose a JPEG, PNG, WebP or another common image file.",
"unsupportedFormat": "This file type is not supported. The types that work are listed above the upload button.",
"corrupt": "The image could not be read or is damaged.",
"tooManyPixels": "The image has too many pixels. Choose a smaller image.",
"timeout": "Processing the image took too long. Try a smaller image.",
+11 -11
View File
@@ -7,41 +7,41 @@
"tooManyLines": "De titel mag maximaal {max} regels hebben."
},
"tagline": {
"tooLong": "De tagline mag maximaal {max} tekens bevatten."
"tooLong": "De korte tekst boven de titel mag maximaal {max} tekens bevatten."
},
"lead": {
"tooLong": "De introductietekst mag maximaal {max} tekens bevatten."
},
"display": {
"invalid": "De weergave moet 'enkel' of 'diavoorstelling' zijn."
"invalid": "Kies ‘Enkel’ of ‘Diavoorstelling’."
},
"button": {
"incomplete": "Een knop heeft zowel een tekst als een doel nodig.",
"labelTooLong": "De knoptekst mag maximaal {max} tekens bevatten.",
"targetTooLong": "Het doel van een knop mag maximaal {max} tekens bevatten.",
"targetInvalid": "Kies een #anker, een /pad of een https://-adres.",
"targetInvalid": "Kies een onderdeel van de pagina (bijvoorbeeld #contact), een pagina van de site (bijvoorbeeld /privacy) of een volledig webadres (https://…).",
"tooMany": "Er zijn maximaal {max} knoppen mogelijk."
},
"schedule": {
"endAfterStart": "Het einde moet na het begin liggen."
},
"slide": {
"imageRequired": "Elke slide heeft een afbeelding nodig.",
"imageUnknown": "Een afbeelding van een slide bestaat niet (meer).",
"altRequired": "Geef een beschrijving (alt-tekst) of markeer de afbeelding als decoratief.",
"altTooLong": "De alt-tekst mag maximaal {max} tekens bevatten.",
"idUnknown": "Een slide hoort niet bij deze hero."
"imageRequired": "Elke afbeelding in de lijst heeft een foto nodig.",
"imageUnknown": "Een afbeelding in de lijst bestaat niet (meer).",
"altRequired": "Geef een beschrijving of kies ‘Alleen versiering’.",
"altTooLong": "De beschrijving mag maximaal {max} tekens bevatten.",
"idUnknown": "Een afbeelding in de lijst hoort niet bij deze hero."
},
"focus": {
"invalid": "Het focuspunt moet tussen 0 en 1 liggen en de zoom tussen 1 en {maxZoom}."
"invalid": "Het punt van het onderwerp moet binnen de foto liggen en het inzoomen tussen 1 en {maxZoom}."
}
},
"image": {
"inUse": "Deze afbeelding wordt nog gebruikt door een slide.",
"inUse": "Deze afbeelding wordt nog gebruikt in de hero.",
"notFound": "Deze afbeelding bestaat niet.",
"rejected": {
"tooLarge": "De afbeelding is te groot (maximaal {max} MB).",
"unsupportedFormat": "Dit bestandstype wordt niet ondersteund. Kies een JPEG-, PNG-, WebP- of ander gangbaar afbeeldingsbestand.",
"unsupportedFormat": "Dit bestandstype wordt niet ondersteund. Boven de uploadknop staat welke typen kunnen.",
"corrupt": "De afbeelding kon niet worden gelezen of is beschadigd.",
"tooManyPixels": "De afbeelding heeft te veel pixels. Kies een kleinere afbeelding.",
"timeout": "Het verwerken van de afbeelding duurde te lang. Probeer een kleinere afbeelding.",