feat(photos): рендер только видимой области при зуме правок

Вместо полноразмерной отредактированной версии просмотр запрашивает у сервера
только видимую область кадра: координаты относительные, поэтому запрос не
зависит от размера оригинала. Рендер куска занимает около 0.15 с против 0.8 с
для всей картинки, а полноразмерная версия больше не готовится вовсе.

Зум больше не сбрасывается, когда приходит отрендеренная версия правок:
состояние просмотра сбрасывается только при смене самого фото.
This commit is contained in:
iu
2026-10-20 23:34:45 +03:00
parent 6d3d7cbdd4
commit 4d2069d079
9 changed files with 328 additions and 40 deletions
+18
View File
@@ -137,6 +137,24 @@ func (h *Handler) Edit(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"photo": p})
}
// EditRegion renders the visible part of an edited photo: only the pixels the
// user actually sees are processed, which is much faster than encoding the
// whole image.
func (h *Handler) EditRegion(c *gin.Context) {
var region EditRegion
if err := c.ShouldBindQuery(&region); err != nil {
httpx.RespondError(c, httpx.BadRequest("invalid_request", "region is required"))
return
}
data, err := h.svc.RenderEditRegion(c.Request.Context(), c.Param("id"), auth.UserID(c), region)
if err != nil {
httpx.RespondError(c, err)
return
}
c.Header("Cache-Control", "private, max-age=300")
c.Data(http.StatusOK, "image/webp", data)
}
// ResetEdit removes the editing parameters of a photo together with the
// edited version, returning it to its original look.
func (h *Handler) ResetEdit(c *gin.Context) {