mirror of
https://gitlab.com/foxixus/neomovies-api.git
synced 2025-10-28 01:48:51 +05:00
Compare commits
2 Commits
39c8366ae1
...
feature/jw
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bdeb1e1d74 | ||
|
|
ea3159fb8e |
@@ -97,6 +97,10 @@ func Handler(w http.ResponseWriter, r *http.Request) {
|
|||||||
api.HandleFunc("/players/alloha/{imdb_id}", playersHandler.GetAllohaPlayer).Methods("GET")
|
api.HandleFunc("/players/alloha/{imdb_id}", playersHandler.GetAllohaPlayer).Methods("GET")
|
||||||
api.HandleFunc("/players/lumex/{imdb_id}", playersHandler.GetLumexPlayer).Methods("GET")
|
api.HandleFunc("/players/lumex/{imdb_id}", playersHandler.GetLumexPlayer).Methods("GET")
|
||||||
api.HandleFunc("/players/vibix/{imdb_id}", playersHandler.GetVibixPlayer).Methods("GET")
|
api.HandleFunc("/players/vibix/{imdb_id}", playersHandler.GetVibixPlayer).Methods("GET")
|
||||||
|
api.HandleFunc("/players/rgshows/{tmdb_id}", playersHandler.GetRgShowsPlayer).Methods("GET")
|
||||||
|
api.HandleFunc("/players/rgshows/{tmdb_id}/{season}/{episode}", playersHandler.GetRgShowsTVPlayer).Methods("GET")
|
||||||
|
api.HandleFunc("/players/iframevideo/{kinopoisk_id}/{imdb_id}", playersHandler.GetIframeVideoPlayer).Methods("GET")
|
||||||
|
api.HandleFunc("/stream/{provider}/{tmdb_id}", playersHandler.GetStreamAPI).Methods("GET")
|
||||||
|
|
||||||
api.HandleFunc("/torrents/search/{imdbId}", torrentsHandler.SearchTorrents).Methods("GET")
|
api.HandleFunc("/torrents/search/{imdbId}", torrentsHandler.SearchTorrents).Methods("GET")
|
||||||
api.HandleFunc("/torrents/movies", torrentsHandler.SearchMovies).Methods("GET")
|
api.HandleFunc("/torrents/movies", torrentsHandler.SearchMovies).Methods("GET")
|
||||||
|
|||||||
3
main.go
3
main.go
@@ -67,6 +67,7 @@ func main() {
|
|||||||
api.HandleFunc("/auth/resend-code", authHandler.ResendVerificationCode).Methods("POST")
|
api.HandleFunc("/auth/resend-code", authHandler.ResendVerificationCode).Methods("POST")
|
||||||
api.HandleFunc("/auth/google/login", authHandler.GoogleLogin).Methods("GET")
|
api.HandleFunc("/auth/google/login", authHandler.GoogleLogin).Methods("GET")
|
||||||
api.HandleFunc("/auth/google/callback", authHandler.GoogleCallback).Methods("GET")
|
api.HandleFunc("/auth/google/callback", authHandler.GoogleCallback).Methods("GET")
|
||||||
|
api.HandleFunc("/auth/refresh", authHandler.RefreshToken).Methods("POST")
|
||||||
|
|
||||||
api.HandleFunc("/search/multi", searchHandler.MultiSearch).Methods("GET")
|
api.HandleFunc("/search/multi", searchHandler.MultiSearch).Methods("GET")
|
||||||
|
|
||||||
@@ -120,6 +121,8 @@ func main() {
|
|||||||
protected.HandleFunc("/auth/profile", authHandler.GetProfile).Methods("GET")
|
protected.HandleFunc("/auth/profile", authHandler.GetProfile).Methods("GET")
|
||||||
protected.HandleFunc("/auth/profile", authHandler.UpdateProfile).Methods("PUT")
|
protected.HandleFunc("/auth/profile", authHandler.UpdateProfile).Methods("PUT")
|
||||||
protected.HandleFunc("/auth/profile", authHandler.DeleteAccount).Methods("DELETE")
|
protected.HandleFunc("/auth/profile", authHandler.DeleteAccount).Methods("DELETE")
|
||||||
|
protected.HandleFunc("/auth/revoke-token", authHandler.RevokeRefreshToken).Methods("POST")
|
||||||
|
protected.HandleFunc("/auth/revoke-all-tokens", authHandler.RevokeAllRefreshTokens).Methods("POST")
|
||||||
|
|
||||||
protected.HandleFunc("/reactions/{mediaType}/{mediaId}/my-reaction", reactionsHandler.GetMyReaction).Methods("GET")
|
protected.HandleFunc("/reactions/{mediaType}/{mediaId}/my-reaction", reactionsHandler.GetMyReaction).Methods("GET")
|
||||||
protected.HandleFunc("/reactions/{mediaType}/{mediaId}", reactionsHandler.SetReaction).Methods("POST")
|
protected.HandleFunc("/reactions/{mediaType}/{mediaId}", reactionsHandler.SetReaction).Methods("POST")
|
||||||
|
|||||||
@@ -2,24 +2,24 @@ package config
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
// Environment variable keys
|
// Environment variable keys
|
||||||
EnvTMDBAccessToken = "TMDB_ACCESS_TOKEN"
|
EnvTMDBAccessToken = "TMDB_ACCESS_TOKEN"
|
||||||
EnvJWTSecret = "JWT_SECRET"
|
EnvJWTSecret = "JWT_SECRET"
|
||||||
EnvPort = "PORT"
|
EnvPort = "PORT"
|
||||||
EnvBaseURL = "BASE_URL"
|
EnvBaseURL = "BASE_URL"
|
||||||
EnvNodeEnv = "NODE_ENV"
|
EnvNodeEnv = "NODE_ENV"
|
||||||
EnvGmailUser = "GMAIL_USER"
|
EnvGmailUser = "GMAIL_USER"
|
||||||
EnvGmailPassword = "GMAIL_APP_PASSWORD"
|
EnvGmailPassword = "GMAIL_APP_PASSWORD"
|
||||||
EnvLumexURL = "LUMEX_URL"
|
EnvLumexURL = "LUMEX_URL"
|
||||||
EnvAllohaToken = "ALLOHA_TOKEN"
|
EnvAllohaToken = "ALLOHA_TOKEN"
|
||||||
EnvRedAPIBaseURL = "REDAPI_BASE_URL"
|
EnvRedAPIBaseURL = "REDAPI_BASE_URL"
|
||||||
EnvRedAPIKey = "REDAPI_KEY"
|
EnvRedAPIKey = "REDAPI_KEY"
|
||||||
EnvMongoDBName = "MONGO_DB_NAME"
|
EnvMongoDBName = "MONGO_DB_NAME"
|
||||||
EnvGoogleClientID = "GOOGLE_CLIENT_ID"
|
EnvGoogleClientID = "GOOGLE_CLIENT_ID"
|
||||||
EnvGoogleClientSecret= "GOOGLE_CLIENT_SECRET"
|
EnvGoogleClientSecret = "GOOGLE_CLIENT_SECRET"
|
||||||
EnvGoogleRedirectURL = "GOOGLE_REDIRECT_URL"
|
EnvGoogleRedirectURL = "GOOGLE_REDIRECT_URL"
|
||||||
EnvFrontendURL = "FRONTEND_URL"
|
EnvFrontendURL = "FRONTEND_URL"
|
||||||
EnvVibixHost = "VIBIX_HOST"
|
EnvVibixHost = "VIBIX_HOST"
|
||||||
EnvVibixToken = "VIBIX_TOKEN"
|
EnvVibixToken = "VIBIX_TOKEN"
|
||||||
|
|
||||||
// Default values
|
// Default values
|
||||||
DefaultJWTSecret = "your-secret-key"
|
DefaultJWTSecret = "your-secret-key"
|
||||||
@@ -28,7 +28,7 @@ const (
|
|||||||
DefaultNodeEnv = "development"
|
DefaultNodeEnv = "development"
|
||||||
DefaultRedAPIBase = "http://redapi.cfhttp.top"
|
DefaultRedAPIBase = "http://redapi.cfhttp.top"
|
||||||
DefaultMongoDBName = "database"
|
DefaultMongoDBName = "database"
|
||||||
DefaultVibixHost = "https://vibix.org"
|
DefaultVibixHost = "https://vibix.org"
|
||||||
|
|
||||||
// Static constants
|
// Static constants
|
||||||
TMDBImageBaseURL = "https://image.tmdb.org/t/p"
|
TMDBImageBaseURL = "https://image.tmdb.org/t/p"
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package handlers
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
|
|
||||||
@@ -46,7 +46,14 @@ func (h *AuthHandler) Login(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := h.authService.Login(req)
|
// Получаем информацию о клиенте для refresh токена
|
||||||
|
userAgent := r.Header.Get("User-Agent")
|
||||||
|
ipAddress := r.RemoteAddr
|
||||||
|
if forwarded := r.Header.Get("X-Forwarded-For"); forwarded != "" {
|
||||||
|
ipAddress = forwarded
|
||||||
|
}
|
||||||
|
|
||||||
|
response, err := h.authService.LoginWithTokens(req, userAgent, ipAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
statusCode := http.StatusBadRequest
|
statusCode := http.StatusBadRequest
|
||||||
if err.Error() == "Account not activated. Please verify your email." {
|
if err.Error() == "Account not activated. Please verify your email." {
|
||||||
@@ -221,5 +228,82 @@ func (h *AuthHandler) ResendVerificationCode(w http.ResponseWriter, r *http.Requ
|
|||||||
json.NewEncoder(w).Encode(response)
|
json.NewEncoder(w).Encode(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RefreshToken refreshes an access token using a refresh token
|
||||||
|
func (h *AuthHandler) RefreshToken(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req models.RefreshTokenRequest
|
||||||
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||||
|
http.Error(w, "Invalid request body", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Получаем информацию о клиенте
|
||||||
|
userAgent := r.Header.Get("User-Agent")
|
||||||
|
ipAddress := r.RemoteAddr
|
||||||
|
if forwarded := r.Header.Get("X-Forwarded-For"); forwarded != "" {
|
||||||
|
ipAddress = forwarded
|
||||||
|
}
|
||||||
|
|
||||||
|
tokenPair, err := h.authService.RefreshAccessToken(req.RefreshToken, userAgent, ipAddress)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
json.NewEncoder(w).Encode(models.APIResponse{
|
||||||
|
Success: true,
|
||||||
|
Data: tokenPair,
|
||||||
|
Message: "Token refreshed successfully",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// RevokeRefreshToken revokes a specific refresh token
|
||||||
|
func (h *AuthHandler) RevokeRefreshToken(w http.ResponseWriter, r *http.Request) {
|
||||||
|
userID, ok := middleware.GetUserIDFromContext(r.Context())
|
||||||
|
if !ok {
|
||||||
|
http.Error(w, "User ID not found in context", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var req models.RefreshTokenRequest
|
||||||
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||||
|
http.Error(w, "Invalid request body", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err := h.authService.RevokeRefreshToken(userID, req.RefreshToken)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
json.NewEncoder(w).Encode(models.APIResponse{
|
||||||
|
Success: true,
|
||||||
|
Message: "Refresh token revoked successfully",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// RevokeAllRefreshTokens revokes all refresh tokens for the current user
|
||||||
|
func (h *AuthHandler) RevokeAllRefreshTokens(w http.ResponseWriter, r *http.Request) {
|
||||||
|
userID, ok := middleware.GetUserIDFromContext(r.Context())
|
||||||
|
if !ok {
|
||||||
|
http.Error(w, "User ID not found in context", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err := h.authService.RevokeAllRefreshTokens(userID)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
json.NewEncoder(w).Encode(models.APIResponse{
|
||||||
|
Success: true,
|
||||||
|
Message: "All refresh tokens revoked successfully",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// helpers
|
// helpers
|
||||||
func generateState() string { return uuidNew() }
|
func generateState() string { return uuidNew() }
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -189,8 +189,6 @@ func (h *MovieHandler) GetSimilar(w http.ResponseWriter, r *http.Request) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func (h *MovieHandler) GetExternalIDs(w http.ResponseWriter, r *http.Request) {
|
func (h *MovieHandler) GetExternalIDs(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
id, err := strconv.Atoi(vars["id"])
|
id, err := strconv.Atoi(vars["id"])
|
||||||
|
|||||||
@@ -7,11 +7,13 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"neomovies-api/pkg/config"
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
"neomovies-api/pkg/config"
|
||||||
|
"neomovies-api/pkg/players"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PlayersHandler struct {
|
type PlayersHandler struct {
|
||||||
@@ -75,7 +77,7 @@ func (h *PlayersHandler) GetAllohaPlayer(w http.ResponseWriter, r *http.Request)
|
|||||||
|
|
||||||
var allohaResponse struct {
|
var allohaResponse struct {
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Data struct {
|
Data struct {
|
||||||
Iframe string `json:"iframe"`
|
Iframe string `json:"iframe"`
|
||||||
} `json:"data"`
|
} `json:"data"`
|
||||||
}
|
}
|
||||||
@@ -235,3 +237,201 @@ func (h *PlayersHandler) GetVibixPlayer(w http.ResponseWriter, r *http.Request)
|
|||||||
|
|
||||||
log.Printf("Successfully served Vibix player for imdb_id: %s", imdbID)
|
log.Printf("Successfully served Vibix player for imdb_id: %s", imdbID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetRgShowsPlayer handles RgShows streaming requests
|
||||||
|
func (h *PlayersHandler) GetRgShowsPlayer(w http.ResponseWriter, r *http.Request) {
|
||||||
|
log.Printf("GetRgShowsPlayer called: %s %s", r.Method, r.URL.Path)
|
||||||
|
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
tmdbID := vars["tmdb_id"]
|
||||||
|
if tmdbID == "" {
|
||||||
|
log.Printf("Error: tmdb_id is empty")
|
||||||
|
http.Error(w, "tmdb_id path param is required", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("Processing tmdb_id: %s", tmdbID)
|
||||||
|
|
||||||
|
pm := players.NewPlayersManager()
|
||||||
|
result, err := pm.GetMovieStreamByProvider("rgshows", tmdbID)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error getting RgShows stream: %v", err)
|
||||||
|
http.Error(w, "Failed to get stream", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !result.Success {
|
||||||
|
log.Printf("RgShows stream not found: %s", result.Error)
|
||||||
|
http.Error(w, "Stream not found", http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create iframe with the stream URL
|
||||||
|
iframe := fmt.Sprintf(`<iframe src="%s" allowfullscreen loading="lazy" style="border:none;width:100%%;height:100%%;"></iframe>`, result.StreamURL)
|
||||||
|
htmlDoc := fmt.Sprintf(`<!DOCTYPE html><html><head><meta charset='utf-8'/><title>RgShows Player</title><style>html,body{margin:0;height:100%%;}</style></head><body>%s</body></html>`, iframe)
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "text/html")
|
||||||
|
w.Write([]byte(htmlDoc))
|
||||||
|
|
||||||
|
log.Printf("Successfully served RgShows player for tmdb_id: %s", tmdbID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRgShowsTVPlayer handles RgShows TV show streaming requests
|
||||||
|
func (h *PlayersHandler) GetRgShowsTVPlayer(w http.ResponseWriter, r *http.Request) {
|
||||||
|
log.Printf("GetRgShowsTVPlayer called: %s %s", r.Method, r.URL.Path)
|
||||||
|
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
tmdbID := vars["tmdb_id"]
|
||||||
|
seasonStr := vars["season"]
|
||||||
|
episodeStr := vars["episode"]
|
||||||
|
|
||||||
|
if tmdbID == "" || seasonStr == "" || episodeStr == "" {
|
||||||
|
log.Printf("Error: missing required parameters")
|
||||||
|
http.Error(w, "tmdb_id, season, and episode path params are required", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
season, err := strconv.Atoi(seasonStr)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error parsing season: %v", err)
|
||||||
|
http.Error(w, "Invalid season number", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
episode, err := strconv.Atoi(episodeStr)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error parsing episode: %v", err)
|
||||||
|
http.Error(w, "Invalid episode number", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("Processing tmdb_id: %s, season: %d, episode: %d", tmdbID, season, episode)
|
||||||
|
|
||||||
|
pm := players.NewPlayersManager()
|
||||||
|
result, err := pm.GetTVStreamByProvider("rgshows", tmdbID, season, episode)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error getting RgShows TV stream: %v", err)
|
||||||
|
http.Error(w, "Failed to get stream", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !result.Success {
|
||||||
|
log.Printf("RgShows TV stream not found: %s", result.Error)
|
||||||
|
http.Error(w, "Stream not found", http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create iframe with the stream URL
|
||||||
|
iframe := fmt.Sprintf(`<iframe src="%s" allowfullscreen loading="lazy" style="border:none;width:100%%;height:100%%;"></iframe>`, result.StreamURL)
|
||||||
|
htmlDoc := fmt.Sprintf(`<!DOCTYPE html><html><head><meta charset='utf-8'/><title>RgShows TV Player</title><style>html,body{margin:0;height:100%%;}</style></head><body>%s</body></html>`, iframe)
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "text/html")
|
||||||
|
w.Write([]byte(htmlDoc))
|
||||||
|
|
||||||
|
log.Printf("Successfully served RgShows TV player for tmdb_id: %s, S%dE%d", tmdbID, season, episode)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetIframeVideoPlayer handles IframeVideo streaming requests
|
||||||
|
func (h *PlayersHandler) GetIframeVideoPlayer(w http.ResponseWriter, r *http.Request) {
|
||||||
|
log.Printf("GetIframeVideoPlayer called: %s %s", r.Method, r.URL.Path)
|
||||||
|
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
kinopoiskID := vars["kinopoisk_id"]
|
||||||
|
imdbID := vars["imdb_id"]
|
||||||
|
|
||||||
|
if kinopoiskID == "" && imdbID == "" {
|
||||||
|
log.Printf("Error: both kinopoisk_id and imdb_id are empty")
|
||||||
|
http.Error(w, "Either kinopoisk_id or imdb_id path param is required", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("Processing kinopoisk_id: %s, imdb_id: %s", kinopoiskID, imdbID)
|
||||||
|
|
||||||
|
pm := players.NewPlayersManager()
|
||||||
|
result, err := pm.GetStreamWithKinopoisk(kinopoiskID, imdbID)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error getting IframeVideo stream: %v", err)
|
||||||
|
http.Error(w, "Failed to get stream", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !result.Success {
|
||||||
|
log.Printf("IframeVideo stream not found: %s", result.Error)
|
||||||
|
http.Error(w, "Stream not found", http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create iframe with the stream URL
|
||||||
|
iframe := fmt.Sprintf(`<iframe src="%s" allowfullscreen loading="lazy" style="border:none;width:100%%;height:100%%;"></iframe>`, result.StreamURL)
|
||||||
|
htmlDoc := fmt.Sprintf(`<!DOCTYPE html><html><head><meta charset='utf-8'/><title>IframeVideo Player</title><style>html,body{margin:0;height:100%%;}</style></head><body>%s</body></html>`, iframe)
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "text/html")
|
||||||
|
w.Write([]byte(htmlDoc))
|
||||||
|
|
||||||
|
log.Printf("Successfully served IframeVideo player for kinopoisk_id: %s, imdb_id: %s", kinopoiskID, imdbID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetStreamAPI returns stream information as JSON API
|
||||||
|
func (h *PlayersHandler) GetStreamAPI(w http.ResponseWriter, r *http.Request) {
|
||||||
|
log.Printf("GetStreamAPI called: %s %s", r.Method, r.URL.Path)
|
||||||
|
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
provider := vars["provider"]
|
||||||
|
tmdbID := vars["tmdb_id"]
|
||||||
|
|
||||||
|
if provider == "" || tmdbID == "" {
|
||||||
|
log.Printf("Error: missing required parameters")
|
||||||
|
http.Error(w, "provider and tmdb_id path params are required", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for TV show parameters
|
||||||
|
seasonStr := r.URL.Query().Get("season")
|
||||||
|
episodeStr := r.URL.Query().Get("episode")
|
||||||
|
kinopoiskID := r.URL.Query().Get("kinopoisk_id")
|
||||||
|
imdbID := r.URL.Query().Get("imdb_id")
|
||||||
|
|
||||||
|
log.Printf("Processing provider: %s, tmdb_id: %s", provider, tmdbID)
|
||||||
|
|
||||||
|
pm := players.NewPlayersManager()
|
||||||
|
var result *players.StreamResult
|
||||||
|
var err error
|
||||||
|
|
||||||
|
switch provider {
|
||||||
|
case "iframevideo":
|
||||||
|
if kinopoiskID == "" && imdbID == "" {
|
||||||
|
http.Error(w, "kinopoisk_id or imdb_id query param is required for IframeVideo", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
result, err = pm.GetStreamWithKinopoisk(kinopoiskID, imdbID)
|
||||||
|
case "rgshows":
|
||||||
|
if seasonStr != "" && episodeStr != "" {
|
||||||
|
season, err1 := strconv.Atoi(seasonStr)
|
||||||
|
episode, err2 := strconv.Atoi(episodeStr)
|
||||||
|
if err1 != nil || err2 != nil {
|
||||||
|
http.Error(w, "Invalid season or episode number", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
result, err = pm.GetTVStreamByProvider("rgshows", tmdbID, season, episode)
|
||||||
|
} else {
|
||||||
|
result, err = pm.GetMovieStreamByProvider("rgshows", tmdbID)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
http.Error(w, "Unsupported provider", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error getting stream from %s: %v", provider, err)
|
||||||
|
result = &players.StreamResult{
|
||||||
|
Success: false,
|
||||||
|
Provider: provider,
|
||||||
|
Error: err.Error(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
json.NewEncoder(w).Encode(result)
|
||||||
|
|
||||||
|
log.Printf("Successfully served stream API for provider: %s, tmdb_id: %s", provider, tmdbID)
|
||||||
|
}
|
||||||
|
|||||||
@@ -85,7 +85,9 @@ func (h *ReactionsHandler) SetReaction(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var request struct{ Type string `json:"type"` }
|
var request struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
}
|
||||||
if err := json.NewDecoder(r.Body).Decode(&request); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&request); err != nil {
|
||||||
http.Error(w, "Invalid request body", http.StatusBadRequest)
|
http.Error(w, "Invalid request body", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -7,21 +7,22 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
||||||
Email string `json:"email" bson:"email" validate:"required,email"`
|
Email string `json:"email" bson:"email" validate:"required,email"`
|
||||||
Password string `json:"-" bson:"password" validate:"required,min=6"`
|
Password string `json:"-" bson:"password" validate:"required,min=6"`
|
||||||
Name string `json:"name" bson:"name" validate:"required"`
|
Name string `json:"name" bson:"name" validate:"required"`
|
||||||
Avatar string `json:"avatar" bson:"avatar"`
|
Avatar string `json:"avatar" bson:"avatar"`
|
||||||
Favorites []string `json:"favorites" bson:"favorites"`
|
Favorites []string `json:"favorites" bson:"favorites"`
|
||||||
Verified bool `json:"verified" bson:"verified"`
|
Verified bool `json:"verified" bson:"verified"`
|
||||||
VerificationCode string `json:"-" bson:"verificationCode,omitempty"`
|
VerificationCode string `json:"-" bson:"verificationCode,omitempty"`
|
||||||
VerificationExpires time.Time `json:"-" bson:"verificationExpires,omitempty"`
|
VerificationExpires time.Time `json:"-" bson:"verificationExpires,omitempty"`
|
||||||
IsAdmin bool `json:"isAdmin" bson:"isAdmin"`
|
IsAdmin bool `json:"isAdmin" bson:"isAdmin"`
|
||||||
AdminVerified bool `json:"adminVerified" bson:"adminVerified"`
|
AdminVerified bool `json:"adminVerified" bson:"adminVerified"`
|
||||||
CreatedAt time.Time `json:"created_at" bson:"createdAt"`
|
CreatedAt time.Time `json:"created_at" bson:"createdAt"`
|
||||||
UpdatedAt time.Time `json:"updated_at" bson:"updatedAt"`
|
UpdatedAt time.Time `json:"updated_at" bson:"updatedAt"`
|
||||||
Provider string `json:"provider,omitempty" bson:"provider,omitempty"`
|
Provider string `json:"provider,omitempty" bson:"provider,omitempty"`
|
||||||
GoogleID string `json:"googleId,omitempty" bson:"googleId,omitempty"`
|
GoogleID string `json:"googleId,omitempty" bson:"googleId,omitempty"`
|
||||||
|
RefreshTokens []RefreshToken `json:"-" bson:"refreshTokens,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LoginRequest struct {
|
type LoginRequest struct {
|
||||||
@@ -36,8 +37,9 @@ type RegisterRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AuthResponse struct {
|
type AuthResponse struct {
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
User User `json:"user"`
|
RefreshToken string `json:"refreshToken"`
|
||||||
|
User User `json:"user"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type VerifyEmailRequest struct {
|
type VerifyEmailRequest struct {
|
||||||
@@ -48,3 +50,20 @@ type VerifyEmailRequest struct {
|
|||||||
type ResendCodeRequest struct {
|
type ResendCodeRequest struct {
|
||||||
Email string `json:"email" validate:"required,email"`
|
Email string `json:"email" validate:"required,email"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RefreshToken struct {
|
||||||
|
Token string `json:"token" bson:"token"`
|
||||||
|
ExpiresAt time.Time `json:"expiresAt" bson:"expiresAt"`
|
||||||
|
CreatedAt time.Time `json:"createdAt" bson:"createdAt"`
|
||||||
|
UserAgent string `json:"userAgent,omitempty" bson:"userAgent,omitempty"`
|
||||||
|
IPAddress string `json:"ipAddress,omitempty" bson:"ipAddress,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type TokenPair struct {
|
||||||
|
AccessToken string `json:"accessToken"`
|
||||||
|
RefreshToken string `json:"refreshToken"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type RefreshTokenRequest struct {
|
||||||
|
RefreshToken string `json:"refreshToken" validate:"required"`
|
||||||
|
}
|
||||||
|
|||||||
208
pkg/players/iframevideo.go
Normal file
208
pkg/players/iframevideo.go
Normal file
@@ -0,0 +1,208 @@
|
|||||||
|
package players
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"mime/multipart"
|
||||||
|
"net/http"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// IframeVideoSearchResponse represents the search response from IframeVideo API
|
||||||
|
type IframeVideoSearchResponse struct {
|
||||||
|
Results []struct {
|
||||||
|
CID int `json:"cid"`
|
||||||
|
Path string `json:"path"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
} `json:"results"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// IframeVideoResponse represents the video response from IframeVideo API
|
||||||
|
type IframeVideoResponse struct {
|
||||||
|
Source string `json:"src"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// IframeVideoPlayer implements the IframeVideo streaming service
|
||||||
|
type IframeVideoPlayer struct {
|
||||||
|
APIHost string
|
||||||
|
CDNHost string
|
||||||
|
Client *http.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewIframeVideoPlayer creates a new IframeVideo player instance
|
||||||
|
func NewIframeVideoPlayer() *IframeVideoPlayer {
|
||||||
|
return &IframeVideoPlayer{
|
||||||
|
APIHost: "https://iframe.video",
|
||||||
|
CDNHost: "https://videoframe.space",
|
||||||
|
Client: &http.Client{
|
||||||
|
Timeout: 8 * time.Second,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetStream gets streaming URL by Kinopoisk ID and IMDB ID
|
||||||
|
func (i *IframeVideoPlayer) GetStream(kinopoiskID, imdbID string) (*StreamResult, error) {
|
||||||
|
// First, search for content
|
||||||
|
searchResult, err := i.searchContent(kinopoiskID, imdbID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("search failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get iframe content to extract token
|
||||||
|
token, err := i.extractToken(searchResult.Path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("token extraction failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get video URL
|
||||||
|
return i.getVideoURL(searchResult.CID, token, searchResult.Type)
|
||||||
|
}
|
||||||
|
|
||||||
|
// searchContent searches for content by Kinopoisk and IMDB IDs
|
||||||
|
func (i *IframeVideoPlayer) searchContent(kinopoiskID, imdbID string) (*struct {
|
||||||
|
CID int
|
||||||
|
Path string
|
||||||
|
Type string
|
||||||
|
}, error) {
|
||||||
|
url := fmt.Sprintf("%s/api/v2/search?imdb=%s&kp=%s", i.APIHost, imdbID, kinopoiskID)
|
||||||
|
|
||||||
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to create request: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Header.Set("Accept", "application/json")
|
||||||
|
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36")
|
||||||
|
|
||||||
|
resp, err := i.Client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to fetch search results: %w", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return nil, fmt.Errorf("API returned status: %d", resp.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
var searchResp IframeVideoSearchResponse
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&searchResp); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to decode response: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(searchResp.Results) == 0 {
|
||||||
|
return nil, fmt.Errorf("content not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
result := searchResp.Results[0]
|
||||||
|
return &struct {
|
||||||
|
CID int
|
||||||
|
Path string
|
||||||
|
Type string
|
||||||
|
}{
|
||||||
|
CID: result.CID,
|
||||||
|
Path: result.Path,
|
||||||
|
Type: result.Type,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// extractToken extracts token from iframe HTML content
|
||||||
|
func (i *IframeVideoPlayer) extractToken(path string) (string, error) {
|
||||||
|
req, err := http.NewRequest("GET", path, nil)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("failed to create request: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set headers similar to C# implementation
|
||||||
|
req.Header.Set("DNT", "1")
|
||||||
|
req.Header.Set("Referer", i.CDNHost+"/")
|
||||||
|
req.Header.Set("Sec-Fetch-Dest", "iframe")
|
||||||
|
req.Header.Set("Sec-Fetch-Mode", "navigate")
|
||||||
|
req.Header.Set("Sec-Fetch-Site", "cross-site")
|
||||||
|
req.Header.Set("Upgrade-Insecure-Requests", "1")
|
||||||
|
req.Header.Set("sec-ch-ua", `"Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"`)
|
||||||
|
req.Header.Set("sec-ch-ua-mobile", "?0")
|
||||||
|
req.Header.Set("sec-ch-ua-platform", `"Windows"`)
|
||||||
|
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36")
|
||||||
|
|
||||||
|
resp, err := i.Client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("failed to fetch iframe content: %w", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return "", fmt.Errorf("iframe returned status: %d", resp.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
content, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("failed to read iframe content: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract token using regex as in C# implementation
|
||||||
|
re := regexp.MustCompile(`\/[^\/]+\/([^\/]+)\/iframe`)
|
||||||
|
matches := re.FindStringSubmatch(string(content))
|
||||||
|
if len(matches) < 2 {
|
||||||
|
return "", fmt.Errorf("token not found in iframe content")
|
||||||
|
}
|
||||||
|
|
||||||
|
return matches[1], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// getVideoURL gets video URL using extracted token
|
||||||
|
func (i *IframeVideoPlayer) getVideoURL(cid int, token, mediaType string) (*StreamResult, error) {
|
||||||
|
// Create multipart form data
|
||||||
|
var buf bytes.Buffer
|
||||||
|
writer := multipart.NewWriter(&buf)
|
||||||
|
|
||||||
|
writer.WriteField("token", token)
|
||||||
|
writer.WriteField("type", mediaType)
|
||||||
|
writer.WriteField("season", "")
|
||||||
|
writer.WriteField("episode", "")
|
||||||
|
writer.WriteField("mobile", "false")
|
||||||
|
writer.WriteField("id", strconv.Itoa(cid))
|
||||||
|
writer.WriteField("qt", "480")
|
||||||
|
|
||||||
|
contentType := writer.FormDataContentType()
|
||||||
|
writer.Close()
|
||||||
|
|
||||||
|
req, err := http.NewRequest("POST", i.CDNHost+"/loadvideo", &buf)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to create request: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Header.Set("Content-Type", contentType)
|
||||||
|
req.Header.Set("Origin", i.CDNHost)
|
||||||
|
req.Header.Set("Referer", i.CDNHost+"/")
|
||||||
|
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36")
|
||||||
|
|
||||||
|
resp, err := i.Client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to fetch video URL: %w", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return nil, fmt.Errorf("video API returned status: %d", resp.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
var videoResp IframeVideoResponse
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&videoResp); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to decode video response: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if videoResp.Source == "" {
|
||||||
|
return nil, fmt.Errorf("video URL not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &StreamResult{
|
||||||
|
Success: true,
|
||||||
|
StreamURL: videoResp.Source,
|
||||||
|
Provider: "IframeVideo",
|
||||||
|
Type: "direct",
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
81
pkg/players/rgshows.go
Normal file
81
pkg/players/rgshows.go
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
package players
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RgShowsResponse represents the response from RgShows API
|
||||||
|
type RgShowsResponse struct {
|
||||||
|
Stream *struct {
|
||||||
|
URL string `json:"url"`
|
||||||
|
} `json:"stream"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// RgShowsPlayer implements the RgShows streaming service
|
||||||
|
type RgShowsPlayer struct {
|
||||||
|
BaseURL string
|
||||||
|
Client *http.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewRgShowsPlayer creates a new RgShows player instance
|
||||||
|
func NewRgShowsPlayer() *RgShowsPlayer {
|
||||||
|
return &RgShowsPlayer{
|
||||||
|
BaseURL: "https://rgshows.com",
|
||||||
|
Client: &http.Client{
|
||||||
|
Timeout: 40 * time.Second,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMovieStream gets streaming URL for a movie by TMDB ID
|
||||||
|
func (r *RgShowsPlayer) GetMovieStream(tmdbID string) (*StreamResult, error) {
|
||||||
|
url := fmt.Sprintf("%s/main/movie/%s", r.BaseURL, tmdbID)
|
||||||
|
return r.fetchStream(url)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTVStream gets streaming URL for a TV show episode by TMDB ID, season and episode
|
||||||
|
func (r *RgShowsPlayer) GetTVStream(tmdbID string, season, episode int) (*StreamResult, error) {
|
||||||
|
url := fmt.Sprintf("%s/main/tv/%s/%d/%d", r.BaseURL, tmdbID, season, episode)
|
||||||
|
return r.fetchStream(url)
|
||||||
|
}
|
||||||
|
|
||||||
|
// fetchStream makes HTTP request to RgShows API and extracts stream URL
|
||||||
|
func (r *RgShowsPlayer) fetchStream(url string) (*StreamResult, error) {
|
||||||
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to create request: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set headers similar to the C# implementation
|
||||||
|
req.Header.Set("Accept", "application/json")
|
||||||
|
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36")
|
||||||
|
|
||||||
|
resp, err := r.Client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to fetch stream: %w", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return nil, fmt.Errorf("API returned status: %d", resp.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
var rgResp RgShowsResponse
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&rgResp); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to decode response: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if rgResp.Stream == nil || rgResp.Stream.URL == "" {
|
||||||
|
return nil, fmt.Errorf("stream not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &StreamResult{
|
||||||
|
Success: true,
|
||||||
|
StreamURL: rgResp.Stream.URL,
|
||||||
|
Provider: "RgShows",
|
||||||
|
Type: "direct",
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
99
pkg/players/types.go
Normal file
99
pkg/players/types.go
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
package players
|
||||||
|
|
||||||
|
// StreamResult represents the result of a streaming request
|
||||||
|
type StreamResult struct {
|
||||||
|
Success bool `json:"success"`
|
||||||
|
StreamURL string `json:"stream_url,omitempty"`
|
||||||
|
Provider string `json:"provider"`
|
||||||
|
Type string `json:"type"` // "direct", "iframe", "hls", etc.
|
||||||
|
Error string `json:"error,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Player interface defines methods for streaming providers
|
||||||
|
type Player interface {
|
||||||
|
GetMovieStream(tmdbID string) (*StreamResult, error)
|
||||||
|
GetTVStream(tmdbID string, season, episode int) (*StreamResult, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PlayersManager manages all available streaming players
|
||||||
|
type PlayersManager struct {
|
||||||
|
rgshows *RgShowsPlayer
|
||||||
|
iframevideo *IframeVideoPlayer
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewPlayersManager creates a new players manager
|
||||||
|
func NewPlayersManager() *PlayersManager {
|
||||||
|
return &PlayersManager{
|
||||||
|
rgshows: NewRgShowsPlayer(),
|
||||||
|
iframevideo: NewIframeVideoPlayer(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMovieStreams tries to get movie streams from all available providers
|
||||||
|
func (pm *PlayersManager) GetMovieStreams(tmdbID string) []*StreamResult {
|
||||||
|
var results []*StreamResult
|
||||||
|
|
||||||
|
// Try RgShows
|
||||||
|
if stream, err := pm.rgshows.GetMovieStream(tmdbID); err == nil {
|
||||||
|
results = append(results, stream)
|
||||||
|
} else {
|
||||||
|
results = append(results, &StreamResult{
|
||||||
|
Success: false,
|
||||||
|
Provider: "RgShows",
|
||||||
|
Error: err.Error(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return results
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTVStreams tries to get TV show streams from all available providers
|
||||||
|
func (pm *PlayersManager) GetTVStreams(tmdbID string, season, episode int) []*StreamResult {
|
||||||
|
var results []*StreamResult
|
||||||
|
|
||||||
|
// Try RgShows
|
||||||
|
if stream, err := pm.rgshows.GetTVStream(tmdbID, season, episode); err == nil {
|
||||||
|
results = append(results, stream)
|
||||||
|
} else {
|
||||||
|
results = append(results, &StreamResult{
|
||||||
|
Success: false,
|
||||||
|
Provider: "RgShows",
|
||||||
|
Error: err.Error(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return results
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMovieStreamByProvider gets movie stream from specific provider
|
||||||
|
func (pm *PlayersManager) GetMovieStreamByProvider(provider, tmdbID string) (*StreamResult, error) {
|
||||||
|
switch provider {
|
||||||
|
case "rgshows":
|
||||||
|
return pm.rgshows.GetMovieStream(tmdbID)
|
||||||
|
default:
|
||||||
|
return &StreamResult{
|
||||||
|
Success: false,
|
||||||
|
Provider: provider,
|
||||||
|
Error: "provider not found",
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTVStreamByProvider gets TV stream from specific provider
|
||||||
|
func (pm *PlayersManager) GetTVStreamByProvider(provider, tmdbID string, season, episode int) (*StreamResult, error) {
|
||||||
|
switch provider {
|
||||||
|
case "rgshows":
|
||||||
|
return pm.rgshows.GetTVStream(tmdbID, season, episode)
|
||||||
|
default:
|
||||||
|
return &StreamResult{
|
||||||
|
Success: false,
|
||||||
|
Provider: provider,
|
||||||
|
Error: "provider not found",
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetStreamWithKinopoisk gets stream using Kinopoisk ID and IMDB ID (for IframeVideo)
|
||||||
|
func (pm *PlayersManager) GetStreamWithKinopoisk(kinopoiskID, imdbID string) (*StreamResult, error) {
|
||||||
|
return pm.iframevideo.GetStream(kinopoiskID, imdbID)
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"encoding/json"
|
||||||
"github.com/golang-jwt/jwt/v5"
|
"github.com/golang-jwt/jwt/v5"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
@@ -19,17 +20,16 @@ import (
|
|||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
"golang.org/x/oauth2/google"
|
"golang.org/x/oauth2/google"
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"neomovies-api/pkg/models"
|
"neomovies-api/pkg/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AuthService contains the database connection, JWT secret, and email service.
|
// AuthService contains the database connection, JWT secret, and email service.
|
||||||
type AuthService struct {
|
type AuthService struct {
|
||||||
db *mongo.Database
|
db *mongo.Database
|
||||||
jwtSecret string
|
jwtSecret string
|
||||||
emailService *EmailService
|
emailService *EmailService
|
||||||
baseURL string
|
baseURL string
|
||||||
googleClientID string
|
googleClientID string
|
||||||
googleClientSecret string
|
googleClientSecret string
|
||||||
googleRedirectURL string
|
googleRedirectURL string
|
||||||
@@ -38,18 +38,18 @@ type AuthService struct {
|
|||||||
|
|
||||||
// Reaction represents a reaction entry in the database.
|
// Reaction represents a reaction entry in the database.
|
||||||
type Reaction struct {
|
type Reaction struct {
|
||||||
MediaID string `bson:"mediaId"`
|
MediaID string `bson:"mediaId"`
|
||||||
Type string `bson:"type"`
|
Type string `bson:"type"`
|
||||||
UserID primitive.ObjectID `bson:"userId"`
|
UserID primitive.ObjectID `bson:"userId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAuthService creates and initializes a new AuthService.
|
// NewAuthService creates and initializes a new AuthService.
|
||||||
func NewAuthService(db *mongo.Database, jwtSecret string, emailService *EmailService, baseURL string, googleClientID string, googleClientSecret string, googleRedirectURL string, frontendURL string) *AuthService {
|
func NewAuthService(db *mongo.Database, jwtSecret string, emailService *EmailService, baseURL string, googleClientID string, googleClientSecret string, googleRedirectURL string, frontendURL string) *AuthService {
|
||||||
service := &AuthService{
|
service := &AuthService{
|
||||||
db: db,
|
db: db,
|
||||||
jwtSecret: jwtSecret,
|
jwtSecret: jwtSecret,
|
||||||
emailService: emailService,
|
emailService: emailService,
|
||||||
baseURL: baseURL,
|
baseURL: baseURL,
|
||||||
googleClientID: googleClientID,
|
googleClientID: googleClientID,
|
||||||
googleClientSecret: googleClientSecret,
|
googleClientSecret: googleClientSecret,
|
||||||
googleRedirectURL: googleRedirectURL,
|
googleRedirectURL: googleRedirectURL,
|
||||||
@@ -81,11 +81,11 @@ func (s *AuthService) GetGoogleLoginURL(state string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type googleUserInfo struct {
|
type googleUserInfo struct {
|
||||||
Sub string `json:"sub"`
|
Sub string `json:"sub"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Picture string `json:"picture"`
|
Picture string `json:"picture"`
|
||||||
EmailVerified bool `json:"email_verified"`
|
EmailVerified bool `json:"email_verified"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// BuildFrontendRedirect builds frontend URL for redirect after OAuth; returns false if not configured
|
// BuildFrontendRedirect builds frontend URL for redirect after OAuth; returns false if not configured
|
||||||
@@ -149,19 +149,19 @@ func (s *AuthService) HandleGoogleCallback(ctx context.Context, code string) (*m
|
|||||||
if err == mongo.ErrNoDocuments {
|
if err == mongo.ErrNoDocuments {
|
||||||
// Create new user
|
// Create new user
|
||||||
user = models.User{
|
user = models.User{
|
||||||
ID: primitive.NewObjectID(),
|
ID: primitive.NewObjectID(),
|
||||||
Email: gUser.Email,
|
Email: gUser.Email,
|
||||||
Password: "",
|
Password: "",
|
||||||
Name: gUser.Name,
|
Name: gUser.Name,
|
||||||
Avatar: gUser.Picture,
|
Avatar: gUser.Picture,
|
||||||
Favorites: []string{},
|
Favorites: []string{},
|
||||||
Verified: true,
|
Verified: true,
|
||||||
IsAdmin: false,
|
IsAdmin: false,
|
||||||
AdminVerified: false,
|
AdminVerified: false,
|
||||||
CreatedAt: time.Now(),
|
CreatedAt: time.Now(),
|
||||||
UpdatedAt: time.Now(),
|
UpdatedAt: time.Now(),
|
||||||
Provider: "google",
|
Provider: "google",
|
||||||
GoogleID: gUser.Sub,
|
GoogleID: gUser.Sub,
|
||||||
}
|
}
|
||||||
if _, err := collection.InsertOne(ctx, user); err != nil {
|
if _, err := collection.InsertOne(ctx, user); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -171,13 +171,17 @@ func (s *AuthService) HandleGoogleCallback(ctx context.Context, code string) (*m
|
|||||||
} else {
|
} else {
|
||||||
// Existing user: ensure fields
|
// Existing user: ensure fields
|
||||||
update := bson.M{
|
update := bson.M{
|
||||||
"verified": true,
|
"verified": true,
|
||||||
"provider": "google",
|
"provider": "google",
|
||||||
"googleId": gUser.Sub,
|
"googleId": gUser.Sub,
|
||||||
"updatedAt": time.Now(),
|
"updatedAt": time.Now(),
|
||||||
}
|
}
|
||||||
if user.Name == "" && gUser.Name != "" { update["name"] = gUser.Name }
|
if user.Name == "" && gUser.Name != "" {
|
||||||
if user.Avatar == "" && gUser.Picture != "" { update["avatar"] = gUser.Picture }
|
update["name"] = gUser.Name
|
||||||
|
}
|
||||||
|
if user.Avatar == "" && gUser.Picture != "" {
|
||||||
|
update["avatar"] = gUser.Picture
|
||||||
|
}
|
||||||
_, _ = collection.UpdateOne(ctx, bson.M{"_id": user.ID}, bson.M{"$set": update})
|
_, _ = collection.UpdateOne(ctx, bson.M{"_id": user.ID}, bson.M{"$set": update})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,10 +190,16 @@ func (s *AuthService) HandleGoogleCallback(ctx context.Context, code string) (*m
|
|||||||
// If we created user above, we already have user.ID set; else fetch updated
|
// If we created user above, we already have user.ID set; else fetch updated
|
||||||
_ = collection.FindOne(ctx, bson.M{"email": gUser.Email}).Decode(&user)
|
_ = collection.FindOne(ctx, bson.M{"email": gUser.Email}).Decode(&user)
|
||||||
}
|
}
|
||||||
token, err := s.generateJWT(user.ID.Hex())
|
tokenPair, err := s.generateTokenPair(user.ID.Hex(), "", "")
|
||||||
if err != nil { return nil, err }
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return &models.AuthResponse{ Token: token, User: user }, nil
|
return &models.AuthResponse{
|
||||||
|
Token: tokenPair.AccessToken,
|
||||||
|
RefreshToken: tokenPair.RefreshToken,
|
||||||
|
User: user,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// generateVerificationCode creates a 6-digit verification code.
|
// generateVerificationCode creates a 6-digit verification code.
|
||||||
@@ -216,18 +226,18 @@ func (s *AuthService) Register(req models.RegisterRequest) (map[string]interface
|
|||||||
codeExpires := time.Now().Add(10 * time.Minute)
|
codeExpires := time.Now().Add(10 * time.Minute)
|
||||||
|
|
||||||
user := models.User{
|
user := models.User{
|
||||||
ID: primitive.NewObjectID(),
|
ID: primitive.NewObjectID(),
|
||||||
Email: req.Email,
|
Email: req.Email,
|
||||||
Password: string(hashedPassword),
|
Password: string(hashedPassword),
|
||||||
Name: req.Name,
|
Name: req.Name,
|
||||||
Favorites: []string{},
|
Favorites: []string{},
|
||||||
Verified: false,
|
Verified: false,
|
||||||
VerificationCode: code,
|
VerificationCode: code,
|
||||||
VerificationExpires: codeExpires,
|
VerificationExpires: codeExpires,
|
||||||
IsAdmin: false,
|
IsAdmin: false,
|
||||||
AdminVerified: false,
|
AdminVerified: false,
|
||||||
CreatedAt: time.Now(),
|
CreatedAt: time.Now(),
|
||||||
UpdatedAt: time.Now(),
|
UpdatedAt: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = collection.InsertOne(context.Background(), user)
|
_, err = collection.InsertOne(context.Background(), user)
|
||||||
@@ -246,7 +256,7 @@ func (s *AuthService) Register(req models.RegisterRequest) (map[string]interface
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Login authenticates a user.
|
// Login authenticates a user.
|
||||||
func (s *AuthService) Login(req models.LoginRequest) (*models.AuthResponse, error) {
|
func (s *AuthService) LoginWithTokens(req models.LoginRequest, userAgent, ipAddress string) (*models.AuthResponse, error) {
|
||||||
collection := s.db.Collection("users")
|
collection := s.db.Collection("users")
|
||||||
|
|
||||||
var user models.User
|
var user models.User
|
||||||
@@ -264,17 +274,23 @@ func (s *AuthService) Login(req models.LoginRequest) (*models.AuthResponse, erro
|
|||||||
return nil, errors.New("Invalid password")
|
return nil, errors.New("Invalid password")
|
||||||
}
|
}
|
||||||
|
|
||||||
token, err := s.generateJWT(user.ID.Hex())
|
tokenPair, err := s.generateTokenPair(user.ID.Hex(), userAgent, ipAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &models.AuthResponse{
|
return &models.AuthResponse{
|
||||||
Token: token,
|
Token: tokenPair.AccessToken,
|
||||||
User: user,
|
RefreshToken: tokenPair.RefreshToken,
|
||||||
|
User: user,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Login authenticates a user (legacy method for backward compatibility).
|
||||||
|
func (s *AuthService) Login(req models.LoginRequest) (*models.AuthResponse, error) {
|
||||||
|
return s.LoginWithTokens(req, "", "")
|
||||||
|
}
|
||||||
|
|
||||||
// GetUserByID retrieves a user by their ID.
|
// GetUserByID retrieves a user by their ID.
|
||||||
func (s *AuthService) GetUserByID(userID string) (*models.User, error) {
|
func (s *AuthService) GetUserByID(userID string) (*models.User, error) {
|
||||||
collection := s.db.Collection("users")
|
collection := s.db.Collection("users")
|
||||||
@@ -320,7 +336,7 @@ func (s *AuthService) UpdateUser(userID string, updates bson.M) (*models.User, e
|
|||||||
func (s *AuthService) generateJWT(userID string) (string, error) {
|
func (s *AuthService) generateJWT(userID string) (string, error) {
|
||||||
claims := jwt.MapClaims{
|
claims := jwt.MapClaims{
|
||||||
"user_id": userID,
|
"user_id": userID,
|
||||||
"exp": time.Now().Add(time.Hour * 24 * 7).Unix(),
|
"exp": time.Now().Add(time.Hour * 1).Unix(), // Сократил время жизни до 1 часа
|
||||||
"iat": time.Now().Unix(),
|
"iat": time.Now().Unix(),
|
||||||
"jti": uuid.New().String(),
|
"jti": uuid.New().String(),
|
||||||
}
|
}
|
||||||
@@ -329,6 +345,158 @@ func (s *AuthService) generateJWT(userID string) (string, error) {
|
|||||||
return token.SignedString([]byte(s.jwtSecret))
|
return token.SignedString([]byte(s.jwtSecret))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// generateRefreshToken generates a new refresh token
|
||||||
|
func (s *AuthService) generateRefreshToken() string {
|
||||||
|
return uuid.New().String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// generateTokenPair generates both access and refresh tokens
|
||||||
|
func (s *AuthService) generateTokenPair(userID, userAgent, ipAddress string) (*models.TokenPair, error) {
|
||||||
|
accessToken, err := s.generateJWT(userID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshToken := s.generateRefreshToken()
|
||||||
|
|
||||||
|
// Сохраняем refresh token в базе данных
|
||||||
|
collection := s.db.Collection("users")
|
||||||
|
objectID, err := primitive.ObjectIDFromHex(userID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshTokenDoc := models.RefreshToken{
|
||||||
|
Token: refreshToken,
|
||||||
|
ExpiresAt: time.Now().Add(time.Hour * 24 * 30), // 30 дней
|
||||||
|
CreatedAt: time.Now(),
|
||||||
|
UserAgent: userAgent,
|
||||||
|
IPAddress: ipAddress,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Удаляем старые истекшие токены и добавляем новый
|
||||||
|
_, err = collection.UpdateOne(
|
||||||
|
context.Background(),
|
||||||
|
bson.M{"_id": objectID},
|
||||||
|
bson.M{
|
||||||
|
"$pull": bson.M{
|
||||||
|
"refreshTokens": bson.M{
|
||||||
|
"expiresAt": bson.M{"$lt": time.Now()},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = collection.UpdateOne(
|
||||||
|
context.Background(),
|
||||||
|
bson.M{"_id": objectID},
|
||||||
|
bson.M{
|
||||||
|
"$push": bson.M{
|
||||||
|
"refreshTokens": refreshTokenDoc,
|
||||||
|
},
|
||||||
|
"$set": bson.M{
|
||||||
|
"updatedAt": time.Now(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &models.TokenPair{
|
||||||
|
AccessToken: accessToken,
|
||||||
|
RefreshToken: refreshToken,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// RefreshAccessToken refreshes an access token using a refresh token
|
||||||
|
func (s *AuthService) RefreshAccessToken(refreshToken, userAgent, ipAddress string) (*models.TokenPair, error) {
|
||||||
|
collection := s.db.Collection("users")
|
||||||
|
|
||||||
|
// Найти пользователя с данным refresh токеном
|
||||||
|
var user models.User
|
||||||
|
err := collection.FindOne(
|
||||||
|
context.Background(),
|
||||||
|
bson.M{
|
||||||
|
"refreshTokens": bson.M{
|
||||||
|
"$elemMatch": bson.M{
|
||||||
|
"token": refreshToken,
|
||||||
|
"expiresAt": bson.M{"$gt": time.Now()},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
).Decode(&user)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("invalid or expired refresh token")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Удалить использованный refresh token
|
||||||
|
_, err = collection.UpdateOne(
|
||||||
|
context.Background(),
|
||||||
|
bson.M{"_id": user.ID},
|
||||||
|
bson.M{
|
||||||
|
"$pull": bson.M{
|
||||||
|
"refreshTokens": bson.M{
|
||||||
|
"token": refreshToken,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Создать новую пару токенов
|
||||||
|
return s.generateTokenPair(user.ID.Hex(), userAgent, ipAddress)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RevokeRefreshToken revokes a specific refresh token
|
||||||
|
func (s *AuthService) RevokeRefreshToken(userID, refreshToken string) error {
|
||||||
|
collection := s.db.Collection("users")
|
||||||
|
objectID, err := primitive.ObjectIDFromHex(userID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = collection.UpdateOne(
|
||||||
|
context.Background(),
|
||||||
|
bson.M{"_id": objectID},
|
||||||
|
bson.M{
|
||||||
|
"$pull": bson.M{
|
||||||
|
"refreshTokens": bson.M{
|
||||||
|
"token": refreshToken,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// RevokeAllRefreshTokens revokes all refresh tokens for a user
|
||||||
|
func (s *AuthService) RevokeAllRefreshTokens(userID string) error {
|
||||||
|
collection := s.db.Collection("users")
|
||||||
|
objectID, err := primitive.ObjectIDFromHex(userID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = collection.UpdateOne(
|
||||||
|
context.Background(),
|
||||||
|
bson.M{"_id": objectID},
|
||||||
|
bson.M{
|
||||||
|
"$set": bson.M{
|
||||||
|
"refreshTokens": []models.RefreshToken{},
|
||||||
|
"updatedAt": time.Now(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// VerifyEmail verifies a user's email with a code.
|
// VerifyEmail verifies a user's email with a code.
|
||||||
func (s *AuthService) VerifyEmail(req models.VerifyEmailRequest) (map[string]interface{}, error) {
|
func (s *AuthService) VerifyEmail(req models.VerifyEmailRequest) (map[string]interface{}, error) {
|
||||||
collection := s.db.Collection("users")
|
collection := s.db.Collection("users")
|
||||||
@@ -439,7 +607,7 @@ func (s *AuthService) DeleteAccount(ctx context.Context, userID string) error {
|
|||||||
go func(r Reaction) {
|
go func(r Reaction) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
url := fmt.Sprintf("%s/reactions/remove/%s/%s", s.baseURL, r.MediaID, r.Type) // Changed from cubAPIURL to baseURL
|
url := fmt.Sprintf("%s/reactions/remove/%s/%s", s.baseURL, r.MediaID, r.Type) // Changed from cubAPIURL to baseURL
|
||||||
req, err := http.NewRequestWithContext(ctx, "POST", url, nil) // or "DELETE"
|
req, err := http.NewRequestWithContext(ctx, "POST", url, nil) // or "DELETE"
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Log the error but don't stop the process
|
// Log the error but don't stop the process
|
||||||
fmt.Printf("failed to create request for cub.rip: %v\n", err)
|
fmt.Printf("failed to create request for cub.rip: %v\n", err)
|
||||||
|
|||||||
@@ -48,8 +48,6 @@ func (s *MovieService) GetSimilar(id, page int, language string) (*models.TMDBRe
|
|||||||
return s.tmdb.GetSimilarMovies(id, page, language)
|
return s.tmdb.GetSimilarMovies(id, page, language)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func (s *MovieService) GetExternalIDs(id int) (*models.ExternalIDs, error) {
|
func (s *MovieService) GetExternalIDs(id int) (*models.ExternalIDs, error) {
|
||||||
return s.tmdb.GetMovieExternalIDs(id)
|
return s.tmdb.GetMovieExternalIDs(id)
|
||||||
}
|
}
|
||||||
@@ -83,7 +83,9 @@ func (s *ReactionsService) GetMyReaction(userID, mediaType, mediaID string) (str
|
|||||||
collection := s.db.Collection("reactions")
|
collection := s.db.Collection("reactions")
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
var result struct{ Type string `bson:"type"` }
|
var result struct {
|
||||||
|
Type string `bson:"type"`
|
||||||
|
}
|
||||||
err := collection.FindOne(ctx, bson.M{
|
err := collection.FindOne(ctx, bson.M{
|
||||||
"userId": userID,
|
"userId": userID,
|
||||||
"mediaType": mediaType,
|
"mediaType": mediaType,
|
||||||
|
|||||||
@@ -207,7 +207,6 @@ func (s *TorrentService) SearchTorrentsByIMDbID(tmdbService *TMDBService, imdbID
|
|||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// SearchMovies - поиск фильмов с дополнительной фильтрацией
|
// SearchMovies - поиск фильмов с дополнительной фильтрацией
|
||||||
func (s *TorrentService) SearchMovies(title, originalTitle, year string) (*models.TorrentSearchResponse, error) {
|
func (s *TorrentService) SearchMovies(title, originalTitle, year string) (*models.TorrentSearchResponse, error) {
|
||||||
params := map[string]string{
|
params := map[string]string{
|
||||||
|
|||||||
Reference in New Issue
Block a user