H4: hero in de eerste HTML (regio, preload), gedeeld datablok met contributors (Offerings byte-identiek), ASF golden files, volledige pijplijntest

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 15:58:02 +01:00
co-authored by Claude Sonnet 5.5
parent ae04120d8c
commit 4369c905cd
41 changed files with 1402 additions and 31 deletions
@@ -48,8 +48,10 @@ public class HeroImageService(
using var admitted = await guard.AdmitAsync(upload, declaredLength, cancellationToken);
var sha = Convert.ToHexStringLower(SHA256.HashData(admitted.Bytes));
// The same photo again is the same image. When its files are gone (a lost or restored media directory) the upload
// repairs them from the file that was just sent.
var existing = await repository.GetImageBySha256Async(sha, cancellationToken);
if (existing is not null)
if (existing is not null && await FilesExistAsync(existing, cancellationToken))
{
return HeroMapping.ToImageDto(existing);
}
@@ -62,7 +64,7 @@ public class HeroImageService(
var original = stripped ?? admitted.Bytes;
var storedFormat = stripped is not null && format == ImageFormat.Heic ? ImageFormat.Jpeg : format;
var image = new HeroImage
var image = existing ?? new HeroImage
{
Id = Guid.NewGuid(),
OriginalSha256 = sha,
@@ -79,13 +81,35 @@ public class HeroImageService(
await store.PutAsync(image.OriginalKey, original, cancellationToken);
await store.PutSetAsync(HeroMapping.Area, image.SetHash, files, cancellationToken);
repository.AddImage(image);
if (existing is null)
{
repository.AddImage(image);
}
await repository.SaveChangesAsync(cancellationToken);
logger.LogInformation("Hero image {ImageId} uploaded by user {UserId} ({Width}x{Height}, {Variants} variants)", image.Id, callerId, image.Width, image.Height, image.Variants.Count);
logger.LogInformation("Hero image {ImageId} {Action} by user {UserId} ({Width}x{Height}, {Variants} variants)", image.Id, existing is null ? "uploaded" : "repaired", callerId, image.Width, image.Height, image.Variants.Count);
return HeroMapping.ToImageDto(image);
}
private async Task<bool> FilesExistAsync(HeroImage image, CancellationToken cancellationToken)
{
if (!await store.ExistsAsync(image.OriginalKey, cancellationToken))
{
return false;
}
foreach (var variant in image.Variants)
{
if (!await store.ExistsAsync($"{HeroMapping.Area}/{image.SetHash}/{variant.FileName}", cancellationToken))
{
return false;
}
}
return true;
}
public async Task<HeroImageDto> SetFocusAsync(Guid imageId, HeroFocusRequest request, Guid callerId, CancellationToken cancellationToken)
{
var image = await repository.GetImageAsync(imageId, cancellationToken) ?? throw new HeroImageNotFoundException();