Seed-Hero.ps1: focuspunten mee in de opslag van de hero (imageFocus) in plaats van een aparte focus-aanroep

Het eindpunt voor de focus is vervallen. Eerst alle uploads, dan een PUT van de hero met slides en imageFocus; idempotent (zelfde foto, zelfde afbeelding). Lokaal getest met de ASF-seed en hero-sls.json, op PowerShell 7 en Windows PowerShell 5.1.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 20:37:22 +01:00
co-authored by Claude Sonnet 5.5
parent 0b56fa6294
commit 4c7787caf2
2 changed files with 35 additions and 14 deletions
+34 -13
View File
@@ -71,16 +71,28 @@ if ($WhatIfPreference) {
}
if (-not $Email) { $Email = Read-Host 'Admin e-mail' }
$secure = Read-Host "Password for $Email" -AsSecureString
$bstr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($secure)
try {
$plain = [Runtime.InteropServices.Marshal]::PtrToStringBSTR($bstr)
$body = @{ email = $Email; password = $plain } | ConvertTo-Json -Compress
$login = Invoke-RestMethod -Method Post -Uri "$api/auth/login" -ContentType 'application/json' -Body $body
# The password is asked interactively. For an unattended run on a LOCAL host only (a test or CI job), the environment
# variable SEED_HERO_PASSWORD is used instead when it is set; it is never printed.
if ($env:SEED_HERO_PASSWORD) {
$plain = $env:SEED_HERO_PASSWORD
try {
$body = @{ email = $Email; password = $plain } | ConvertTo-Json -Compress
$login = Invoke-RestMethod -Method Post -Uri "$api/auth/login" -ContentType 'application/json' -Body $body
}
finally { $plain = $null; $body = $null }
}
finally {
[Runtime.InteropServices.Marshal]::ZeroFreeBSTR($bstr)
$plain = $null; $body = $null
else {
$secure = Read-Host "Password for $Email" -AsSecureString
$bstr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($secure)
try {
$plain = [Runtime.InteropServices.Marshal]::PtrToStringBSTR($bstr)
$body = @{ email = $Email; password = $plain } | ConvertTo-Json -Compress
$login = Invoke-RestMethod -Method Post -Uri "$api/auth/login" -ContentType 'application/json' -Body $body
}
finally {
[Runtime.InteropServices.Marshal]::ZeroFreeBSTR($bstr)
$plain = $null; $body = $null
}
}
$token = $login.accessToken
$headers = @{ Authorization = "Bearer $token" }
@@ -108,14 +120,22 @@ function Send-Photo([string] $path) {
finally { $client.Dispose() }
}
# First every photo is uploaded (the same photo again is the same image, so a second run duplicates nothing). The focus
# point of a photo is not a call of its own: a changed focus takes effect when the hero is saved, so it travels in the
# same request as the hero (imageFocus).
$requestSlides = @()
$imageFocus = @()
foreach ($s in $slides) {
$image = Send-Photo (Join-Path $ImagesDirectory $s.file)
Write-Host "upload $($s.file) -> image $($image.id)"
if ($s.focus) {
$focus = @{ focus = @{ x = [double]$s.focus.x; y = [double]$s.focus.y; zoom = 1.0 }; wide = $null; tall = $null } | ConvertTo-Json -Depth 5
$null = Invoke-RestMethod -Method Put -Uri "$api/hero/images/$($image.id)/focus" -Headers $headers -ContentType 'application/json' -Body $focus
Write-Host "focus $($s.file) at $($s.focus.x), $($s.focus.y)"
if ($s.focus -and -not ($imageFocus | Where-Object { $_.imageId -eq $image.id })) {
$imageFocus += [ordered]@{
imageId = $image.id
focus = [ordered]@{ x = [double]$s.focus.x; y = [double]$s.focus.y; zoom = 1.0 }
wide = $null
tall = $null
}
Write-Host "focus $($s.file) at $($s.focus.x), $($s.focus.y) (saved with the hero)"
}
$requestSlides += [ordered]@{ imageId = $image.id; alt = $(if ($s.decorative) { $null } else { $s.alt }); decorative = [bool]$s.decorative; isActive = $true }
}
@@ -130,6 +150,7 @@ $payload = [ordered]@{
startsAt = $null
endsAt = $null
slides = $requestSlides
imageFocus = $imageFocus
} | ConvertTo-Json -Depth 6
try {