Hero: een gewijzigd focuspunt geldt pas bij het opslaan van de hero (Bryan); het focus-venster houdt de wijziging lokaal
Het eindpunt PUT /hero/images/{id}/focus is vervallen; de focus gaat mee in de opslag (imageFocus) en de varianten worden dan in nieuwe bestanden opnieuw gesneden.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -96,20 +96,21 @@ public class HeroAsfSiteE2ETests : IClassFixture<AsfSiteFactory>
|
||||
{
|
||||
var seed = JsonDocument.Parse(File.ReadAllText(Path.Combine(web, "contract", "host-injection", "hero", "seed.json"))).RootElement;
|
||||
var slides = new List<HeroSlideRequest>();
|
||||
var focusEdits = new List<HeroImageFocusRequest>();
|
||||
foreach (var slide in seed.GetProperty("slides").EnumerateArray())
|
||||
{
|
||||
var photo = File.ReadAllBytes(Path.Combine(web, "src", "assets", slide.GetProperty("file").GetString()!));
|
||||
var image = await InScope(sp => sp.GetRequiredService<IHeroImageService>().UploadAsync(new MemoryStream(photo), photo.Length, caller, default));
|
||||
var focus = slide.GetProperty("focus");
|
||||
await InScope(sp => sp.GetRequiredService<IHeroImageService>().SetFocusAsync(
|
||||
Guid.Parse(image.Id), new HeroFocusRequest(new FocusDto(focus.GetProperty("x").GetDouble(), focus.GetProperty("y").GetDouble(), 1)), caller, default));
|
||||
// The focus travels with the save of the hero, like the admin does it.
|
||||
focusEdits.Add(new HeroImageFocusRequest(Guid.Parse(image.Id), new FocusDto(focus.GetProperty("x").GetDouble(), focus.GetProperty("y").GetDouble(), 1)));
|
||||
slides.Add(new HeroSlideRequest(null, Guid.Parse(image.Id), slide.GetProperty("alt").GetString()));
|
||||
}
|
||||
|
||||
await InScope(sp => sp.GetRequiredService<IHeroService>().SaveAsync(
|
||||
new HeroSaveRequest(seed.GetProperty("title").GetString(), seed.GetProperty("tagline").GetString(), null, seed.GetProperty("display").GetString(),
|
||||
seed.GetProperty("buttons").EnumerateArray().Select(b => new HeroButtonRequest(b.GetProperty("label").GetString(), b.GetProperty("target").GetString())).ToList(),
|
||||
true, null, null, slides), caller, default));
|
||||
true, null, null, slides, focusEdits), caller, default));
|
||||
|
||||
var response = await client.GetAsync("/");
|
||||
var page = await response.Content.ReadAsStringAsync();
|
||||
|
||||
@@ -46,7 +46,6 @@ public class HeroOnTheMasterHostTests : IClassFixture<ApiWebApplicationFactory>
|
||||
[InlineData("PUT", "/api/v1/hero")]
|
||||
[InlineData("POST", "/api/v1/hero/images")]
|
||||
[InlineData("DELETE", "/api/v1/hero/images/11111111-2222-3333-4444-555555555555")]
|
||||
[InlineData("PUT", "/api/v1/hero/images/11111111-2222-3333-4444-555555555555/focus")]
|
||||
public async Task Management_RequiresAnAdministrator(string method, string url)
|
||||
{
|
||||
var request = new HttpRequestMessage(new HttpMethod(method), url);
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using FluentAssertions;
|
||||
using SlpModularCms.Modules.Hero.Models;
|
||||
using SlpModularCms.Modules.Hero.Services;
|
||||
|
||||
namespace SlpModularCms.Modules.Hero.Tests;
|
||||
|
||||
/// <summary>A changed focus is part of saving the hero: nothing live changes before that save.</summary>
|
||||
public class HeroFocusSaveTests
|
||||
{
|
||||
private static HeroSaveRequest Save(Guid imageId, IReadOnlyList<HeroImageFocusRequest>? focus)
|
||||
=> new("Andrea Slop", null, null, "single", [], true, null, null, [new HeroSlideRequest(null, imageId, "foto")], focus);
|
||||
|
||||
[Fact]
|
||||
public async Task TheLiveHero_KeepsItsAddresses_UntilTheHeroIsSavedWithTheNewFocus()
|
||||
{
|
||||
using var rig = new HeroTestRig();
|
||||
var image = await rig.Upload(HeroTestRig.Photo());
|
||||
var id = Guid.Parse(image.Id);
|
||||
await rig.Service.SaveAsync(Save(id, null), HeroTestRig.Admin, default);
|
||||
var before = (await rig.Public.GetActiveAsync(default))!.Slides[0].Image.Src;
|
||||
|
||||
// Nothing but a save changes what is live: the focus travels with the save request.
|
||||
(await rig.Public.GetActiveAsync(default))!.Slides[0].Image.Src.Should().Be(before);
|
||||
|
||||
await rig.Service.SaveAsync(Save(id, [new HeroImageFocusRequest(id, new FocusDto(0.5, 0.5, 1), null, new FocusDto(1.0, 0.5, 1))]), HeroTestRig.Admin, default);
|
||||
var after = (await rig.Public.GetActiveAsync(default))!.Slides[0].Image;
|
||||
|
||||
var beforeSet = before.Split('/')[3];
|
||||
after.Variants.Should().OnlyContain(v => !v.Url.Contains(beforeSet), "a changed focus gives new addresses");
|
||||
after.FocusByRatio.Should().ContainKey("tall");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TheOldFiles_StayOnDisk_AfterTheSave_UntilTheCleanUp()
|
||||
{
|
||||
using var rig = new HeroTestRig();
|
||||
var image = await rig.Upload(HeroTestRig.Photo());
|
||||
var id = Guid.Parse(image.Id);
|
||||
await rig.Service.SaveAsync(Save(id, null), HeroTestRig.Admin, default);
|
||||
var oldVariant = image.Variants.First();
|
||||
|
||||
await rig.Service.SaveAsync(Save(id, [new HeroImageFocusRequest(id, new FocusDto(0.1, 0.1, 1.5))]), HeroTestRig.Admin, default);
|
||||
|
||||
(await rig.Store.ExistsAsync(oldVariant.Url["/media/".Length..], default)).Should().BeTrue("a site that still holds the old data keeps working for the retention time");
|
||||
rig.Db.HeroRetiredFiles.Should().ContainSingle(f => f.Kind == "set");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task APreparedFocusThatIsNeverSaved_LeavesOnlyUnreferencedFiles_ThatTheCleanUpRemoves()
|
||||
{
|
||||
using var rig = new HeroTestRig();
|
||||
var image = await rig.Upload(HeroTestRig.Photo());
|
||||
var id = Guid.Parse(image.Id);
|
||||
await rig.Service.SaveAsync(Save(id, null), HeroTestRig.Admin, default);
|
||||
var live = rig.Db.HeroImages.Single().SetHash;
|
||||
|
||||
// The save stops after the new files were written (here: the hero refers to a slide of another hero).
|
||||
var failing = new HeroSaveRequest("Andrea Slop", null, null, "single", [], true, null, null, [new HeroSlideRequest(Guid.NewGuid(), id, "foto")],
|
||||
[new HeroImageFocusRequest(id, new FocusDto(0.9, 0.9, 2))]);
|
||||
var act = async () => await rig.Service.SaveAsync(failing, HeroTestRig.Admin, default);
|
||||
await act.Should().ThrowAsync<HeroSaveRejectedException>();
|
||||
|
||||
rig.Db.HeroImages.Single().SetHash.Should().Be(live, "the failed save did not change the stored image");
|
||||
(await rig.Public.GetActiveAsync(default))!.Slides[0].Image.Src.Should().Contain(live);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AFocusForAnUnknownImage_IsRejected()
|
||||
{
|
||||
using var rig = new HeroTestRig();
|
||||
|
||||
var act = async () => await rig.Service.SaveAsync(Save(Guid.NewGuid(), null) with { Slides = [], ImageFocus = [new HeroImageFocusRequest(Guid.NewGuid(), new FocusDto(0.5, 0.5, 1))] }, HeroTestRig.Admin, default);
|
||||
|
||||
(await act.Should().ThrowAsync<HeroSaveRejectedException>()).Which.Field.Should().Be("ImageFocus[0].ImageId");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-0.1, 0.5, 1.0)]
|
||||
[InlineData(0.5, 1.1, 1.0)]
|
||||
[InlineData(0.5, 0.5, 0.5)]
|
||||
[InlineData(0.5, 0.5, 4.5)]
|
||||
public void AnInvalidFocusInTheRequest_IsRefusedByTheValidation(double x, double y, double zoom)
|
||||
{
|
||||
var request = Save(Guid.NewGuid(), [new HeroImageFocusRequest(Guid.NewGuid(), new FocusDto(x, y, zoom))]);
|
||||
var results = new List<ValidationResult>();
|
||||
|
||||
Validator.TryValidateObject(request, new ValidationContext(request), results, true);
|
||||
|
||||
results.SelectMany(r => r.MemberNames).Should().Contain("ImageFocus[0]");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AValidFocusEdit_PassesTheValidation()
|
||||
{
|
||||
var request = Save(Guid.NewGuid(), [new HeroImageFocusRequest(Guid.NewGuid(), new FocusDto(0.2, 0.9, 2), new FocusDto(0.1, 0.1, 1), null)]);
|
||||
var results = new List<ValidationResult>();
|
||||
|
||||
Validator.TryValidateObject(request, new ValidationContext(request), results, true);
|
||||
|
||||
results.Should().BeEmpty();
|
||||
}
|
||||
}
|
||||
@@ -97,7 +97,7 @@ public class HeroImageServiceTests
|
||||
var image = await rig.Upload(HeroTestRig.Photo());
|
||||
var oldSet = rig.Db.HeroImages.Single().SetHash;
|
||||
|
||||
var changed = await rig.Images.SetFocusAsync(Guid.Parse(image.Id), new HeroFocusRequest(new FocusDto(0.5, 0.5, 1), null, new FocusDto(1.0, 0.5, 1)), HeroTestRig.Admin, CancellationToken.None);
|
||||
var changed = await rig.SetFocus(Guid.Parse(image.Id), new HeroFocusRequest(new FocusDto(0.5, 0.5, 1), null, new FocusDto(1.0, 0.5, 1)));
|
||||
|
||||
var newSet = rig.Db.HeroImages.Single().SetHash;
|
||||
newSet.Should().NotBe(oldSet);
|
||||
@@ -123,7 +123,7 @@ public class HeroImageServiceTests
|
||||
using var rig = new HeroTestRig();
|
||||
var image = await rig.Upload(HeroTestRig.Photo());
|
||||
|
||||
await rig.Images.SetFocusAsync(Guid.Parse(image.Id), new HeroFocusRequest(new FocusDto(0.5, 0.5, 1)), HeroTestRig.Admin, CancellationToken.None);
|
||||
await rig.SetFocus(Guid.Parse(image.Id), new HeroFocusRequest(new FocusDto(0.5, 0.5, 1)));
|
||||
|
||||
(await rig.Store.ListSetsAsync("hero", CancellationToken.None)).Should().HaveCount(1);
|
||||
rig.Db.HeroRetiredFiles.Should().BeEmpty();
|
||||
@@ -135,9 +135,9 @@ public class HeroImageServiceTests
|
||||
using var rig = new HeroTestRig();
|
||||
var image = await rig.Upload(HeroTestRig.Photo());
|
||||
var original = rig.Db.HeroImages.Single().SetHash;
|
||||
await rig.Images.SetFocusAsync(Guid.Parse(image.Id), new HeroFocusRequest(new FocusDto(0.5, 0.5, 1), null, new FocusDto(0.9, 0.5, 1)), HeroTestRig.Admin, CancellationToken.None);
|
||||
await rig.SetFocus(Guid.Parse(image.Id), new HeroFocusRequest(new FocusDto(0.5, 0.5, 1), null, new FocusDto(0.9, 0.5, 1)));
|
||||
|
||||
await rig.Images.SetFocusAsync(Guid.Parse(image.Id), new HeroFocusRequest(new FocusDto(0.5, 0.5, 1)), HeroTestRig.Admin, CancellationToken.None);
|
||||
await rig.SetFocus(Guid.Parse(image.Id), new HeroFocusRequest(new FocusDto(0.5, 0.5, 1)));
|
||||
|
||||
rig.Db.HeroImages.Single().SetHash.Should().Be(original);
|
||||
}
|
||||
@@ -164,10 +164,10 @@ public class HeroImageServiceTests
|
||||
{
|
||||
using var rig = new HeroTestRig();
|
||||
|
||||
var focus = async () => await rig.Images.SetFocusAsync(Guid.NewGuid(), new HeroFocusRequest(new FocusDto(0.5, 0.5, 1)), HeroTestRig.Admin, CancellationToken.None);
|
||||
var focus = async () => await rig.SetFocus(Guid.NewGuid(), new HeroFocusRequest(new FocusDto(0.5, 0.5, 1)));
|
||||
var delete = async () => await rig.Images.DeleteAsync(Guid.NewGuid(), HeroTestRig.Admin, CancellationToken.None);
|
||||
|
||||
await focus.Should().ThrowAsync<HeroImageNotFoundException>();
|
||||
await focus.Should().ThrowAsync<HeroSaveRejectedException>();
|
||||
await delete.Should().ThrowAsync<HeroImageNotFoundException>();
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ public sealed class HeroTestRig : IDisposable
|
||||
var gate = new MediaProcessingGate(mediaOptions);
|
||||
var guard = new MediaUploadGuard(Processor, gate, Status, mediaOptions);
|
||||
Images = new HeroImageService(guard, Processor, Store, gate, Repository, mediaOptions, NullLogger<HeroImageService>.Instance, Time, IndexCache);
|
||||
Service = new HeroService(Repository, Options.Create(HeroOptions), NullLogger<HeroService>.Instance, Time, IndexCache);
|
||||
Service = new HeroService(Repository, Images, Options.Create(HeroOptions), NullLogger<HeroService>.Instance, Time, IndexCache);
|
||||
Public = new PublicHeroService(Repository, Options.Create(HeroOptions), Time);
|
||||
Cleanup = new HeroMediaCleanup(Repository, Store, mediaOptions, NullLogger<HeroMediaCleanup>.Instance, Time);
|
||||
}
|
||||
@@ -77,6 +77,16 @@ public sealed class HeroTestRig : IDisposable
|
||||
return stream.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>Changes the focus of an image the way the admin does: with the next save of the hero (the slides of the hero are left empty here).</summary>
|
||||
public async Task<SlpModularCms.Modules.Hero.Models.HeroImageDto> SetFocus(Guid imageId, SlpModularCms.Modules.Hero.Models.HeroFocusRequest request)
|
||||
{
|
||||
await Service.SaveAsync(
|
||||
new SlpModularCms.Modules.Hero.Models.HeroSaveRequest("Titel", null, null, "single", [], true, null, null, [],
|
||||
[new SlpModularCms.Modules.Hero.Models.HeroImageFocusRequest(imageId, request.Focus, request.Wide, request.Tall)]),
|
||||
Admin, CancellationToken.None);
|
||||
return SlpModularCms.Modules.Hero.Services.HeroMapping.ToImageDto((await Repository.GetImageAsync(imageId, CancellationToken.None))!);
|
||||
}
|
||||
|
||||
public Task<SlpModularCms.Modules.Hero.Models.HeroImageDto> Upload(byte[] bytes)
|
||||
=> Images.UploadAsync(new MemoryStream(bytes), bytes.Length, Admin, CancellationToken.None);
|
||||
|
||||
|
||||
@@ -54,6 +54,12 @@ public class HeroController(IHeroService service, IPublicHeroService publicServi
|
||||
ModelState.AddModelError(exception.Field, exception.Message);
|
||||
return ValidationProblem(ModelState);
|
||||
}
|
||||
catch (ImageRejectedException rejection)
|
||||
{
|
||||
// Cutting the variants for a changed focus needs the stored original and a free processing slot.
|
||||
var status = rejection.Reason == ImageRejection.Busy ? StatusCodes.Status429TooManyRequests : StatusCodes.Status503ServiceUnavailable;
|
||||
return StatusCode(status, new { error = rejection.Code, message = HttpTexts.From(HttpContext).Get(HeroTexts.Image.For(rejection.Reason)) });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,24 +95,6 @@ public class HeroImagesController(IHeroImageService service, IOptions<MediaOptio
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("{id:guid}/focus")]
|
||||
[ProducesResponseType<HeroImageDto>(StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> SetFocus(Guid id, [FromBody] HeroFocusRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Ok(await service.SetFocusAsync(id, request, HeroCaller.Id(User), cancellationToken));
|
||||
}
|
||||
catch (HeroImageNotFoundException)
|
||||
{
|
||||
return NotFound(new { error = "not_found", message = Texts().Get(HeroTexts.Image.NotFound) });
|
||||
}
|
||||
catch (ImageRejectedException rejection)
|
||||
{
|
||||
return Rejected(rejection);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete("{id:guid}")]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(StatusCodes.Status409Conflict)]
|
||||
|
||||
@@ -71,6 +71,9 @@ public record HeroButtonRequest(string? Label, string? Target);
|
||||
|
||||
public record HeroSlideRequest(Guid? Id, Guid ImageId, string? Alt, bool Decorative = false, bool IsActive = true);
|
||||
|
||||
/// <summary>A changed focus of one image; it takes effect when the hero is saved (the admin keeps it locally until then).</summary>
|
||||
public record HeroImageFocusRequest(Guid ImageId, FocusDto Focus, FocusDto? Wide = null, FocusDto? Tall = null);
|
||||
|
||||
public record HeroFocusRequest(FocusDto Focus, FocusDto? Wide = null, FocusDto? Tall = null) : IValidatableObject
|
||||
{
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
@@ -101,7 +104,8 @@ public record HeroSaveRequest(
|
||||
bool IsActive,
|
||||
DateTimeOffset? StartsAt,
|
||||
DateTimeOffset? EndsAt,
|
||||
IReadOnlyList<HeroSlideRequest>? Slides) : IValidatableObject
|
||||
IReadOnlyList<HeroSlideRequest>? Slides,
|
||||
IReadOnlyList<HeroImageFocusRequest>? ImageFocus = null) : IValidatableObject
|
||||
{
|
||||
public const int TitleMax = 200;
|
||||
public const int TitleMaxLines = 5;
|
||||
@@ -190,6 +194,20 @@ public record HeroSaveRequest(
|
||||
yield return new ValidationResult(texts.Get(HeroTexts.Validation.EndAfterStart), [nameof(EndsAt)]);
|
||||
}
|
||||
|
||||
var focusEdits = ImageFocus ?? [];
|
||||
for (var i = 0; i < focusEdits.Count; i++)
|
||||
{
|
||||
var edit = focusEdits[i];
|
||||
var valid = edit.ImageId != Guid.Empty
|
||||
&& edit.Focus is not null && edit.Focus.ToSetting().IsValid
|
||||
&& (edit.Wide is null || edit.Wide.ToSetting().IsValid)
|
||||
&& (edit.Tall is null || edit.Tall.ToSetting().IsValid);
|
||||
if (!valid)
|
||||
{
|
||||
yield return new ValidationResult(texts.Get(HeroTexts.Validation.FocusInvalid, args: ("maxZoom", FocusSetting.MaxZoom)), [$"{nameof(ImageFocus)}[{i}]"]);
|
||||
}
|
||||
}
|
||||
|
||||
var slides = Slides ?? [];
|
||||
for (var i = 0; i < slides.Count; i++)
|
||||
{
|
||||
|
||||
@@ -23,8 +23,14 @@ public interface IHeroImageService
|
||||
/// <exception cref="ImageRejectedException">The upload is refused; see the code.</exception>
|
||||
Task<HeroImageDto> UploadAsync(Stream upload, long declaredLength, Guid callerId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>Changes where the subject is (general and optionally per ratio) and cuts the variants again around it.</summary>
|
||||
Task<HeroImageDto> SetFocusAsync(Guid imageId, HeroFocusRequest request, Guid callerId, CancellationToken cancellationToken);
|
||||
/// <summary>
|
||||
/// Applies a changed focus (general and optionally per ratio) to a tracked image: when the set changes, the variants are
|
||||
/// cut again around the new point into a NEW set of files (new addresses, nothing live is touched) and the old set is
|
||||
/// noted as retired. Nothing is saved here: the caller saves it together with the hero, so a changed focus only becomes
|
||||
/// visible when the hero is saved. When the hero is not saved the new files are never referenced and the clean-up
|
||||
/// removes them after the retention time.
|
||||
/// </summary>
|
||||
Task StageFocusAsync(HeroImage image, HeroFocusRequest request, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>Removes an image nothing uses; its files go after the retention time.</summary>
|
||||
Task DeleteAsync(Guid imageId, Guid callerId, CancellationToken cancellationToken);
|
||||
@@ -110,10 +116,8 @@ public class HeroImageService(
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<HeroImageDto> SetFocusAsync(Guid imageId, HeroFocusRequest request, Guid callerId, CancellationToken cancellationToken)
|
||||
public async Task StageFocusAsync(HeroImage image, HeroFocusRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var image = await repository.GetImageAsync(imageId, cancellationToken) ?? throw new HeroImageNotFoundException();
|
||||
|
||||
var oldSet = image.SetHash;
|
||||
var general = request.Focus.ToSetting().Normalize();
|
||||
image.FocusX = general.X;
|
||||
@@ -140,12 +144,8 @@ public class HeroImageService(
|
||||
var files = await RenderSetAsync(image, memory.ToArray(), storedFormat, cancellationToken);
|
||||
await store.PutSetAsync(HeroMapping.Area, image.SetHash, files, cancellationToken);
|
||||
repository.AddRetired(new HeroRetiredFile { Id = Guid.NewGuid(), Kind = "set", Key = oldSet, RetiredAt = _time.GetUtcNow() });
|
||||
logger.LogInformation("Hero image {ImageId}: variants cut again for a changed focus (saved with the hero)", image.Id);
|
||||
}
|
||||
|
||||
await repository.SaveChangesAsync(cancellationToken);
|
||||
indexCache?.Invalidate();
|
||||
logger.LogInformation("Hero image {ImageId} focus changed by user {UserId}", imageId, callerId);
|
||||
return HeroMapping.ToImageDto(image);
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(Guid imageId, Guid callerId, CancellationToken cancellationToken)
|
||||
|
||||
@@ -25,6 +25,7 @@ public interface IHeroService
|
||||
|
||||
public class HeroService(
|
||||
IHeroRepository repository,
|
||||
IHeroImageService imageService,
|
||||
IOptions<HeroOptions> options,
|
||||
ILogger<HeroService> logger,
|
||||
TimeProvider? time = null,
|
||||
@@ -42,8 +43,17 @@ public class HeroService(
|
||||
var now = _time.GetUtcNow();
|
||||
var slideRequests = request.Slides ?? [];
|
||||
|
||||
var imageIds = slideRequests.Select(s => s.ImageId).Distinct().ToList();
|
||||
var focusRequests = request.ImageFocus ?? [];
|
||||
var imageIds = slideRequests.Select(s => s.ImageId).Concat(focusRequests.Select(f => f.ImageId)).Distinct().ToList();
|
||||
var images = (await repository.GetImagesAsync(imageIds, cancellationToken)).ToDictionary(i => i.Id);
|
||||
for (var i = 0; i < focusRequests.Count; i++)
|
||||
{
|
||||
if (!images.ContainsKey(focusRequests[i].ImageId))
|
||||
{
|
||||
throw new HeroSaveRejectedException($"ImageFocus[{i}].ImageId", _texts.Get(HeroTexts.Validation.Slide.ImageUnknown));
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < slideRequests.Count; i++)
|
||||
{
|
||||
if (!images.ContainsKey(slideRequests[i].ImageId))
|
||||
@@ -105,6 +115,13 @@ public class HeroService(
|
||||
}
|
||||
}
|
||||
|
||||
// A changed focus is applied only now, together with the hero: the new variants are cut into new files first, then
|
||||
// the hero and the images are saved in one go, so nothing live changes before the hero is saved.
|
||||
foreach (var edit in focusRequests)
|
||||
{
|
||||
await imageService.StageFocusAsync(images[edit.ImageId], new HeroFocusRequest(edit.Focus, edit.Wide, edit.Tall), cancellationToken);
|
||||
}
|
||||
|
||||
await repository.SaveChangesAsync(cancellationToken);
|
||||
|
||||
indexCache?.Invalidate();
|
||||
|
||||
Reference in New Issue
Block a user