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