Mediabibliotheek fase A: read-only gebruikscontract, Hero-provider, opruimselectie en selectiecomponenten
Continuous Integration / config-sls (pull_request) Successful in 7s
Continuous Integration / config-asf (pull_request) Successful in 7s
Continuous Integration / changes (pull_request) Successful in 26s
Continuous Integration / compile-sites (pull_request) Successful in 1m50s
Continuous Integration / backend-build (pull_request) Successful in 1m53s
Continuous Integration / vulnerability-scan (pull_request) Successful in 1m53s
Continuous Integration / frontend-prepare (pull_request) Successful in 2m18s
Continuous Integration / frontend-build (pull_request) Successful in 56s
Continuous Integration / frontend-lint (pull_request) Successful in 2m20s
Continuous Integration / frontend-test (pull_request) Successful in 2m31s
Continuous Integration / backend-test (pull_request) Successful in 3m7s
Continuous Integration / publish-sls-test (pull_request) Skipped
Continuous Integration / publish-sls-production (pull_request) Skipped
Continuous Integration / deploy-sls-test (pull_request) Skipped
Continuous Integration / deploy-sls-production (pull_request) Skipped
Continuous Integration / publish-asf-test (pull_request) Skipped
Continuous Integration / deploy-asf-test (pull_request) Skipped
Continuous Integration / smoke-sls-test (pull_request) Skipped
Continuous Integration / smoke-asf-test (pull_request) Skipped

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 13:47:10 +01:00
co-authored by Claude Sonnet 5.5
parent 22e077b41b
commit 7e2e6a430f
17 changed files with 760 additions and 0 deletions
@@ -0,0 +1,55 @@
using SlpModularCms.Core.Media;
using SlpModularCms.Core.Media.Library;
using SlpModularCms.Modules.Hero.Data.Entities;
using SlpModularCms.Modules.Hero.Repositories;
namespace SlpModularCms.Modules.Hero.Services;
/// <summary>
/// Tells the media library which hero images exist and where they are used (one use per slide, with its position in the
/// hero). Read-only: nothing of the hero changes through this class.
/// </summary>
public class HeroMediaUsageProvider(IHeroRepository repository) : IMediaUsageProvider
{
public const string SlideKind = "slide";
public string Module => HeroMapping.Area;
public async Task<IReadOnlyList<MediaPhoto>> ListPhotosAsync(CancellationToken cancellationToken)
{
var images = await repository.GetAllImagesReadOnlyAsync(cancellationToken);
return images
.Select(i => new MediaPhoto(Module, i.Id, i.Bytes, i.Width, i.Height, i.CreatedAt, Thumbnail(i)))
.ToList();
}
public async Task<IReadOnlyList<MediaUse>> ListUsesAsync(IReadOnlyCollection<Guid> photoIds, CancellationToken cancellationToken)
{
var wanted = photoIds.ToHashSet();
var slides = await repository.GetAllSlidesReadOnlyAsync(cancellationToken);
// The position of a slide is its place in its hero, in display order (1-based), also for slides that are off.
var uses = new List<MediaUse>();
foreach (var hero in slides.GroupBy(s => s.HeroId))
{
var ordered = hero.OrderBy(s => s.SortOrder).ThenBy(s => s.Id).ToList();
for (var index = 0; index < ordered.Count; index++)
{
var slide = ordered[index];
if (wanted.Contains(slide.ImageId))
{
uses.Add(new MediaUse(Module, slide.ImageId, SlideKind, index + 1, slide.IsActive));
}
}
}
return uses;
}
/// <summary>The smallest published WebP of the set; null while the set is not cut yet.</summary>
private static string? Thumbnail(HeroImage image)
{
var pick = HeroMapping.Published(image).Where(v => v.Type == ImageFormat.WebP.MimeType()).OrderBy(v => v.Width).FirstOrDefault();
return pick is null || string.IsNullOrEmpty(image.SetHash) ? null : MediaPaths.Url(HeroMapping.Area, image.SetHash, pick.FileName);
}
}