Mediascherm: paneel Controle bibliotheek (read-check in gewone taal, stand van de schakelaars)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -113,11 +113,15 @@ public class MediaLibraryControllerTests
|
||||
verifier.CheckAsync(Arg.Any<CancellationToken>()).Returns(new MediaReadCheck("hero", MediaReadMode.Compare, 3, 2, ["photo x is missing in the library"]));
|
||||
var reader = Substitute.For<IMediaLibraryReader>();
|
||||
reader.Mode.Returns(MediaReadMode.Compare);
|
||||
var switches = Substitute.For<IMediaLibrarySwitchState>();
|
||||
switches.Current.Returns(new MediaLibrarySwitches(true, true, MediaReadMode.Compare));
|
||||
|
||||
var result = await new MediaLibraryController(library, new Clock(), null, [verifier], reader).ReadCheck(CancellationToken.None);
|
||||
var result = await new MediaLibraryController(library, new Clock(), null, [verifier], reader, switches).ReadCheck(CancellationToken.None);
|
||||
|
||||
var response = result.Should().BeOfType<OkObjectResult>().Subject.Value.Should().BeOfType<MediaReadCheckResponse>().Subject;
|
||||
response.Mode.Should().Be("compare");
|
||||
response.CopyOnStartup.Should().BeTrue();
|
||||
response.DualWrite.Should().BeTrue();
|
||||
response.Modules.Should().ContainSingle().Which.Should().Match<MediaReadCheckDto>(m => m.Module == "hero" && m.Photos == 3 && m.Uses == 2 && !m.Matches && m.Differences.Count == 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -89,6 +89,7 @@ public static class ServiceCollectionExtensions
|
||||
services.TryAddScoped<Media.Library.IMediaLibraryService, Media.Library.MediaLibraryService>();
|
||||
services.TryAddScoped<Media.Library.IMediaLibrarySync, Media.Library.NoMediaLibrarySync>();
|
||||
services.TryAddScoped<Media.Library.IMediaLibraryReader, Media.Library.NoMediaLibraryReader>();
|
||||
services.TryAddSingleton<Media.Library.IMediaLibrarySwitchState, Media.Library.NoMediaLibrarySwitchState>();
|
||||
services.TryAddSingleton(sp =>
|
||||
new ResetCooldown(sp.GetRequiredService<TimeProvider>(), TimeSpan.FromMinutes(sp.GetRequiredService<IOptions<PasswordResetSettings>>().Value.CooldownMinutes)));
|
||||
services.AddScoped<IPasswordResetService, PasswordResetService>();
|
||||
|
||||
@@ -23,7 +23,10 @@ public sealed record MediaPhotoDto(
|
||||
/// <summary>The result of comparing a module's own tables with the library tables (read switch, phase 2 step C).</summary>
|
||||
public sealed record MediaReadCheckDto(string Module, string Mode, int Photos, int Uses, bool Matches, IReadOnlyList<string> Differences);
|
||||
|
||||
public sealed record MediaReadCheckResponse(string Mode, IReadOnlyList<MediaReadCheckDto> Modules);
|
||||
/// <param name="Mode">The read switch: off, compare or on.</param>
|
||||
/// <param name="CopyOnStartup">The copy switch (start-up copy into the library tables).</param>
|
||||
/// <param name="DualWrite">The write-through switch.</param>
|
||||
public sealed record MediaReadCheckResponse(string Mode, IReadOnlyList<MediaReadCheckDto> Modules, bool CopyOnStartup = false, bool DualWrite = false);
|
||||
|
||||
public sealed record MediaLibraryDto(IReadOnlyList<MediaPhotoDto> Photos, IReadOnlyList<string> Modules);
|
||||
|
||||
@@ -54,7 +57,7 @@ public sealed record MediaTrashResponse(IReadOnlyList<MediaUseResultDto> Results
|
||||
[ApiController]
|
||||
[Route("media-library")]
|
||||
[Authorize(Policy = "AdminOnly")]
|
||||
public class MediaLibraryController(IMediaLibraryService library, TimeProvider time, MediaStorageUsage? storage = null, IEnumerable<IMediaReadVerifier>? verifiers = null, IMediaLibraryReader? reader = null) : ControllerBase
|
||||
public class MediaLibraryController(IMediaLibraryService library, TimeProvider time, MediaStorageUsage? storage = null, IEnumerable<IMediaReadVerifier>? verifiers = null, IMediaLibraryReader? reader = null, IMediaLibrarySwitchState? switches = null) : ControllerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Compares what each module holds with what the library's own tables hold and lists every difference. Read-only; works
|
||||
@@ -71,7 +74,8 @@ public class MediaLibraryController(IMediaLibraryService library, TimeProvider t
|
||||
results.Add(new MediaReadCheckDto(check.Module, check.Mode.ToString().ToLowerInvariant(), check.Photos, check.Uses, check.Matches, check.Differences.Take(50).ToList()));
|
||||
}
|
||||
|
||||
return Ok(new MediaReadCheckResponse((reader?.Mode ?? MediaReadMode.Off).ToString().ToLowerInvariant(), results));
|
||||
var state = switches?.Current ?? new MediaLibrarySwitches(false, false, reader?.Mode ?? MediaReadMode.Off);
|
||||
return Ok(new MediaReadCheckResponse(state.ReadFromLibrary.ToString().ToLowerInvariant(), results, state.CopyOnStartup, state.DualWrite));
|
||||
}
|
||||
|
||||
[HttpGet("photos")]
|
||||
|
||||
@@ -33,6 +33,21 @@ public sealed class NoMediaLibraryReader : IMediaLibraryReader
|
||||
public Task<IReadOnlyList<MediaUseSnapshot>> ListUsesAsync(string module, CancellationToken cancellationToken) => Task.FromResult<IReadOnlyList<MediaUseSnapshot>>([]);
|
||||
}
|
||||
|
||||
/// <summary>The current state of the migration switches (for the check in the library screen).</summary>
|
||||
public sealed record MediaLibrarySwitches(bool CopyOnStartup, bool DualWrite, MediaReadMode ReadFromLibrary);
|
||||
|
||||
/// <summary>Tells the current state of the migration switches.</summary>
|
||||
public interface IMediaLibrarySwitchState
|
||||
{
|
||||
MediaLibrarySwitches Current { get; }
|
||||
}
|
||||
|
||||
/// <summary>The default: no library tables, so every switch is off.</summary>
|
||||
public sealed class NoMediaLibrarySwitchState : IMediaLibrarySwitchState
|
||||
{
|
||||
public MediaLibrarySwitches Current => new(false, false, MediaReadMode.Off);
|
||||
}
|
||||
|
||||
/// <summary>What a comparison of a module's own tables with the library tables found. <c>Differences</c> is empty when they agree.</summary>
|
||||
public sealed record MediaReadCheck(string Module, MediaReadMode Mode, int Photos, int Uses, IReadOnlyList<string> Differences)
|
||||
{
|
||||
|
||||
@@ -40,6 +40,7 @@ public class MediaModule : IModule
|
||||
services.AddScoped<MediaLibraryCopier>();
|
||||
services.Replace(ServiceDescriptor.Scoped<IMediaLibrarySync, MediaLibrarySync>());
|
||||
services.Replace(ServiceDescriptor.Scoped<IMediaLibraryReader, MediaLibraryReader>());
|
||||
services.Replace(ServiceDescriptor.Singleton<IMediaLibrarySwitchState, MediaLibrarySwitchState>());
|
||||
services.AddHostedService<MediaLibraryCopyService>();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
using Microsoft.Extensions.Options;
|
||||
using SlpModularCms.Core.Media.Library;
|
||||
|
||||
namespace SlpModularCms.Modules.Media.Services;
|
||||
|
||||
/// <summary>The migration switches as configured right now (read from the options on every call).</summary>
|
||||
public sealed class MediaLibrarySwitchState(IOptionsMonitor<MediaLibraryOptions> options) : IMediaLibrarySwitchState
|
||||
{
|
||||
public MediaLibrarySwitches Current => new(options.CurrentValue.CopyOnStartup, options.CurrentValue.DualWrite, options.CurrentValue.ReadFromLibrary);
|
||||
}
|
||||
Reference in New Issue
Block a user