From 78f174018e98d675a3bf7e26052e7cc5928e06a3 Mon Sep 17 00:00:00 2001 From: onysd Date: Fri, 7 Aug 2026 11:30:12 +0300 Subject: [PATCH] fix --- cmd/telesrv-admin/server.go | 6 +++--- internal/domain/gif_catalog.go | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/cmd/telesrv-admin/server.go b/cmd/telesrv-admin/server.go index 17252231..8e5abf40 100644 --- a/cmd/telesrv-admin/server.go +++ b/cmd/telesrv-admin/server.go @@ -1844,7 +1844,7 @@ type createGifCatalogEntryAPIRequest struct { func (s *server) handleCreateGifCatalogEntryAPI(w http.ResponseWriter, r *http.Request) { defer r.Body.Close() - r.Body = http.MaxBytesReader(w, r.Body, 21<<20) + r.Body = http.MaxBytesReader(w, r.Body, domain.MaxGifCatalogUploadSize+(1<<20)) if err := r.ParseMultipartForm(1 << 20); err != nil { writeAPIError(w, http.StatusBadRequest, "invalid multipart form: "+err.Error()) return @@ -1865,8 +1865,8 @@ func (s *server) handleCreateGifCatalogEntryAPI(w http.ResponseWriter, r *http.R return } defer file.Close() - data, err := io.ReadAll(io.LimitReader(file, (20<<20)+1)) - if err != nil || len(data) == 0 || len(data) > 20<<20 { + data, err := io.ReadAll(io.LimitReader(file, domain.MaxGifCatalogUploadSize+1)) + if err != nil || len(data) == 0 || int64(len(data)) > domain.MaxGifCatalogUploadSize { writeAPIError(w, http.StatusBadRequest, "gif file is empty or too large") return } diff --git a/internal/domain/gif_catalog.go b/internal/domain/gif_catalog.go index 08b23480..a33fc0fe 100644 --- a/internal/domain/gif_catalog.go +++ b/internal/domain/gif_catalog.go @@ -27,10 +27,19 @@ const ( // response -- mirrors MaxBotInlineResults, the TL-level cap the client // itself enforces per messages.getInlineBotResults response. MaxGifCatalogEntries = MaxBotInlineResults - // MaxGifCatalogUploadSize bounds one admin-uploaded catalog file. - // 20MB matches MaxBotInlineWebSize, the size a client-side inline GIF - // result is already allowed to be. - MaxGifCatalogUploadSize = MaxBotInlineWebSize + // MaxGifCatalogUploadSize bounds one admin-uploaded or seed-imported + // catalog file (the raw GIF/MP4 before transcoding, not the smaller MP4 + // files.Service.AdminUploadGifMaterial produces from it). + // + // Deliberately its own constant, not MaxBotInlineWebSize: that bounds + // content a *client* submits as an inline result, an unrelated + // constraint. This one instead matches + // files.gifTranscodeMaxInputBytes -- the actual ceiling the ffmpeg + // transcoder accepts -- so a real download (unoptimized meme/reaction + // GIFs routinely run 20-50MB, frame-by-frame GIF encoding is notoriously + // space-inefficient) doesn't get rejected here before ever reaching a + // step that could actually handle it. + MaxGifCatalogUploadSize = 50 << 20 ) // GifCatalogEntry is one admin-curated GIF served by the built-in @gif inline