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:
@@ -86,6 +86,11 @@ public static class MediaReadComparer
|
||||
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))
|
||||
{
|
||||
differences.Add($"photo {own.Id}: trash state differs");
|
||||
@@ -113,7 +118,7 @@ public static class MediaReadComparer
|
||||
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");
|
||||
}
|
||||
|
||||
@@ -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
|
||||
/// module uses, so no public address changes (migration plan, decision 13).
|
||||
/// </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(
|
||||
Guid Id,
|
||||
string Module,
|
||||
@@ -25,10 +27,17 @@ public sealed record MediaAssetSnapshot(
|
||||
Guid CreatedByUserId,
|
||||
string? OriginalFileName,
|
||||
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>
|
||||
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>
|
||||
/// 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 NSubstitute;
|
||||
using SlpModularCms.Core.Media.Library;
|
||||
using SlpModularCms.Modules.Hero.Data.Entities;
|
||||
using SlpModularCms.Modules.Hero.Models;
|
||||
using SlpModularCms.Modules.Hero.Services;
|
||||
using Xunit;
|
||||
@@ -73,4 +74,21 @@ public class HeroLibrarySyncTests
|
||||
second.Crops.Should().NotBeNull();
|
||||
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.OriginalFileName,
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -112,4 +112,19 @@ public class MediaLibraryCopierTests : IDisposable
|
||||
report.Assets.Should().Be(2);
|
||||
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.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 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 Guid CreatedByUserId { 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>
|
||||
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.SourceFormat).IsRequired().HasMaxLength(10);
|
||||
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.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.SetHash).IsRequired().HasMaxLength(16);
|
||||
entity.Property(e => e.Crops).IsRequired().HasColumnType("longtext");
|
||||
entity.Property(e => e.Variants).HasColumnType("longtext");
|
||||
entity.HasIndex(e => e.AssetId);
|
||||
});
|
||||
}
|
||||
|
||||
+182
@@ -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)
|
||||
.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");
|
||||
|
||||
@@ -123,6 +148,9 @@ namespace SlpModularCms.Modules.Media.Migrations
|
||||
.HasMaxLength(16)
|
||||
.HasColumnType("varchar(16)");
|
||||
|
||||
b.Property<string>("Variants")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AssetId");
|
||||
|
||||
@@ -122,6 +122,10 @@ public sealed class MediaLibraryCopier(MediaDbContext db, IEnumerable<IMediaMigr
|
||||
row.OriginalFileName = snapshot.OriginalFileName;
|
||||
row.LastUsedAt = snapshot.LastUsedAt;
|
||||
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).
|
||||
@@ -140,6 +144,7 @@ public sealed class MediaLibraryCopier(MediaDbContext db, IEnumerable<IMediaMigr
|
||||
row.Position = snapshot.Position;
|
||||
row.Active = snapshot.Active;
|
||||
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 : "[]";
|
||||
}
|
||||
|
||||
@@ -186,6 +191,10 @@ public sealed class MediaLibraryCopier(MediaDbContext db, IEnumerable<IMediaMigr
|
||||
{
|
||||
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)
|
||||
@@ -194,9 +203,9 @@ public sealed class MediaLibraryCopier(MediaDbContext db, IEnumerable<IMediaMigr
|
||||
{
|
||||
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))
|
||||
.Select(a => new MediaAssetSnapshot(
|
||||
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();
|
||||
|
||||
public async Task<IReadOnlyList<MediaUseSnapshot>> ListUsesAsync(string module, CancellationToken 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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user