From e68ce7f114d7e112ff33777b52fe4bfa42ff3c31 Mon Sep 17 00:00:00 2001 From: Erno Date: Sun, 19 Oct 2025 15:55:57 +0000 Subject: [PATCH] feat(images): proxy external http(s) poster URLs; feat(players): accept 'kinopoisk_id' alias for Lumex --- pkg/handlers/images.go | 25 ++++++++++++++++--------- pkg/handlers/players.go | 7 ++++--- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/pkg/handlers/images.go b/pkg/handlers/images.go index 12d744f..49a8e8a 100644 --- a/pkg/handlers/images.go +++ b/pkg/handlers/images.go @@ -1,15 +1,15 @@ package handlers import ( - "fmt" - "io" - "net/http" - "os" - "path/filepath" - "strings" + "fmt" + "io" + "net/http" + "os" + "path/filepath" + "strings" - "github.com/gorilla/mux" - "neomovies-api/pkg/config" + "github.com/gorilla/mux" + "neomovies-api/pkg/config" ) type ImagesHandler struct{} @@ -36,7 +36,14 @@ func (h *ImagesHandler) GetImage(w http.ResponseWriter, r *http.Request) { size = "original" } - imageURL := fmt.Sprintf("%s/%s/%s", config.TMDBImageBaseURL, size, imagePath) + var imageURL string + if strings.HasPrefix(imagePath, "http://") || strings.HasPrefix(imagePath, "https://") { + // Проксируем внешний абсолютный URL (например, Kinopoisk) + imageURL = imagePath + } else { + // TMDB относительный путь + imageURL = fmt.Sprintf("%s/%s/%s", config.TMDBImageBaseURL, size, imagePath) + } resp, err := http.Get(imageURL) if err != nil { diff --git a/pkg/handlers/players.go b/pkg/handlers/players.go index 5ca1400..d5c3f45 100644 --- a/pkg/handlers/players.go +++ b/pkg/handlers/players.go @@ -30,7 +30,7 @@ func (h *PlayersHandler) GetAllohaPlayer(w http.ResponseWriter, r *http.Request) log.Printf("GetAllohaPlayer called: %s %s", r.Method, r.URL.Path) vars := mux.Vars(r) - idType := vars["id_type"] + idType := vars["id_type"] id := vars["id"] if idType == "" || id == "" { @@ -39,9 +39,10 @@ func (h *PlayersHandler) GetAllohaPlayer(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) + http.Error(w, "id_type must be 'kp' (kinopoisk_id) or 'imdb'", http.StatusBadRequest) return }