Fase 3a: bibliotheektabellen krijgen set, varianten en uitsnede-overrides (additief), kopie, schrijf-door en controle vullen en vergelijken ze

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 00:00:59 +01:00
co-authored by Claude Sonnet 5.5
parent e1f2abf004
commit 53e1e3c8a6
14 changed files with 429 additions and 9 deletions
@@ -80,3 +80,4 @@ Kept while Bryan is away (2026-11-17): no questions to him, a most probable assu
| 49 | **Compact tiles in the clean-up and the delete confirmation** (product owner request, 2026-11-17). | `PhotoSelectionList` has a third layout `compact` (3/4/6/8 columns, square small thumbnails, name and a short usage line on one truncated line each, full name, date, size and usage in the tooltip; checkbox chip, whole-tile select, select all and the bulk bar unchanged). The clean-up dialog uses it. The "places that lose the photo" list in the second step of `DeleteDialog` is a read-only compact grid of the same kind. `PurgeDialog` shows no photo list (only a count), so it is unchanged; the library tiles and the ImagePicker are unchanged. | Long row lists again in the dialogs (much scrolling, little overview). | `PhotoSelectionList.tsx` (`layout="compact"`), `CleanupDialog.tsx`, `DeleteDialog.tsx` (`delete-places`) | | 49 | **Compact tiles in the clean-up and the delete confirmation** (product owner request, 2026-11-17). | `PhotoSelectionList` has a third layout `compact` (3/4/6/8 columns, square small thumbnails, name and a short usage line on one truncated line each, full name, date, size and usage in the tooltip; checkbox chip, whole-tile select, select all and the bulk bar unchanged). The clean-up dialog uses it. The "places that lose the photo" list in the second step of `DeleteDialog` is a read-only compact grid of the same kind. `PurgeDialog` shows no photo list (only a count), so it is unchanged; the library tiles and the ImagePicker are unchanged. | Long row lists again in the dialogs (much scrolling, little overview). | `PhotoSelectionList.tsx` (`layout="compact"`), `CleanupDialog.tsx`, `DeleteDialog.tsx` (`delete-places`) |
| 50 | **Step C reads the library screen's data from the library tables, not the hero admin** (2026-11-17). | The read switch (`off`/`compare`/`on`) changes where the library screen gets photos, trash and uses; the hero's admin and public endpoints keep their own tables because they need the variants, which move in phase 3. Thumbnails come from the hero. `compare` only logs and reports (`GET media-library/read-check`); `on` falls back to the hero's tables when the library cannot be read. | Serve the hero admin from the library too: needs the variants (and cut sets) in the library tables first. | `HeroMediaUsageProvider`, `IMediaLibraryReader`, `MediaLibraryReader`, `MediaReadComparer` | | 50 | **Step C reads the library screen's data from the library tables, not the hero admin** (2026-11-17). | The read switch (`off`/`compare`/`on`) changes where the library screen gets photos, trash and uses; the hero's admin and public endpoints keep their own tables because they need the variants, which move in phase 3. Thumbnails come from the hero. `compare` only logs and reports (`GET media-library/read-check`); `on` falls back to the hero's tables when the library cannot be read. | Serve the hero admin from the library too: needs the variants (and cut sets) in the library tables first. | `HeroMediaUsageProvider`, `IMediaLibraryReader`, `MediaLibraryReader`, `MediaReadComparer` |
| 51 | **"Controle bibliotheek" panel in the library screen** (SLS-Main for Bryan, 2026-11-17). | A small panel under the storage meter, for administrators (the whole screen is admin only), asks `GET media-library/read-check` only when its button is clicked and says in plain words (nl/en) whether the library tables match each module or lists the differences, plus the state of the three switches (copy, write-through, reading off/compare/on; the response now carries `copyOnStartup` and `dualWrite`). It changes nothing. Always shown, not only on test. | Show it only when the read switch is not off: Bryan could then not check before switching. | `LibraryCheck.tsx`, `MediaLibraryController.ReadCheck`, `IMediaLibrarySwitchState` | | 51 | **"Controle bibliotheek" panel in the library screen** (SLS-Main for Bryan, 2026-11-17). | A small panel under the storage meter, for administrators (the whole screen is admin only), asks `GET media-library/read-check` only when its button is clicked and says in plain words (nl/en) whether the library tables match each module or lists the differences, plus the state of the three switches (copy, write-through, reading off/compare/on; the response now carries `copyOnStartup` and `dualWrite`). It changes nothing. Always shown, not only on test. | Show it only when the read switch is not off: Bryan could then not check before switching. | `LibraryCheck.tsx`, `MediaLibraryController.ReadCheck`, `IMediaLibrarySwitchState` |
| 52 | **Phase 3a: the library tables hold what the hero needs to publish** (2026-11-18). | Additive migration `AddHeroPhotoColumns` of the Media module: `MediaAssets.SetHash`, `MediaAssets.Variants` (the module's own JSON), the wide/tall overrides of the photo's crop, and `MediaUses.Variants`. The copy, the write-through and the verification fill and compare them; the read check shows a difference in them. Nothing reads them to publish yet (that is 3b). | Store the variants relationally: more tables for no gain while only the hero publishes from here. | `MediaEntities`, `MediaLibraryCopier`, `HeroMediaMigrationSource` |
@@ -86,6 +86,11 @@ public static class MediaReadComparer
differences.Add($"photo {own.Id}: hash, key or size differs"); differences.Add($"photo {own.Id}: hash, key or size differs");
} }
if (own.SetHash != copy.SetHash || own.VariantsJson != copy.VariantsJson)
{
differences.Add($"photo {own.Id}: set hash or variants differ");
}
if ((own.DeletedAt is null) != (copy.DeletedAt is null)) if ((own.DeletedAt is null) != (copy.DeletedAt is null))
{ {
differences.Add($"photo {own.Id}: trash state differs"); differences.Add($"photo {own.Id}: trash state differs");
@@ -113,7 +118,7 @@ public static class MediaReadComparer
continue; continue;
} }
if (own.AssetId != copy.AssetId || own.Position != copy.Position || own.Active != copy.Active || own.SetHash != copy.SetHash) if (own.AssetId != copy.AssetId || own.Position != copy.Position || own.Active != copy.Active || own.SetHash != copy.SetHash || own.VariantsJson != copy.VariantsJson)
{ {
differences.Add($"use {own.Id}: photo, position, active flag or set hash differs"); differences.Add($"use {own.Id}: photo, position, active flag or set hash differs");
} }
@@ -7,6 +7,8 @@ public sealed record MediaCropSnapshot(string Ratio, double X, double Y, double
/// A photo as a module holds it today, for copying into the library's own tables. Same ids, hashes and set hashes as the /// A photo as a module holds it today, for copying into the library's own tables. Same ids, hashes and set hashes as the
/// module uses, so no public address changes (migration plan, decision 13). /// module uses, so no public address changes (migration plan, decision 13).
/// </summary> /// </summary>
// Phase 3: the snapshots also carry what the module needs to publish the photo from the library tables: the variants of the
// current set (opaque JSON, the module's own format) and the wide and tall overrides of the photo's crop (null = none).
public sealed record MediaAssetSnapshot( public sealed record MediaAssetSnapshot(
Guid Id, Guid Id,
string Module, string Module,
@@ -25,10 +27,17 @@ public sealed record MediaAssetSnapshot(
Guid CreatedByUserId, Guid CreatedByUserId,
string? OriginalFileName, string? OriginalFileName,
DateTimeOffset? LastUsedAt, DateTimeOffset? LastUsedAt,
DateTimeOffset? DeletedAt); DateTimeOffset? DeletedAt,
string? VariantsJson = null,
double? WideFocusX = null,
double? WideFocusY = null,
double? WideZoom = null,
double? TallFocusX = null,
double? TallFocusY = null,
double? TallZoom = null);
/// <summary>One place a photo is used, as a module holds it today. <c>Crops</c> are the crops of THIS use (crop per use); null = the crops of its photo.</summary> /// <summary>One place a photo is used, as a module holds it today. <c>Crops</c> are the crops of THIS use (crop per use); null = the crops of its photo.</summary>
public sealed record MediaUseSnapshot(Guid Id, Guid AssetId, string Module, string PlaceKind, int Position, bool Active, string SetHash, IReadOnlyList<MediaCropSnapshot>? Crops = null); public sealed record MediaUseSnapshot(Guid Id, Guid AssetId, string Module, string PlaceKind, int Position, bool Active, string SetHash, IReadOnlyList<MediaCropSnapshot>? Crops = null, string? VariantsJson = null);
/// <summary> /// <summary>
/// What a module offers so the library can copy its photos and uses into its own tables. Read-only: the module's data is /// What a module offers so the library can copy its photos and uses into its own tables. Read-only: the module's data is
@@ -1,6 +1,7 @@
using FluentAssertions; using FluentAssertions;
using NSubstitute; using NSubstitute;
using SlpModularCms.Core.Media.Library; using SlpModularCms.Core.Media.Library;
using SlpModularCms.Modules.Hero.Data.Entities;
using SlpModularCms.Modules.Hero.Models; using SlpModularCms.Modules.Hero.Models;
using SlpModularCms.Modules.Hero.Services; using SlpModularCms.Modules.Hero.Services;
using Xunit; using Xunit;
@@ -73,4 +74,21 @@ public class HeroLibrarySyncTests
second.Crops.Should().NotBeNull(); second.Crops.Should().NotBeNull();
second.Crops!.Single(c => c.Ratio == "wide").X.Should().BeApproximately(0.1, 0.0001); second.Crops!.Single(c => c.Ratio == "wide").X.Should().BeApproximately(0.1, 0.0001);
} }
[Fact]
public async Task The_migration_source_gives_the_variants_in_the_format_the_hero_stores_them_and_the_overrides_of_the_crop()
{
using var rig = new HeroTestRig();
var image = await rig.Upload(HeroTestRig.Photo());
var id = Guid.Parse(image.Id);
await rig.Images.SetFocusAsync(id, new HeroFocusRequest(new FocusDto(0.5, 0.5, 1), new FocusDto(0.2, 0.3, 1.5), null), HeroTestRig.Admin, CancellationToken.None);
await rig.RenderPending();
var asset = (await new HeroMediaMigrationSource(rig.Repository).ListAssetsAsync(CancellationToken.None)).Single();
var stored = rig.Db.HeroImages.Single(i => i.Id == id);
asset.SetHash.Should().Be(stored.SetHash);
System.Text.Json.JsonSerializer.Deserialize<List<HeroVariant>>(asset.VariantsJson!).Should().Equal(stored.Variants);
(asset.WideFocusX, asset.WideFocusY, asset.WideZoom).Should().Be((0.2, 0.3, 1.5));
(asset.TallFocusX, asset.TallFocusY, asset.TallZoom).Should().Be((null, null, null));
}
} }
@@ -40,7 +40,8 @@ public class HeroMediaMigrationSource(IHeroRepository repository) : IMediaMigrat
} }
} }
uses.Add(new MediaUseSnapshot(slide.Id, slide.ImageId, Module, HeroMediaUsageProvider.SlideKind, index + 1, slide.IsActive, setHash, crops)); var variantsJson = slide.HasOwnCrop && slide.Variants is { Count: > 0 } ? Json(slide.Variants) : null;
uses.Add(new MediaUseSnapshot(slide.Id, slide.ImageId, Module, HeroMediaUsageProvider.SlideKind, index + 1, slide.IsActive, setHash, crops, variantsJson));
} }
} }
@@ -66,7 +67,17 @@ public class HeroMediaMigrationSource(IHeroRepository repository) : IMediaMigrat
i.CreatedByUserId, i.CreatedByUserId,
i.OriginalFileName, i.OriginalFileName,
i.LastUsedAt, i.LastUsedAt,
i.DeletedAt); i.DeletedAt,
Json(i.Variants),
i.WideFocusX,
i.WideFocusY,
i.WideZoom,
i.TallFocusX,
i.TallFocusY,
i.TallZoom);
/// <summary>The variants as the hero stores them (the same serializer as its database column), so they can go back unchanged.</summary>
public static string Json(IEnumerable<HeroVariant> variants) => System.Text.Json.JsonSerializer.Serialize(variants.ToList(), (System.Text.Json.JsonSerializerOptions?)null);
private static MediaCropSnapshot Crop(string ratio, HeroImage image) private static MediaCropSnapshot Crop(string ratio, HeroImage image)
{ {
@@ -112,4 +112,19 @@ public class MediaLibraryCopierTests : IDisposable
report.Assets.Should().Be(2); report.Assets.Should().Be(2);
report.Uses.Should().Be(1); report.Uses.Should().Be(1);
} }
[Fact]
public async Task Copies_and_verifies_the_variants_the_set_hash_and_the_crop_overrides_of_a_photo_and_of_a_use()
{
var variants = "[{\"Ratio\":\"wide\",\"Width\":480,\"Height\":270,\"Type\":\"image/webp\",\"FileName\":\"wide-480.webp\",\"Bytes\":1234}]";
var a = Asset() with { VariantsJson = variants, WideFocusX = 0.1, WideFocusY = 0.2, WideZoom = 1.3, TallFocusX = 0.7 };
var use = Use(a) with { VariantsJson = variants, SetHash = "fedcba9876543210" };
await Copier(new Source("hero", [a], [use])).CopyAsync(CancellationToken.None);
var photo = await _db.MediaAssets.SingleAsync();
photo.Variants.Should().Be(variants);
photo.SetHash.Should().Be(a.SetHash);
(photo.WideFocusX, photo.WideFocusY, photo.WideZoom, photo.TallFocusX, photo.TallFocusY).Should().Be((0.1, 0.2, 1.3, 0.7, null));
(await _db.MediaUses.SingleAsync()).Variants.Should().Be(variants);
}
} }
@@ -67,4 +67,19 @@ public class MediaLibraryReaderTests : IDisposable
differences.Should().Contain(d => d.StartsWith("use ") && d.Contains("differs")); differences.Should().Contain(d => d.StartsWith("use ") && d.Contains("differs"));
differences.Should().Contain(d => d.Contains(ghost.Id.ToString())); differences.Should().Contain(d => d.Contains(ghost.Id.ToString()));
} }
[Fact]
public async Task Reads_back_the_variants_and_set_hash_and_the_comparer_notices_a_difference_in_them()
{
var hero = Asset("hero") with { VariantsJson = "[{\"Ratio\":\"wide\"}]", WideFocusX = 0.3 };
await new MediaLibraryCopier(_db, [new Source("hero", [hero], [])], NullLogger<MediaLibraryCopier>.Instance).CopyAsync(CancellationToken.None);
var reader = new MediaLibraryReader(_db, Options.Create(new MediaLibraryOptions()));
var back = (await reader.ListAssetsAsync("hero", CancellationToken.None)).Single();
back.VariantsJson.Should().Be(hero.VariantsJson);
back.SetHash.Should().Be(hero.SetHash);
back.WideFocusX.Should().Be(0.3);
MediaReadComparer.Compare([hero], [], [back], []).Should().BeEmpty();
MediaReadComparer.Compare([hero with { VariantsJson = "[]" }], [], [back], []).Should().Contain(d => d.Contains("set hash or variants differ"));
}
} }
@@ -24,6 +24,17 @@ public class MediaAsset
public double DefaultFocusY { get; set; } = 0.5; public double DefaultFocusY { get; set; } = 0.5;
public double DefaultZoom { get; set; } = 1.0; public double DefaultZoom { get; set; } = 1.0;
// Phase 3: what the owning module needs to publish the photo from here. The overrides of the photo's crop per ratio
// (null = the default crop), the hash of the current set and its variants as the module's own JSON.
public double? WideFocusX { get; set; }
public double? WideFocusY { get; set; }
public double? WideZoom { get; set; }
public double? TallFocusX { get; set; }
public double? TallFocusY { get; set; }
public double? TallZoom { get; set; }
public string? SetHash { get; set; }
public string? Variants { get; set; }
public DateTimeOffset CreatedAt { get; set; } public DateTimeOffset CreatedAt { get; set; }
public Guid CreatedByUserId { get; set; } public Guid CreatedByUserId { get; set; }
public string? OriginalFileName { get; set; } public string? OriginalFileName { get; set; }
@@ -56,4 +67,7 @@ public class MediaAssetUse
/// <summary>The crops of this use as JSON: <c>[{ratio, x, y, zoom}]</c>. Empty for a natural-ratio use.</summary> /// <summary>The crops of this use as JSON: <c>[{ratio, x, y, zoom}]</c>. Empty for a natural-ratio use.</summary>
public string Crops { get; set; } = "[]"; public string Crops { get; set; } = "[]";
/// <summary>Phase 3: the variants of this use's own set as the module's own JSON (null = the photo's).</summary>
public string? Variants { get; set; }
} }
@@ -22,6 +22,8 @@ public class MediaDbContext(DbContextOptions<MediaDbContext> options) : DbContex
entity.Property(e => e.OriginalKey).IsRequired().HasMaxLength(200); entity.Property(e => e.OriginalKey).IsRequired().HasMaxLength(200);
entity.Property(e => e.SourceFormat).IsRequired().HasMaxLength(10); entity.Property(e => e.SourceFormat).IsRequired().HasMaxLength(10);
entity.Property(e => e.OriginalFileName).HasMaxLength(200); entity.Property(e => e.OriginalFileName).HasMaxLength(200);
entity.Property(e => e.SetHash).HasMaxLength(16);
entity.Property(e => e.Variants).HasColumnType("longtext");
entity.HasIndex(e => e.CreatedAt); entity.HasIndex(e => e.CreatedAt);
entity.HasMany(e => e.Uses).WithOne(u => u.Asset).HasForeignKey(u => u.AssetId).OnDelete(DeleteBehavior.Cascade); entity.HasMany(e => e.Uses).WithOne(u => u.Asset).HasForeignKey(u => u.AssetId).OnDelete(DeleteBehavior.Cascade);
}); });
@@ -34,6 +36,7 @@ public class MediaDbContext(DbContextOptions<MediaDbContext> options) : DbContex
entity.Property(e => e.PlaceKind).IsRequired().HasMaxLength(20); entity.Property(e => e.PlaceKind).IsRequired().HasMaxLength(20);
entity.Property(e => e.SetHash).IsRequired().HasMaxLength(16); entity.Property(e => e.SetHash).IsRequired().HasMaxLength(16);
entity.Property(e => e.Crops).IsRequired().HasColumnType("longtext"); entity.Property(e => e.Crops).IsRequired().HasColumnType("longtext");
entity.Property(e => e.Variants).HasColumnType("longtext");
entity.HasIndex(e => e.AssetId); entity.HasIndex(e => e.AssetId);
}); });
} }
@@ -0,0 +1,182 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SlpModularCms.Modules.Media.Data;
#nullable disable
namespace SlpModularCms.Modules.Media.Migrations
{
[DbContext(typeof(MediaDbContext))]
[Migration("20261117225718_AddHeroPhotoColumns")]
partial class AddHeroPhotoColumns
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "10.0.9")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
modelBuilder.Entity("SlpModularCms.Modules.Media.Data.Entities.MediaAsset", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<long>("Bytes")
.HasColumnType("bigint");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("datetime");
b.Property<Guid>("CreatedByUserId")
.HasColumnType("char(36)");
b.Property<double>("DefaultFocusX")
.HasColumnType("double");
b.Property<double>("DefaultFocusY")
.HasColumnType("double");
b.Property<double>("DefaultZoom")
.HasColumnType("double");
b.Property<DateTimeOffset?>("DeletedAt")
.HasColumnType("datetime");
b.Property<int>("Height")
.HasColumnType("int");
b.Property<DateTimeOffset?>("LastUsedAt")
.HasColumnType("datetime");
b.Property<string>("Module")
.IsRequired()
.HasMaxLength(20)
.HasColumnType("varchar(20)");
b.Property<string>("OriginalFileName")
.HasMaxLength(200)
.HasColumnType("varchar(200)");
b.Property<string>("OriginalKey")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("varchar(200)");
b.Property<string>("OriginalSha256")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("varchar(64)");
b.Property<string>("SetHash")
.HasMaxLength(16)
.HasColumnType("varchar(16)");
b.Property<string>("SourceFormat")
.IsRequired()
.HasMaxLength(10)
.HasColumnType("varchar(10)");
b.Property<double?>("TallFocusX")
.HasColumnType("double");
b.Property<double?>("TallFocusY")
.HasColumnType("double");
b.Property<double?>("TallZoom")
.HasColumnType("double");
b.Property<string>("Variants")
.HasColumnType("longtext");
b.Property<double?>("WideFocusX")
.HasColumnType("double");
b.Property<double?>("WideFocusY")
.HasColumnType("double");
b.Property<double?>("WideZoom")
.HasColumnType("double");
b.Property<int>("Width")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CreatedAt");
b.HasIndex("OriginalSha256")
.IsUnique();
b.ToTable("MediaAssets", (string)null);
});
modelBuilder.Entity("SlpModularCms.Modules.Media.Data.Entities.MediaAssetUse", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<bool>("Active")
.HasColumnType("tinyint(1)");
b.Property<Guid>("AssetId")
.HasColumnType("char(36)");
b.Property<string>("Crops")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("Module")
.IsRequired()
.HasMaxLength(20)
.HasColumnType("varchar(20)");
b.Property<string>("PlaceKind")
.IsRequired()
.HasMaxLength(20)
.HasColumnType("varchar(20)");
b.Property<int>("Position")
.HasColumnType("int");
b.Property<string>("SetHash")
.IsRequired()
.HasMaxLength(16)
.HasColumnType("varchar(16)");
b.Property<string>("Variants")
.HasColumnType("longtext");
b.HasKey("Id");
b.HasIndex("AssetId");
b.ToTable("MediaUses", (string)null);
});
modelBuilder.Entity("SlpModularCms.Modules.Media.Data.Entities.MediaAssetUse", b =>
{
b.HasOne("SlpModularCms.Modules.Media.Data.Entities.MediaAsset", "Asset")
.WithMany("Uses")
.HasForeignKey("AssetId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Asset");
});
modelBuilder.Entity("SlpModularCms.Modules.Media.Data.Entities.MediaAsset", b =>
{
b.Navigation("Uses");
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,109 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SlpModularCms.Modules.Media.Migrations
{
/// <inheritdoc />
public partial class AddHeroPhotoColumns : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "Variants",
table: "MediaUses",
type: "longtext",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "SetHash",
table: "MediaAssets",
type: "varchar(16)",
maxLength: 16,
nullable: true);
migrationBuilder.AddColumn<double>(
name: "TallFocusX",
table: "MediaAssets",
type: "double",
nullable: true);
migrationBuilder.AddColumn<double>(
name: "TallFocusY",
table: "MediaAssets",
type: "double",
nullable: true);
migrationBuilder.AddColumn<double>(
name: "TallZoom",
table: "MediaAssets",
type: "double",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "Variants",
table: "MediaAssets",
type: "longtext",
nullable: true);
migrationBuilder.AddColumn<double>(
name: "WideFocusX",
table: "MediaAssets",
type: "double",
nullable: true);
migrationBuilder.AddColumn<double>(
name: "WideFocusY",
table: "MediaAssets",
type: "double",
nullable: true);
migrationBuilder.AddColumn<double>(
name: "WideZoom",
table: "MediaAssets",
type: "double",
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Variants",
table: "MediaUses");
migrationBuilder.DropColumn(
name: "SetHash",
table: "MediaAssets");
migrationBuilder.DropColumn(
name: "TallFocusX",
table: "MediaAssets");
migrationBuilder.DropColumn(
name: "TallFocusY",
table: "MediaAssets");
migrationBuilder.DropColumn(
name: "TallZoom",
table: "MediaAssets");
migrationBuilder.DropColumn(
name: "Variants",
table: "MediaAssets");
migrationBuilder.DropColumn(
name: "WideFocusX",
table: "MediaAssets");
migrationBuilder.DropColumn(
name: "WideFocusY",
table: "MediaAssets");
migrationBuilder.DropColumn(
name: "WideZoom",
table: "MediaAssets");
}
}
}
@@ -71,11 +71,36 @@ namespace SlpModularCms.Modules.Media.Migrations
.HasMaxLength(64) .HasMaxLength(64)
.HasColumnType("varchar(64)"); .HasColumnType("varchar(64)");
b.Property<string>("SetHash")
.HasMaxLength(16)
.HasColumnType("varchar(16)");
b.Property<string>("SourceFormat") b.Property<string>("SourceFormat")
.IsRequired() .IsRequired()
.HasMaxLength(10) .HasMaxLength(10)
.HasColumnType("varchar(10)"); .HasColumnType("varchar(10)");
b.Property<double?>("TallFocusX")
.HasColumnType("double");
b.Property<double?>("TallFocusY")
.HasColumnType("double");
b.Property<double?>("TallZoom")
.HasColumnType("double");
b.Property<string>("Variants")
.HasColumnType("longtext");
b.Property<double?>("WideFocusX")
.HasColumnType("double");
b.Property<double?>("WideFocusY")
.HasColumnType("double");
b.Property<double?>("WideZoom")
.HasColumnType("double");
b.Property<int>("Width") b.Property<int>("Width")
.HasColumnType("int"); .HasColumnType("int");
@@ -123,6 +148,9 @@ namespace SlpModularCms.Modules.Media.Migrations
.HasMaxLength(16) .HasMaxLength(16)
.HasColumnType("varchar(16)"); .HasColumnType("varchar(16)");
b.Property<string>("Variants")
.HasColumnType("longtext");
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("AssetId"); b.HasIndex("AssetId");
@@ -122,6 +122,10 @@ public sealed class MediaLibraryCopier(MediaDbContext db, IEnumerable<IMediaMigr
row.OriginalFileName = snapshot.OriginalFileName; row.OriginalFileName = snapshot.OriginalFileName;
row.LastUsedAt = snapshot.LastUsedAt; row.LastUsedAt = snapshot.LastUsedAt;
row.DeletedAt = snapshot.DeletedAt; row.DeletedAt = snapshot.DeletedAt;
row.SetHash = snapshot.SetHash;
row.Variants = snapshot.VariantsJson;
(row.WideFocusX, row.WideFocusY, row.WideZoom) = (snapshot.WideFocusX, snapshot.WideFocusY, snapshot.WideZoom);
(row.TallFocusX, row.TallFocusY, row.TallZoom) = (snapshot.TallFocusX, snapshot.TallFocusY, snapshot.TallZoom);
} }
// Uses reference their asset; the crops of a use are the crops of its photo (the hero's wide and tall). // Uses reference their asset; the crops of a use are the crops of its photo (the hero's wide and tall).
@@ -140,6 +144,7 @@ public sealed class MediaLibraryCopier(MediaDbContext db, IEnumerable<IMediaMigr
row.Position = snapshot.Position; row.Position = snapshot.Position;
row.Active = snapshot.Active; row.Active = snapshot.Active;
row.SetHash = snapshot.SetHash; row.SetHash = snapshot.SetHash;
row.Variants = snapshot.VariantsJson;
row.Crops = snapshot.Crops is not null ? JsonSerializer.Serialize(snapshot.Crops, Json) : cropsByAsset.TryGetValue(snapshot.AssetId, out var crops) ? crops : "[]"; row.Crops = snapshot.Crops is not null ? JsonSerializer.Serialize(snapshot.Crops, Json) : cropsByAsset.TryGetValue(snapshot.AssetId, out var crops) ? crops : "[]";
} }
@@ -186,6 +191,10 @@ public sealed class MediaLibraryCopier(MediaDbContext db, IEnumerable<IMediaMigr
{ {
differences.Add($"photo {asset.Id}: hash, key or size differs"); differences.Add($"photo {asset.Id}: hash, key or size differs");
} }
else if (copy.SetHash != asset.SetHash || copy.Variants != asset.VariantsJson)
{
differences.Add($"photo {asset.Id}: set hash or variants differ");
}
} }
foreach (var use in uses) foreach (var use in uses)
@@ -194,9 +203,9 @@ public sealed class MediaLibraryCopier(MediaDbContext db, IEnumerable<IMediaMigr
{ {
differences.Add($"use {use.Id} is missing in the copy"); differences.Add($"use {use.Id} is missing in the copy");
} }
else if (copy.SetHash != use.SetHash || copy.AssetId != use.AssetId) else if (copy.SetHash != use.SetHash || copy.AssetId != use.AssetId || copy.Variants != use.VariantsJson)
{ {
differences.Add($"use {use.Id}: set hash or photo differs"); differences.Add($"use {use.Id}: set hash, variants or photo differs");
} }
} }
@@ -14,11 +14,12 @@ public sealed class MediaLibraryReader(MediaDbContext db, IOptions<MediaLibraryO
=> (await db.MediaAssets.AsNoTracking().Where(a => a.Module == module).ToListAsync(cancellationToken)) => (await db.MediaAssets.AsNoTracking().Where(a => a.Module == module).ToListAsync(cancellationToken))
.Select(a => new MediaAssetSnapshot( .Select(a => new MediaAssetSnapshot(
a.Id, a.Module, a.OriginalSha256, a.OriginalKey, a.SourceFormat, a.Width, a.Height, a.Bytes, a.Id, a.Module, a.OriginalSha256, a.OriginalKey, a.SourceFormat, a.Width, a.Height, a.Bytes,
a.DefaultFocusX, a.DefaultFocusY, a.DefaultZoom, string.Empty, [], a.CreatedAt, a.CreatedByUserId, a.OriginalFileName, a.LastUsedAt, a.DeletedAt)) a.DefaultFocusX, a.DefaultFocusY, a.DefaultZoom, a.SetHash ?? string.Empty, [], a.CreatedAt, a.CreatedByUserId, a.OriginalFileName, a.LastUsedAt, a.DeletedAt,
a.Variants, a.WideFocusX, a.WideFocusY, a.WideZoom, a.TallFocusX, a.TallFocusY, a.TallZoom))
.ToList(); .ToList();
public async Task<IReadOnlyList<MediaUseSnapshot>> ListUsesAsync(string module, CancellationToken cancellationToken) public async Task<IReadOnlyList<MediaUseSnapshot>> ListUsesAsync(string module, CancellationToken cancellationToken)
=> (await db.MediaUses.AsNoTracking().Where(u => u.Module == module).ToListAsync(cancellationToken)) => (await db.MediaUses.AsNoTracking().Where(u => u.Module == module).ToListAsync(cancellationToken))
.Select(u => new MediaUseSnapshot(u.Id, u.AssetId, u.Module, u.PlaceKind, u.Position, u.Active, u.SetHash)) .Select(u => new MediaUseSnapshot(u.Id, u.AssetId, u.Module, u.PlaceKind, u.Position, u.Active, u.SetHash, null, u.Variants))
.ToList(); .ToList();
} }