mirror of
https://gitlab.com/foxixus/neomovies-api.git
synced 2025-10-27 17:38:51 +05:00
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:
@@ -4,9 +4,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"neomovies-api/pkg/config"
|
"neomovies-api/pkg/config"
|
||||||
@@ -39,13 +41,24 @@ func (h *ImagesHandler) GetImage(w http.ResponseWriter, r *http.Request) {
|
|||||||
var imageURL string
|
var imageURL string
|
||||||
if strings.HasPrefix(imagePath, "http://") || strings.HasPrefix(imagePath, "https://") {
|
if strings.HasPrefix(imagePath, "http://") || strings.HasPrefix(imagePath, "https://") {
|
||||||
// Проксируем внешний абсолютный URL (например, Kinopoisk)
|
// Проксируем внешний абсолютный URL (например, Kinopoisk)
|
||||||
imageURL = imagePath
|
// Поддержим случай, когда на фронте параметр уже был url-encoded
|
||||||
|
decoded, _ := url.QueryUnescape(imagePath)
|
||||||
|
imageURL = decoded
|
||||||
} else {
|
} else {
|
||||||
// TMDB относительный путь
|
// TMDB относительный путь
|
||||||
imageURL = fmt.Sprintf("%s/%s/%s", config.TMDBImageBaseURL, size, imagePath)
|
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 {
|
if err != nil {
|
||||||
h.servePlaceholder(w, r)
|
h.servePlaceholder(w, r)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -152,6 +152,8 @@ func (h *PlayersHandler) GetLumexPlayer(w http.ResponseWriter, r *http.Request)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Поддержка алиаса
|
||||||
|
if idType == "kinopoisk_id" { idType = "kp" }
|
||||||
if idType != "kp" && idType != "imdb" {
|
if idType != "kp" && idType != "imdb" {
|
||||||
log.Printf("Error: invalid id_type: %s", idType)
|
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' or 'imdb'", http.StatusBadRequest)
|
||||||
@@ -166,21 +168,20 @@ func (h *PlayersHandler) GetLumexPlayer(w http.ResponseWriter, r *http.Request)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Формируем запрос вида: https://portal.lumex.host/api/short?api_token=...&kinopoisk_id=...
|
// Встраивание напрямую через p.lumex.cloud: <iframe src="//p.lumex.cloud/<code>?kp_id=...">
|
||||||
// Ожидается, что LUMEX_URL уже содержит базовый URL и api_token, например:
|
// Ожидается, что LUMEX_URL задаёт базу вида: https://p.lumex.cloud/<code>
|
||||||
// LUMEX_URL=https://portal.lumex.host/api/short?api_token=XXXX
|
|
||||||
var paramName string
|
var paramName string
|
||||||
if idType == "kp" {
|
if idType == "kp" {
|
||||||
paramName = "kinopoisk_id"
|
paramName = "kp_id"
|
||||||
} else {
|
} else {
|
||||||
paramName = "imdb_id"
|
paramName = "imdb_id"
|
||||||
}
|
}
|
||||||
|
|
||||||
separator := "&"
|
separator := "?"
|
||||||
if !strings.Contains(h.config.LumexURL, "?") {
|
if strings.Contains(h.config.LumexURL, "?") {
|
||||||
separator = "?"
|
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)
|
log.Printf("Lumex URL: %s", playerURL)
|
||||||
|
|
||||||
iframe := fmt.Sprintf(`<iframe src="%s" allowfullscreen loading="lazy" style="border:none;width:100%%;height:100%%;"></iframe>`, playerURL)
|
iframe := fmt.Sprintf(`<iframe src="%s" allowfullscreen loading="lazy" style="border:none;width:100%%;height:100%%;"></iframe>`, playerURL)
|
||||||
|
|||||||
Reference in New Issue
Block a user