Fase 2 stap A: write-through van de Hero naar de bibliotheek (schakelaar uit), per-slide uitsnede en set in de bibliotheek
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -113,8 +113,12 @@ public class HeroImageService(
|
||||
ILogger<HeroImageService> logger,
|
||||
TimeProvider? time = null,
|
||||
IIndexHtmlCache? indexCache = null,
|
||||
HeroRenderSignal? signal = null) : IHeroImageService
|
||||
HeroRenderSignal? signal = null,
|
||||
IMediaLibrarySync? librarySync = null) : IHeroImageService
|
||||
{
|
||||
/// <summary>Mirrors the hero into the media library's tables (write-through, off unless switched on). Never throws.</summary>
|
||||
private Task SyncLibraryAsync() => librarySync?.SyncAsync(HeroMapping.Area, CancellationToken.None) ?? Task.CompletedTask;
|
||||
|
||||
private readonly TimeProvider _time = time ?? TimeProvider.System;
|
||||
|
||||
public async Task<HeroImageDto> UploadAsync(Stream upload, long declaredLength, Guid callerId, CancellationToken cancellationToken, string? originalFileName = null)
|
||||
@@ -137,6 +141,7 @@ public class HeroImageService(
|
||||
if (existing is not null && await FilesExistAsync(existing, cancellationToken))
|
||||
{
|
||||
await repository.SaveChangesAsync(cancellationToken);
|
||||
await SyncLibraryAsync();
|
||||
// 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();
|
||||
@@ -176,6 +181,7 @@ public class HeroImageService(
|
||||
}
|
||||
|
||||
await repository.SaveChangesAsync(cancellationToken);
|
||||
await SyncLibraryAsync();
|
||||
signal?.Notify();
|
||||
|
||||
logger.LogInformation("Hero image {ImageId} {Action} by user {UserId} ({Width}x{Height}); its variants are cut in the background", image.Id, existing is null ? "uploaded" : "repaired", callerId, image.Width, image.Height);
|
||||
@@ -222,6 +228,7 @@ public class HeroImageService(
|
||||
|
||||
ApplyFocus(image, request);
|
||||
await repository.SaveChangesAsync(cancellationToken);
|
||||
await SyncLibraryAsync();
|
||||
signal?.Reset(imageId);
|
||||
signal?.Notify();
|
||||
|
||||
@@ -242,6 +249,7 @@ public class HeroImageService(
|
||||
Apply(request.Wide, v => (slide.WideFocusX, slide.WideFocusY, slide.WideZoom) = v);
|
||||
Apply(request.Tall, v => (slide.TallFocusX, slide.TallFocusY, slide.TallZoom) = v);
|
||||
await repository.SaveChangesAsync(cancellationToken);
|
||||
await SyncLibraryAsync();
|
||||
signal?.Reset(slideId);
|
||||
signal?.Notify();
|
||||
|
||||
@@ -265,6 +273,7 @@ public class HeroImageService(
|
||||
}
|
||||
|
||||
await repository.SaveChangesAsync(cancellationToken);
|
||||
await SyncLibraryAsync();
|
||||
signal?.Reset(slideId);
|
||||
indexCache?.Invalidate();
|
||||
|
||||
@@ -454,6 +463,7 @@ public class HeroImageService(
|
||||
}
|
||||
|
||||
await repository.SaveChangesAsync(cancellationToken);
|
||||
await SyncLibraryAsync();
|
||||
indexCache?.Invalidate();
|
||||
logger.LogInformation("Hero slide {SlideId}: {Variants} variants cut in {Seconds:0.0} s", slide.Id, variants.Count, watch.Elapsed.TotalSeconds);
|
||||
return slide.Id;
|
||||
@@ -507,6 +517,7 @@ public class HeroImageService(
|
||||
}
|
||||
|
||||
await repository.SaveChangesAsync(cancellationToken);
|
||||
await SyncLibraryAsync();
|
||||
indexCache?.Invalidate();
|
||||
logger.LogInformation("Hero image {ImageId}: {Variants} variants cut in {Seconds:0.0} s", image.Id, variants.Count, watch.Elapsed.TotalSeconds);
|
||||
return image.Id;
|
||||
@@ -525,6 +536,7 @@ public class HeroImageService(
|
||||
repository.AddRetired(new HeroRetiredFile { Id = Guid.NewGuid(), Kind = "original", Key = image.OriginalKey, RetiredAt = now });
|
||||
repository.RemoveImage(image);
|
||||
await repository.SaveChangesAsync(cancellationToken);
|
||||
await SyncLibraryAsync();
|
||||
|
||||
logger.LogInformation("Hero image {ImageId} removed by user {UserId}", imageId, callerId);
|
||||
}
|
||||
@@ -548,6 +560,7 @@ public class HeroImageService(
|
||||
|
||||
image.DeletedAt = now;
|
||||
await repository.SaveChangesAsync(cancellationToken);
|
||||
await SyncLibraryAsync();
|
||||
indexCache?.Invalidate();
|
||||
|
||||
logger.LogInformation("Hero image {ImageId} moved to the trash by user {UserId} ({Slides} slides removed)", imageId, callerId, slides.Count);
|
||||
@@ -572,6 +585,7 @@ public class HeroImageService(
|
||||
var (setHash, originalKey) = (image.SetHash, image.OriginalKey);
|
||||
repository.RemoveImage(image);
|
||||
await repository.SaveChangesAsync(cancellationToken);
|
||||
await SyncLibraryAsync();
|
||||
|
||||
if (setHash.Length > 0 && !setShared)
|
||||
{
|
||||
@@ -598,6 +612,7 @@ public class HeroImageService(
|
||||
|
||||
image.DeletedAt = null;
|
||||
await repository.SaveChangesAsync(cancellationToken);
|
||||
await SyncLibraryAsync();
|
||||
signal?.Notify();
|
||||
|
||||
logger.LogInformation("Hero image {ImageId} restored from the trash by user {UserId}", imageId, callerId);
|
||||
|
||||
Reference in New Issue
Block a user