From f8d54a29019cad0f7a132203532f1f7e749a8529 Mon Sep 17 00:00:00 2001 From: Erno Date: Sun, 19 Oct 2025 17:08:58 +0000 Subject: [PATCH] feat(players): use p.lumex.cloud iframe with kp_id; fix(images): robust proxy for absolute URLs (decode, timeout, headers) --- pkg/handlers/images.go | 17 +++++++++++++++-- pkg/handlers/players.go | 19 ++++++++++--------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/pkg/handlers/images.go b/pkg/handlers/images.go index 49a8e8a..23317de 100644 --- a/pkg/handlers/images.go +++ b/pkg/handlers/images.go @@ -4,9 +4,11 @@ import ( "fmt" "io" "net/http" + "net/url" "os" "path/filepath" "strings" + "time" "github.com/gorilla/mux" "neomovies-api/pkg/config" @@ -39,13 +41,24 @@ func (h *ImagesHandler) GetImage(w http.ResponseWriter, r *http.Request) { var imageURL string if strings.HasPrefix(imagePath, "http://") || strings.HasPrefix(imagePath, "https://") { // Проксируем внешний абсолютный URL (например, Kinopoisk) - imageURL = imagePath + // Поддержим случай, когда на фронте параметр уже был url-encoded + decoded, _ := url.QueryUnescape(imagePath) + imageURL = decoded } else { // TMDB относительный путь imageURL = fmt.Sprintf("%s/%s/%s", config.TMDBImageBaseURL, size, imagePath) } - resp, err := http.Get(imageURL) + client := &http.Client{Timeout: 10 * time.Second} + req, err := http.NewRequest("GET", imageURL, nil) + if err != nil { + h.servePlaceholder(w, r) + return + } + // Проксируем важные заголовки, чтобы источники не резали по UA + if ua := r.Header.Get("User-Agent"); ua != "" { req.Header.Set("User-Agent", ua) } + if ref := r.Header.Get("Referer"); ref != "" { req.Header.Set("Referer", ref) } + resp, err := client.Do(req) if err != nil { h.servePlaceholder(w, r) return diff --git a/pkg/handlers/players.go b/pkg/handlers/players.go index 643756b..650e781 100644 --- a/pkg/handlers/players.go +++ b/pkg/handlers/players.go @@ -152,7 +152,9 @@ func (h *PlayersHandler) GetLumexPlayer(w http.ResponseWriter, r *http.Request) return } - if idType != "kp" && idType != "imdb" { + // Поддержка алиаса + if idType == "kinopoisk_id" { idType = "kp" } + if idType != "kp" && idType != "imdb" { log.Printf("Error: invalid id_type: %s", idType) http.Error(w, "id_type must be 'kp' or 'imdb'", http.StatusBadRequest) return @@ -166,21 +168,20 @@ func (h *PlayersHandler) GetLumexPlayer(w http.ResponseWriter, r *http.Request) return } - // Формируем запрос вида: https://portal.lumex.host/api/short?api_token=...&kinopoisk_id=... - // Ожидается, что LUMEX_URL уже содержит базовый URL и api_token, например: - // LUMEX_URL=https://portal.lumex.host/api/short?api_token=XXXX + // Встраивание напрямую через p.lumex.cloud: `, playerURL)