Fase 3c (code, nog niet uitgerold): foto's altijd in de bibliotheektabel, HeroImages-migratie met controle, schakelaars en hulpmiddelen weg
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -113,24 +113,8 @@ public class HeroImageService(
|
||||
ILogger<HeroImageService> logger,
|
||||
TimeProvider? time = null,
|
||||
IIndexHtmlCache? indexCache = null,
|
||||
HeroRenderSignal? signal = null,
|
||||
IMediaLibrarySync? librarySync = null,
|
||||
IHeroLegacyImageMirror? legacyMirror = null) : IHeroImageService
|
||||
HeroRenderSignal? signal = null) : IHeroImageService
|
||||
{
|
||||
/// <summary>Mirrors the hero into the media library's tables (write-through, off unless switched on). Never throws.</summary>
|
||||
private async Task SyncLibraryAsync()
|
||||
{
|
||||
if (legacyMirror is not null)
|
||||
{
|
||||
await legacyMirror.SyncAsync(CancellationToken.None);
|
||||
}
|
||||
|
||||
if (librarySync is not null)
|
||||
{
|
||||
await librarySync.SyncAsync(HeroMapping.Area, CancellationToken.None);
|
||||
}
|
||||
}
|
||||
|
||||
private readonly TimeProvider _time = time ?? TimeProvider.System;
|
||||
|
||||
public async Task<HeroImageDto> UploadAsync(Stream upload, long declaredLength, Guid callerId, CancellationToken cancellationToken, string? originalFileName = null)
|
||||
@@ -153,7 +137,6 @@ 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();
|
||||
@@ -193,7 +176,6 @@ 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);
|
||||
@@ -240,7 +222,6 @@ public class HeroImageService(
|
||||
|
||||
ApplyFocus(image, request);
|
||||
await repository.SaveChangesAsync(cancellationToken);
|
||||
await SyncLibraryAsync();
|
||||
signal?.Reset(imageId);
|
||||
signal?.Notify();
|
||||
|
||||
@@ -261,7 +242,6 @@ 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();
|
||||
|
||||
@@ -285,7 +265,6 @@ public class HeroImageService(
|
||||
}
|
||||
|
||||
await repository.SaveChangesAsync(cancellationToken);
|
||||
await SyncLibraryAsync();
|
||||
signal?.Reset(slideId);
|
||||
indexCache?.Invalidate();
|
||||
|
||||
@@ -475,7 +454,6 @@ 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;
|
||||
@@ -529,7 +507,6 @@ 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;
|
||||
@@ -548,7 +525,6 @@ 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);
|
||||
}
|
||||
@@ -572,7 +548,6 @@ 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);
|
||||
@@ -597,7 +572,6 @@ public class HeroImageService(
|
||||
var (setHash, originalKey) = (image.SetHash, image.OriginalKey);
|
||||
repository.RemoveImage(image);
|
||||
await repository.SaveChangesAsync(cancellationToken);
|
||||
await SyncLibraryAsync();
|
||||
|
||||
if (setHash.Length > 0 && !setShared)
|
||||
{
|
||||
@@ -624,7 +598,6 @@ 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