feat(worker): add centered 128x128 JPEG crop

This commit is contained in:
kk10
2026-11-16 13:12:04 +03:00
parent 9149dddf11
commit 73d57e31a5
3 changed files with 160 additions and 65 deletions
+8 -2
View File
@@ -155,6 +155,11 @@ func TestWorkerPersistenceAndDuplicate(t *testing.T) {
if err != nil || cfg.Width != 256 || cfg.Height != 160 {
t.Fatal("invalid JPEG thumbnail")
}
crop := workerContent(t, user, att.ID, "crop")
cfg, err = jpeg.DecodeConfig(bytes.NewReader(crop))
if err != nil || cfg.Width != 128 || cfg.Height != 128 {
t.Fatal("invalid JPEG crop")
}
// Re-publish the same intent, modeling duplicate delivery after a lost publisher confirmation.
workerSQL(t, "UPDATE outbox SET published_at=NULL WHERE "+where)
workerWait(t, "duplicate publication", 15*time.Second, func() bool {
@@ -162,10 +167,11 @@ func TestWorkerPersistenceAndDuplicate(t *testing.T) {
})
workerWait(t, "duplicate acknowledgement", 15*time.Second, func() bool { return workerQueue(t) == "0:0" })
duplicate := waitAttachment(t, user, att.ID, "ready", 30*time.Second)
if !reflect.DeepEqual(ready, duplicate) || workerSQL(t, "SELECT count(*) FROM attachment_variants WHERE "+where) != "1" {
if !reflect.DeepEqual(ready, duplicate) || workerSQL(t, "SELECT count(*) FROM attachment_variants WHERE "+where) != "2" {
t.Fatal("duplicate job changed metadata or duplicated variants")
}
if !bytes.Equal(workerContent(t, user, att.ID, "thumbnail"), thumb) ||
if !bytes.Equal(workerContent(t, user, att.ID, "crop"), crop) ||
!bytes.Equal(workerContent(t, user, att.ID, "thumbnail"), thumb) ||
!bytes.Equal(workerContent(t, user, att.ID, "original"), source) {
t.Fatal("duplicate changed content")
}