mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-08 11:07:42 +08:00
feat: proxy only affects tmdb
This commit is contained in:
@@ -66,7 +66,8 @@ func (c *Client) TMDB() (*tmdb.Client, error) {
|
||||
if api == "" {
|
||||
return nil, errors.New("TMDB apiKey not set")
|
||||
}
|
||||
return tmdb.NewClient(api)
|
||||
proxy := c.db.GetSetting(db.SettingProxy)
|
||||
return tmdb.NewClient(api, proxy)
|
||||
}
|
||||
|
||||
func (c *Client) MustTMDB() *tmdb.Client {
|
||||
|
||||
@@ -39,8 +39,6 @@ type Server struct {
|
||||
|
||||
func (s *Server) Serve() error {
|
||||
s.core.Init()
|
||||
|
||||
s.restoreProxy()
|
||||
|
||||
s.jwtSerect = s.db.GetSetting(db.JwtSerectKey)
|
||||
//st, _ := fs.Sub(ui.Web, "build/web")
|
||||
@@ -129,7 +127,8 @@ func (s *Server) TMDB() (*tmdb.Client, error) {
|
||||
if api == "" {
|
||||
return nil, errors.New("TMDB apiKey not set")
|
||||
}
|
||||
return tmdb.NewClient(api)
|
||||
proxy := s.db.GetSetting(db.SettingProxy)
|
||||
return tmdb.NewClient(api, proxy)
|
||||
}
|
||||
|
||||
func (s *Server) MustTMDB() *tmdb.Client {
|
||||
|
||||
@@ -3,8 +3,6 @@ package server
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"polaris/db"
|
||||
"polaris/ent"
|
||||
"polaris/log"
|
||||
@@ -55,29 +53,10 @@ func (s *Server) SetSetting(c *gin.Context) (interface{}, error) {
|
||||
s.db.SetSetting(db.SettingPlexMatchEnabled, "false")
|
||||
}
|
||||
|
||||
s.setProxy(in.Proxy)
|
||||
s.db.SetSetting(db.SettingProxy, in.Proxy)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *Server) setProxy(proxy string) {
|
||||
proxyUrl, err := url.Parse(proxy)
|
||||
tp := http.DefaultTransport.(*http.Transport)
|
||||
if proxy == "" || err != nil {
|
||||
log.Warnf("proxy url not valid, disabling: %v", proxy)
|
||||
tp.Proxy = nil
|
||||
s.db.SetSetting(db.SettingProxy, "")
|
||||
} else {
|
||||
log.Infof("set proxy to %v", proxy)
|
||||
tp.Proxy = http.ProxyURL(proxyUrl)
|
||||
s.db.SetSetting(db.SettingProxy, proxy)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) restoreProxy() {
|
||||
p := s.db.GetSetting(db.SettingProxy)
|
||||
s.setProxy(p)
|
||||
}
|
||||
|
||||
func (s *Server) GetSetting(c *gin.Context) (interface{}, error) {
|
||||
tmdb := s.db.GetSetting(db.SettingTmdbApiKey)
|
||||
downloadDir := s.db.GetSetting(db.SettingDownloadDir)
|
||||
|
||||
Reference in New Issue
Block a user