fix(web): правки применяются сразу и не сбрасывают вкладку

Вкладка «Редактирование» больше не переключается на «Сведения» при
обновлении того же фото: временное состояние панели сбрасывается только при
смене фото.

Правки теперь рендерятся без ожидания тика воркера: сервис будит воркер сразу
после постановки задачи, а уведомление о готовых вариантах приходит до
кодирования полноразмерной версии. Задержка между сохранением правок и
появлением отредактированной версии — около 0.25 с вместо нескольких секунд.
This commit is contained in:
iu
2026-10-20 23:11:57 +03:00
parent 0548b1ab5e
commit cd3d17c0f0
8 changed files with 87 additions and 27 deletions
+24 -20
View File
@@ -43,16 +43,20 @@ func applyLight(src image.Image, p LightParams) *image.NRGBA {
return dst
}
// buildEditedVariants renders the edited version of a photo: the full-size
// image plus the thumb, medium and preview variants. The variants mirror the
// base ones, so the grid and the viewer can switch to them transparently.
func buildEditedVariants(data []byte, p EditParams) (thumb, medium, preview, full []byte, err error) {
// decodeAndAdjust decodes the original and applies the light adjustments to
// it, so the variants and the full-size version share one decode.
func decodeAndAdjust(data []byte, p EditParams) (*image.NRGBA, error) {
img, err := imaging.Decode(bytes.NewReader(data), imaging.AutoOrientation(true))
if err != nil {
return nil, nil, nil, nil, err
return nil, err
}
edited := applyLight(img, p.Light)
return applyLight(img, p.Light), nil
}
// encodeEditedVariants renders the grid variants of an edited photo. They
// mirror the base ones, so the grid and the viewer can switch to them
// transparently.
func encodeEditedVariants(edited *image.NRGBA) (thumb, medium, preview []byte, err error) {
thumbImg := imaging.Fill(edited, 200, 200, imaging.Center, imaging.Lanczos)
mediumImg := imaging.Fill(edited, 800, 800, imaging.Center, imaging.Lanczos)
previewImg := imaging.Fit(edited, 1200, 1200, imaging.Lanczos)
@@ -60,30 +64,30 @@ func buildEditedVariants(data []byte, p EditParams) (thumb, medium, preview, ful
opts := webp.Options{Quality: 82}
var buf bytes.Buffer
if err := webp.Encode(&buf, thumbImg, opts); err != nil {
return nil, nil, nil, nil, err
return nil, nil, nil, err
}
thumb = buf.Bytes()
buf.Reset()
if err := webp.Encode(&buf, mediumImg, opts); err != nil {
return nil, nil, nil, nil, err
return nil, nil, nil, err
}
medium = buf.Bytes()
buf.Reset()
if err := webp.Encode(&buf, previewImg, opts); err != nil {
return nil, nil, nil, nil, err
return nil, nil, nil, err
}
preview = buf.Bytes()
buf.Reset()
if err := webp.Encode(&buf, edited, opts); err != nil {
// Полноразмерная версия не обязательна: превью и миниатюры уже
// готовы, поэтому ошибку кодирования полной версии не считаем
// фатальной.
full = nil
} else {
full = buf.Bytes()
}
return thumb, medium, preview, full, nil
return thumb, medium, preview, nil
}
// encodeEditedFull renders the full-size edited version of a photo. It is
// encoded separately from the grid variants because it is the slowest step.
func encodeEditedFull(edited *image.NRGBA) ([]byte, error) {
var buf bytes.Buffer
if err := webp.Encode(&buf, edited, webp.Options{Quality: 82}); err != nil {
return nil, err
}
return buf.Bytes(), nil
}