feat(players): use p.lumex.cloud iframe with kp_id; fix(images): robust proxy for absolute URLs (decode, timeout, headers)

This commit is contained in:
Erno
2025-10-19 17:08:58 +00:00
parent 1f51746740
commit f8d54a2901
2 changed files with 25 additions and 11 deletions

View File

@@ -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

View File

@@ -152,6 +152,8 @@ func (h *PlayersHandler) GetLumexPlayer(w http.ResponseWriter, r *http.Request)
return
}
// Поддержка алиаса
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)
@@ -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: <iframe src="//p.lumex.cloud/<code>?kp_id=...">
// Ожидается, что LUMEX_URL задаёт базу вида: https://p.lumex.cloud/<code>
var paramName string
if idType == "kp" {
paramName = "kinopoisk_id"
paramName = "kp_id"
} else {
paramName = "imdb_id"
}
separator := "&"
if !strings.Contains(h.config.LumexURL, "?") {
separator = "?"
separator := "?"
if strings.Contains(h.config.LumexURL, "?") {
separator = "&"
}
playerURL := fmt.Sprintf("%s% s%s=%s", h.config.LumexURL, separator, paramName, id)
playerURL := fmt.Sprintf("%s%s%s=%s", h.config.LumexURL, separator, paramName, url.QueryEscape(id))
log.Printf("Lumex URL: %s", playerURL)
iframe := fmt.Sprintf(`<iframe src="%s" allowfullscreen loading="lazy" style="border:none;width:100%%;height:100%%;"></iframe>`, playerURL)