Update the configuration reading using polochon's way
This commit is contained in:
parent
9424780861
commit
1a30447ab1
@ -8,5 +8,5 @@ import (
|
||||
|
||||
// GetModulesStatuses return the statuses of all the modules
|
||||
func GetModulesStatuses(env *web.Env, w http.ResponseWriter, r *http.Request) error {
|
||||
return env.RenderJSON(w, env.Config.PolochonConfig.ModulesStatus())
|
||||
return env.RenderJSON(w, env.Config.ModulesStatus())
|
||||
}
|
||||
|
@ -10,7 +10,8 @@ import (
|
||||
|
||||
// Backend represents the data backend
|
||||
type Backend struct {
|
||||
Database *sqlx.DB
|
||||
Database *sqlx.DB
|
||||
configured bool
|
||||
}
|
||||
|
||||
// Name implements the Module interface
|
||||
@ -18,6 +19,12 @@ func (b *Backend) Name() string {
|
||||
return "canape-backend"
|
||||
}
|
||||
|
||||
// Init implements the module interface
|
||||
func (b *Backend) Init([]byte) error {
|
||||
b.configured = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// Status implements the Module interface
|
||||
func (b *Backend) Status() (polochon.ModuleStatus, error) {
|
||||
return polochon.StatusOK, nil
|
||||
|
@ -7,19 +7,46 @@ import (
|
||||
polochonConfig "github.com/odwrtw/polochon/lib/configuration"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// Config represents the Config of the canape app
|
||||
type Config struct {
|
||||
// Canape holds the canape specific config
|
||||
type Canape struct {
|
||||
Authorizer AuthorizerConfig `yaml:"authorizer"`
|
||||
PGDSN string `yaml:"pgdsn"`
|
||||
Port string `yaml:"listen_port"`
|
||||
PublicDir string `yaml:"public_dir"`
|
||||
ImgURLPrefix string `yaml:"img_url_prefix"`
|
||||
PeriodicRefresh PeriodicRefreshConfig `yaml:"periodic_refresh"`
|
||||
}
|
||||
|
||||
PolochonConfig *polochonConfig.Config
|
||||
// Config represents the Config of the canape app
|
||||
type Config struct {
|
||||
polochonConfig.Config
|
||||
Canape
|
||||
}
|
||||
|
||||
// UnmarshalYAML implements the Unmarshaler interface
|
||||
func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
polochonParams := struct {
|
||||
polochonConfig.Config `yaml:",inline"`
|
||||
}{}
|
||||
|
||||
if err := unmarshal(&polochonParams); err != nil {
|
||||
return err
|
||||
}
|
||||
c.Config = polochonParams.Config
|
||||
|
||||
canapeParams := struct {
|
||||
Canape `yaml:",inline"`
|
||||
}{}
|
||||
|
||||
if err := unmarshal(&canapeParams); err != nil {
|
||||
return err
|
||||
}
|
||||
c.Canape = canapeParams.Canape
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AuthorizerConfig is the config for the authentication
|
||||
@ -44,41 +71,11 @@ func Load(path string, log *logrus.Entry) (*Config, error) {
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
cf := &Config{}
|
||||
polochonConfigFile := &polochonConfig.ConfigFileRoot{}
|
||||
polochonConfig := &polochonConfig.Config{}
|
||||
|
||||
// Read it
|
||||
b, err := ioutil.ReadAll(file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Unmarshal its content into the Config obj
|
||||
err = yaml.Unmarshal(b, cf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Unmarshal its content into the polochon.ConfigFileRoot obj
|
||||
err = yaml.Unmarshal(b, polochonConfigFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Init all the show torrenters / detailers / searchers / explorers
|
||||
err = polochonConfig.InitShow(polochonConfigFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Init all the movie torrenters / detailers / searchers / explorers
|
||||
err = polochonConfig.InitMovie(polochonConfigFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cf.PolochonConfig = polochonConfig
|
||||
|
||||
return cf, nil
|
||||
conf := &Config{}
|
||||
return conf, yaml.Unmarshal(b, conf)
|
||||
}
|
||||
|
@ -15,9 +15,9 @@ import (
|
||||
func NewExplorer(env *web.Env, mediaType, name string) (polochon.Explorer, error) {
|
||||
var explorers []polochon.Explorer
|
||||
if mediaType == "movie" {
|
||||
explorers = env.Config.PolochonConfig.Movie.Explorers
|
||||
explorers = env.Config.Movie.Explorers
|
||||
} else {
|
||||
explorers = env.Config.PolochonConfig.Show.Explorers
|
||||
explorers = env.Config.Show.Explorers
|
||||
}
|
||||
|
||||
for _, e := range explorers {
|
||||
@ -96,7 +96,7 @@ func GetMediaIDs(env *web.Env, mediaType string, source string, category string)
|
||||
func RefreshShows(env *web.Env) {
|
||||
showMap := make(map[string]*shows.Show)
|
||||
// Iterate over all show explorers
|
||||
for _, showExplorer := range env.Config.PolochonConfig.Show.Explorers {
|
||||
for _, showExplorer := range env.Config.Show.Explorers {
|
||||
availableOptions := showExplorer.AvailableShowOptions()
|
||||
// Iterate over all show explorer options
|
||||
for _, option := range availableOptions {
|
||||
@ -132,7 +132,7 @@ func RefreshShows(env *web.Env) {
|
||||
for id := range showMap {
|
||||
show := shows.New(id, env.Config.PublicDir, env.Config.ImgURLPrefix)
|
||||
// Refresh the shows
|
||||
err := show.Refresh(env, env.Config.PolochonConfig.Show.Detailers)
|
||||
err := show.Refresh(env, env.Config.Show.Detailers)
|
||||
if err != nil {
|
||||
env.Log.Warnf("error while refreshing show %s : %s", id, err)
|
||||
}
|
||||
@ -146,7 +146,7 @@ func RefreshShows(env *web.Env) {
|
||||
// too many requests on our torrenters
|
||||
for _, e := range show.LastSeasonEpisodes() {
|
||||
// Refresh the torrents
|
||||
err := shows.RefreshTorrents(env, e, env.Config.PolochonConfig.Show.Torrenters)
|
||||
err := shows.RefreshTorrents(env, e, env.Config.Show.Torrenters)
|
||||
if err != nil {
|
||||
env.Log.Error(err)
|
||||
}
|
||||
@ -162,7 +162,7 @@ func RefreshShows(env *web.Env) {
|
||||
func RefreshMovies(env *web.Env) {
|
||||
movieMap := make(map[string]struct{})
|
||||
// Iterate over all movie explorers
|
||||
for _, movieExplorer := range env.Config.PolochonConfig.Movie.Explorers {
|
||||
for _, movieExplorer := range env.Config.Movie.Explorers {
|
||||
availableOptions := movieExplorer.AvailableMovieOptions()
|
||||
// Iterate over all movie explorer options
|
||||
for _, option := range availableOptions {
|
||||
@ -198,12 +198,12 @@ func RefreshMovies(env *web.Env) {
|
||||
for id := range movieMap {
|
||||
movie := movies.New(id, nil, nil, false, env.Config.PublicDir, env.Config.ImgURLPrefix)
|
||||
// Refresh the movie
|
||||
err := movie.Refresh(env, env.Config.PolochonConfig.Movie.Detailers)
|
||||
err := movie.Refresh(env, env.Config.Movie.Detailers)
|
||||
if err != nil {
|
||||
env.Log.Warnf("error while refreshing movie %s : %s", id, err)
|
||||
}
|
||||
// Refresh its torrents
|
||||
err = movie.RefreshTorrents(env, env.Config.PolochonConfig.Movie.Torrenters)
|
||||
err = movie.RefreshTorrents(env, env.Config.Movie.Torrenters)
|
||||
if err != nil {
|
||||
env.Log.Warnf("error while refreshing movie torrents %s : %s", id, err)
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ func GetMovies(env *web.Env, user *users.User, source string, category string) (
|
||||
// First check in the DB
|
||||
before := []polochon.Detailer{env.Backend.Detailer}
|
||||
// Then with the default detailers
|
||||
after := env.Config.PolochonConfig.Movie.Detailers
|
||||
after := env.Config.Movie.Detailers
|
||||
err := movie.GetAndFetch(env, before, after)
|
||||
if err != nil {
|
||||
env.Log.Errorf("error while getting movie details : %s", err)
|
||||
@ -148,7 +148,7 @@ func GetShows(env *web.Env, user *users.User, source string, category string, fo
|
||||
// First check in the DB
|
||||
before := []polochon.Detailer{env.Backend.Detailer}
|
||||
// Then with the default detailers
|
||||
after := env.Config.PolochonConfig.Show.Detailers
|
||||
after := env.Config.Show.Detailers
|
||||
err := show.GetAndFetch(env, before, after)
|
||||
if err != nil {
|
||||
env.Log.Errorf("error while getting show details : %s", err)
|
||||
|
@ -45,7 +45,7 @@ func PolochonMoviesHandler(env *web.Env, w http.ResponseWriter, r *http.Request)
|
||||
// First try from the db
|
||||
first := []polochon.Detailer{env.Backend.Detailer}
|
||||
// Then try from the polochon detailer
|
||||
detailers := env.Config.PolochonConfig.Movie.Detailers
|
||||
detailers := env.Config.Movie.Detailers
|
||||
err := m.GetAndFetch(env, first, detailers)
|
||||
if err != nil {
|
||||
env.Log.Error(err)
|
||||
@ -97,12 +97,12 @@ func RefreshMovieHandler(env *web.Env, w http.ResponseWriter, r *http.Request) e
|
||||
m := New(id, client, pMovie, isWishlisted, env.Config.PublicDir, env.Config.ImgURLPrefix)
|
||||
|
||||
// Refresh the movie's infos
|
||||
if err := m.Refresh(env, env.Config.PolochonConfig.Movie.Detailers); err != nil {
|
||||
if err := m.Refresh(env, env.Config.Movie.Detailers); err != nil {
|
||||
env.Log.Error(err)
|
||||
}
|
||||
|
||||
// Refresh the movie's torrents
|
||||
if err := m.RefreshTorrents(env, env.Config.PolochonConfig.Movie.Torrenters); err != nil {
|
||||
if err := m.RefreshTorrents(env, env.Config.Movie.Torrenters); err != nil {
|
||||
env.Log.Error(err)
|
||||
}
|
||||
|
||||
@ -139,7 +139,7 @@ func SearchMovie(env *web.Env, w http.ResponseWriter, r *http.Request) error {
|
||||
}
|
||||
|
||||
var movies []*polochon.Movie
|
||||
searchers := env.Config.PolochonConfig.Movie.Searchers
|
||||
searchers := env.Config.Movie.Searchers
|
||||
// Search for the movie with all the Searchers
|
||||
for _, searcher := range searchers {
|
||||
result, err := searcher.SearchMovie(search, env.Log)
|
||||
@ -167,7 +167,7 @@ func SearchMovie(env *web.Env, w http.ResponseWriter, r *http.Request) error {
|
||||
// First check in the DB
|
||||
before := []polochon.Detailer{env.Backend.Detailer}
|
||||
// Then with the default detailers
|
||||
after := env.Config.PolochonConfig.Movie.Detailers
|
||||
after := env.Config.Movie.Detailers
|
||||
err := movie.GetAndFetch(env, before, after)
|
||||
if err != nil {
|
||||
env.Log.Errorf("error while getting movie details : %s", err)
|
||||
@ -293,7 +293,7 @@ func GetWishlistHandler(env *web.Env, w http.ResponseWriter, r *http.Request) er
|
||||
// First check in the DB
|
||||
before := []polochon.Detailer{env.Backend.Detailer}
|
||||
// Then with the default detailers
|
||||
after := env.Config.PolochonConfig.Movie.Detailers
|
||||
after := env.Config.Movie.Detailers
|
||||
err := movie.GetAndFetch(env, before, after)
|
||||
if err != nil {
|
||||
env.Log.Errorf("error while getting movie details : %s", err)
|
||||
|
@ -52,7 +52,7 @@ func GetDetailsHandler(env *web.Env, w http.ResponseWriter, r *http.Request) err
|
||||
// First try from the db
|
||||
first := []polochon.Detailer{env.Backend.Detailer}
|
||||
// Then try from the polochon detailers
|
||||
detailers := env.Config.PolochonConfig.Show.Detailers
|
||||
detailers := env.Config.Show.Detailers
|
||||
err = s.GetAndFetch(env, first, detailers)
|
||||
if err != nil {
|
||||
env.Log.Error(err)
|
||||
@ -100,7 +100,7 @@ func RefreshShowHandler(env *web.Env, w http.ResponseWriter, r *http.Request) er
|
||||
|
||||
s := NewWithClient(id, client, pShow, wShow, env.Config.PublicDir, env.Config.ImgURLPrefix)
|
||||
// Refresh the polochon detailers
|
||||
detailers := env.Config.PolochonConfig.Show.Detailers
|
||||
detailers := env.Config.Show.Detailers
|
||||
err = s.Refresh(env, detailers)
|
||||
if err != nil {
|
||||
env.Log.Error(err)
|
||||
@ -110,7 +110,7 @@ func RefreshShowHandler(env *web.Env, w http.ResponseWriter, r *http.Request) er
|
||||
env.Log.Debug("getting episodes torrents")
|
||||
for _, e := range s.Episodes {
|
||||
// Get torrents from the db
|
||||
err := RefreshTorrents(env, e, env.Config.PolochonConfig.Show.Torrenters)
|
||||
err := RefreshTorrents(env, e, env.Config.Show.Torrenters)
|
||||
if err != nil {
|
||||
env.Log.Error(err)
|
||||
}
|
||||
@ -133,7 +133,7 @@ func SearchShow(env *web.Env, w http.ResponseWriter, r *http.Request) error {
|
||||
}
|
||||
|
||||
var shows []*polochon.Show
|
||||
searchers := env.Config.PolochonConfig.Show.Searchers
|
||||
searchers := env.Config.Show.Searchers
|
||||
// Iterate on all the searchers to search for the show
|
||||
for _, searcher := range searchers {
|
||||
result, err := searcher.SearchShow(search, env.Log)
|
||||
@ -174,7 +174,7 @@ func SearchShow(env *web.Env, w http.ResponseWriter, r *http.Request) error {
|
||||
// First try from the db
|
||||
first := []polochon.Detailer{env.Backend.Detailer}
|
||||
// Then try from the polochon detailers
|
||||
detailers := env.Config.PolochonConfig.Show.Detailers
|
||||
detailers := env.Config.Show.Detailers
|
||||
err := show.GetAndFetch(env, first, detailers)
|
||||
if err != nil {
|
||||
env.Log.Error(err)
|
||||
@ -265,7 +265,7 @@ func GetWishlistHandler(env *web.Env, w http.ResponseWriter, r *http.Request) er
|
||||
// First check in the DB
|
||||
before := []polochon.Detailer{env.Backend.Detailer}
|
||||
// Then with the default detailers
|
||||
after := env.Config.PolochonConfig.Show.Detailers
|
||||
after := env.Config.Show.Detailers
|
||||
err := show.GetAndFetch(env, before, after)
|
||||
if err != nil {
|
||||
env.Log.Errorf("error while getting show details : %s", err)
|
||||
@ -297,7 +297,7 @@ func PolochonShowsHandler(env *web.Env, w http.ResponseWriter, r *http.Request)
|
||||
// First try from the db
|
||||
first := []polochon.Detailer{env.Backend.Detailer}
|
||||
// Then try from the polochon detailer
|
||||
detailers := env.Config.PolochonConfig.Show.Detailers
|
||||
detailers := env.Config.Show.Detailers
|
||||
err := s.GetAndFetch(env, first, detailers)
|
||||
if err != nil {
|
||||
env.Log.Error(err)
|
||||
@ -335,14 +335,14 @@ func RefreshEpisodeHandler(env *web.Env, w http.ResponseWriter, r *http.Request)
|
||||
|
||||
e := NewEpisode(client, pShow, id, season, episode)
|
||||
// Refresh the episode
|
||||
err = e.Refresh(env, env.Config.PolochonConfig.Show.Detailers)
|
||||
err = e.Refresh(env, env.Config.Show.Detailers)
|
||||
if err != nil {
|
||||
env.Log.Error(err)
|
||||
return env.RenderError(w, err)
|
||||
}
|
||||
|
||||
// Refresh the torrents
|
||||
err = e.RefreshTorrents(env, env.Config.PolochonConfig.Show.Torrenters)
|
||||
err = e.RefreshTorrents(env, env.Config.Show.Torrenters)
|
||||
if err != nil {
|
||||
env.Log.Error(err)
|
||||
}
|
||||
|
@ -107,9 +107,9 @@ func SearchHandler(env *web.Env, w http.ResponseWriter, r *http.Request) error {
|
||||
var torrenters []polochon.Torrenter
|
||||
switch searchType {
|
||||
case "movies":
|
||||
torrenters = env.Config.PolochonConfig.Movie.Torrenters
|
||||
torrenters = env.Config.Movie.Torrenters
|
||||
case "shows":
|
||||
torrenters = env.Config.PolochonConfig.Show.Torrenters
|
||||
torrenters = env.Config.Show.Torrenters
|
||||
default:
|
||||
return env.RenderError(w, errors.New("invalid search type"))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user