Cleanup the PublicDir / ImgURLPrefix stuff
This commit is contained in:
parent
eff6b6e19f
commit
7f91b145eb
@ -130,7 +130,7 @@ func RefreshShows(env *web.Env) {
|
|||||||
|
|
||||||
// Iterate over the map of shows to refresh them
|
// Iterate over the map of shows to refresh them
|
||||||
for id := range showMap {
|
for id := range showMap {
|
||||||
show := shows.New(id, env.Config.PublicDir, env.Config.ImgURLPrefix)
|
show := shows.New(id)
|
||||||
// Refresh the shows
|
// Refresh the shows
|
||||||
err := show.Refresh(env, env.Config.Show.Detailers)
|
err := show.Refresh(env, env.Config.Show.Detailers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -196,7 +196,7 @@ func RefreshMovies(env *web.Env) {
|
|||||||
|
|
||||||
// Iterate over the map of movies to refresh them
|
// Iterate over the map of movies to refresh them
|
||||||
for id := range movieMap {
|
for id := range movieMap {
|
||||||
movie := movies.New(env, id, nil, nil, false)
|
movie := movies.New(id, nil, nil, false)
|
||||||
// Refresh the movie
|
// Refresh the movie
|
||||||
err := movie.Refresh(env, env.Config.Movie.Detailers)
|
err := movie.Refresh(env, env.Config.Movie.Detailers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -80,7 +80,7 @@ func GetMovies(env *web.Env, user *models.User, source string, category string)
|
|||||||
// Fill all the movies infos from the list of IDs
|
// Fill all the movies infos from the list of IDs
|
||||||
for _, id := range media.IDs {
|
for _, id := range media.IDs {
|
||||||
pMovie, _ := pMovies.Has(id)
|
pMovie, _ := pMovies.Has(id)
|
||||||
movie := movies.New(env, id, client, pMovie, moviesWishlist.IsMovieInWishlist(id))
|
movie := movies.New(id, client, pMovie, moviesWishlist.IsMovieInWishlist(id))
|
||||||
// First check in the DB
|
// First check in the DB
|
||||||
before := []polochon.Detailer{env.Backend.Detailer}
|
before := []polochon.Detailer{env.Backend.Detailer}
|
||||||
// Then with the default detailers
|
// Then with the default detailers
|
||||||
@ -141,7 +141,7 @@ func GetShows(env *web.Env, user *models.User, source string, category string, f
|
|||||||
for _, id := range media.IDs {
|
for _, id := range media.IDs {
|
||||||
pShow, _ := pShows.Has(id)
|
pShow, _ := pShows.Has(id)
|
||||||
wShow, _ := wShows.IsShowInWishlist(id)
|
wShow, _ := wShows.IsShowInWishlist(id)
|
||||||
show := shows.NewWithClient(&polochon.Show{ImdbID: id}, client, pShow, wShow, env.Config.PublicDir, env.Config.ImgURLPrefix)
|
show := shows.NewWithClient(&polochon.Show{ImdbID: id}, client, pShow, wShow)
|
||||||
|
|
||||||
// First check in the DB
|
// First check in the DB
|
||||||
before := []polochon.Detailer{env.Backend.Detailer}
|
before := []polochon.Detailer{env.Backend.Detailer}
|
||||||
|
@ -76,7 +76,7 @@ func RefreshMovieHandler(env *web.Env, w http.ResponseWriter, r *http.Request) e
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a new movie
|
// Create a new movie
|
||||||
m := New(env, id, client, pMovie, isWishlisted)
|
m := New(id, client, pMovie, isWishlisted)
|
||||||
|
|
||||||
// Refresh the movie's infos
|
// Refresh the movie's infos
|
||||||
if err := m.Refresh(env, env.Config.Movie.Detailers); err != nil {
|
if err := m.Refresh(env, env.Config.Movie.Detailers); err != nil {
|
||||||
@ -141,7 +141,6 @@ func SearchMovie(env *web.Env, w http.ResponseWriter, r *http.Request) error {
|
|||||||
for _, m := range movies {
|
for _, m := range movies {
|
||||||
pMovie, _ := pMovies.Has(m.ImdbID)
|
pMovie, _ := pMovies.Has(m.ImdbID)
|
||||||
movie := New(
|
movie := New(
|
||||||
env,
|
|
||||||
m.ImdbID,
|
m.ImdbID,
|
||||||
client,
|
client,
|
||||||
pMovie,
|
pMovie,
|
||||||
@ -251,7 +250,6 @@ func GetWishlistHandler(env *web.Env, w http.ResponseWriter, r *http.Request) er
|
|||||||
for _, imdbID := range moviesWishlist.List() {
|
for _, imdbID := range moviesWishlist.List() {
|
||||||
pMovie, _ := pMovies.Has(imdbID)
|
pMovie, _ := pMovies.Has(imdbID)
|
||||||
movie := New(
|
movie := New(
|
||||||
env,
|
|
||||||
imdbID,
|
imdbID,
|
||||||
client,
|
client,
|
||||||
pMovie,
|
pMovie,
|
||||||
|
@ -21,8 +21,6 @@ type Movie struct {
|
|||||||
*polochon.Movie
|
*polochon.Movie
|
||||||
client *papi.Client
|
client *papi.Client
|
||||||
pMovie *papi.Movie
|
pMovie *papi.Movie
|
||||||
publicDir string
|
|
||||||
imgURLPrefix string
|
|
||||||
Wishlisted bool `json:"wishlisted"`
|
Wishlisted bool `json:"wishlisted"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,12 +72,10 @@ func (m *Movie) MarshalJSON() ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new Movie with all the needed infos
|
// New returns a new Movie with all the needed infos
|
||||||
func New(env *web.Env, imdbID string, client *papi.Client, pMovie *papi.Movie, isWishlisted bool) *Movie {
|
func New(imdbID string, client *papi.Client, pMovie *papi.Movie, isWishlisted bool) *Movie {
|
||||||
return &Movie{
|
return &Movie{
|
||||||
client: client,
|
client: client,
|
||||||
pMovie: pMovie,
|
pMovie: pMovie,
|
||||||
publicDir: env.Config.PublicDir,
|
|
||||||
imgURLPrefix: env.Config.ImgURLPrefix,
|
|
||||||
Wishlisted: isWishlisted,
|
Wishlisted: isWishlisted,
|
||||||
Movie: &polochon.Movie{
|
Movie: &polochon.Movie{
|
||||||
ImdbID: imdbID,
|
ImdbID: imdbID,
|
||||||
@ -241,7 +237,7 @@ func (m *Movie) imgURL() string {
|
|||||||
|
|
||||||
// imgFile returns the image location on disk
|
// imgFile returns the image location on disk
|
||||||
func (m *Movie) imgFile() string {
|
func (m *Movie) imgFile() string {
|
||||||
return filepath.Join(m.publicDir, "img", m.imgURL())
|
return filepath.Join(models.PublicDir, "img", m.imgURL())
|
||||||
}
|
}
|
||||||
|
|
||||||
// getPolochonMovies returns an array of the user's polochon movies
|
// getPolochonMovies returns an array of the user's polochon movies
|
||||||
@ -269,7 +265,6 @@ func getPolochonMovies(user *models.User, env *web.Env) ([]*Movie, error) {
|
|||||||
// Create Movies objects from the movies retrieved
|
// Create Movies objects from the movies retrieved
|
||||||
for _, pmovie := range pmovies.List() {
|
for _, pmovie := range pmovies.List() {
|
||||||
movie := New(
|
movie := New(
|
||||||
env,
|
|
||||||
pmovie.ImdbID,
|
pmovie.ImdbID,
|
||||||
client,
|
client,
|
||||||
pmovie,
|
pmovie,
|
||||||
|
@ -43,7 +43,7 @@ func GetDetailsHandler(env *web.Env, w http.ResponseWriter, r *http.Request) err
|
|||||||
log.Println("Got error getting wishlisted show ", err)
|
log.Println("Got error getting wishlisted show ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
s := NewWithClient(&polochon.Show{ImdbID: id}, client, pShow, wShow, env.Config.PublicDir, env.Config.ImgURLPrefix)
|
s := NewWithClient(&polochon.Show{ImdbID: id}, client, pShow, wShow)
|
||||||
// First try from the db
|
// First try from the db
|
||||||
first := []polochon.Detailer{env.Backend.Detailer}
|
first := []polochon.Detailer{env.Backend.Detailer}
|
||||||
// Then try from the polochon detailers
|
// Then try from the polochon detailers
|
||||||
@ -89,7 +89,7 @@ func RefreshShowHandler(env *web.Env, w http.ResponseWriter, r *http.Request) er
|
|||||||
log.Println("Got error getting wishlisted show ", err)
|
log.Println("Got error getting wishlisted show ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
s := NewWithClient(&polochon.Show{ImdbID: id}, client, pShow, wShow, env.Config.PublicDir, env.Config.ImgURLPrefix)
|
s := NewWithClient(&polochon.Show{ImdbID: id}, client, pShow, wShow)
|
||||||
// Refresh the polochon detailers
|
// Refresh the polochon detailers
|
||||||
detailers := env.Config.Show.Detailers
|
detailers := env.Config.Show.Detailers
|
||||||
err = s.Refresh(env, detailers)
|
err = s.Refresh(env, detailers)
|
||||||
@ -163,7 +163,7 @@ func SearchShow(env *web.Env, w http.ResponseWriter, r *http.Request) error {
|
|||||||
for _, s := range shows {
|
for _, s := range shows {
|
||||||
pShow, _ := pShows.Has(s.ImdbID)
|
pShow, _ := pShows.Has(s.ImdbID)
|
||||||
wShow, _ := wShows.IsShowInWishlist(s.ImdbID)
|
wShow, _ := wShows.IsShowInWishlist(s.ImdbID)
|
||||||
show := NewWithClient(s, client, pShow, wShow, env.Config.PublicDir, env.Config.ImgURLPrefix)
|
show := NewWithClient(s, client, pShow, wShow)
|
||||||
|
|
||||||
// First try from the db
|
// First try from the db
|
||||||
first := []polochon.Detailer{env.Backend.Detailer}
|
first := []polochon.Detailer{env.Backend.Detailer}
|
||||||
@ -243,7 +243,7 @@ func GetWishlistHandler(env *web.Env, w http.ResponseWriter, r *http.Request) er
|
|||||||
for _, wishedShow := range wShows.List() {
|
for _, wishedShow := range wShows.List() {
|
||||||
pShow, _ := pShows.Has(wishedShow.ImdbID)
|
pShow, _ := pShows.Has(wishedShow.ImdbID)
|
||||||
poloShow := &polochon.Show{ImdbID: wishedShow.ImdbID}
|
poloShow := &polochon.Show{ImdbID: wishedShow.ImdbID}
|
||||||
show := NewWithClient(poloShow, client, pShow, wishedShow, env.Config.PublicDir, env.Config.ImgURLPrefix)
|
show := NewWithClient(poloShow, client, pShow, wishedShow)
|
||||||
|
|
||||||
// First check in the DB
|
// First check in the DB
|
||||||
before := []polochon.Detailer{env.Backend.Detailer}
|
before := []polochon.Detailer{env.Backend.Detailer}
|
||||||
@ -312,8 +312,6 @@ func RefreshEpisodeHandler(env *web.Env, w http.ResponseWriter, r *http.Request)
|
|||||||
Show: &polochon.Show{ImdbID: id},
|
Show: &polochon.Show{ImdbID: id},
|
||||||
client: client,
|
client: client,
|
||||||
pShow: pShow,
|
pShow: pShow,
|
||||||
publicDir: env.Config.PublicDir,
|
|
||||||
imgURLPrefix: env.Config.ImgURLPrefix,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
e := NewEpisode(s, season, episode)
|
e := NewEpisode(s, season, episode)
|
||||||
|
@ -22,8 +22,6 @@ type Show struct {
|
|||||||
*polochon.Show
|
*polochon.Show
|
||||||
TrackedSeason *int `json:"tracked_season"`
|
TrackedSeason *int `json:"tracked_season"`
|
||||||
TrackedEpisode *int `json:"tracked_episode"`
|
TrackedEpisode *int `json:"tracked_episode"`
|
||||||
publicDir string
|
|
||||||
imgURLPrefix string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalJSON implements the Marshal interface
|
// MarshalJSON implements the Marshal interface
|
||||||
@ -55,24 +53,20 @@ func (s *Show) MarshalJSON() ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new Show with a polochon ShowConfig
|
// New returns a new Show with a polochon ShowConfig
|
||||||
func New(imdbID string, publicDir, imgURLPrefix string) *Show {
|
func New(imdbID string) *Show {
|
||||||
return &Show{
|
return &Show{
|
||||||
Show: &polochon.Show{
|
Show: &polochon.Show{
|
||||||
ImdbID: imdbID,
|
ImdbID: imdbID,
|
||||||
},
|
},
|
||||||
publicDir: publicDir,
|
|
||||||
imgURLPrefix: imgURLPrefix,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWithClient returns a new Show with a polochon ShowConfig
|
// NewWithClient returns a new Show with a polochon ShowConfig
|
||||||
func NewWithClient(show *polochon.Show, client *papi.Client, pShow *papi.Show, wShow *models.WishedShow, publicDir, imgURLPrefix string) *Show {
|
func NewWithClient(show *polochon.Show, client *papi.Client, pShow *papi.Show, wShow *models.WishedShow) *Show {
|
||||||
s := &Show{
|
s := &Show{
|
||||||
Show: show,
|
Show: show,
|
||||||
client: client,
|
client: client,
|
||||||
pShow: pShow,
|
pShow: pShow,
|
||||||
publicDir: publicDir,
|
|
||||||
imgURLPrefix: imgURLPrefix,
|
|
||||||
}
|
}
|
||||||
if wShow != nil {
|
if wShow != nil {
|
||||||
s.TrackedSeason = &wShow.Season
|
s.TrackedSeason = &wShow.Season
|
||||||
@ -155,7 +149,7 @@ func (s *Show) GetImageURL(imgType string) string {
|
|||||||
if _, err := os.Stat(s.imgFile(imgType)); os.IsNotExist(err) {
|
if _, err := os.Stat(s.imgFile(imgType)); os.IsNotExist(err) {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return s.imgURLPrefix + s.imgURL(imgType)
|
return models.ImgURLPrefix + s.imgURL(imgType)
|
||||||
}
|
}
|
||||||
|
|
||||||
// downloadImages will download the show images
|
// downloadImages will download the show images
|
||||||
@ -217,12 +211,12 @@ func (s *Show) imgURL(imgType string) string {
|
|||||||
|
|
||||||
// imgDirectory returns the directory containing all the show images
|
// imgDirectory returns the directory containing all the show images
|
||||||
func (s *Show) imgDirectory() string {
|
func (s *Show) imgDirectory() string {
|
||||||
return filepath.Join(s.publicDir, "img", fmt.Sprintf("shows/%s", s.ImdbID))
|
return filepath.Join(models.PublicDir, "img", fmt.Sprintf("shows/%s", s.ImdbID))
|
||||||
}
|
}
|
||||||
|
|
||||||
// imgFile returns the image location on disk
|
// imgFile returns the image location on disk
|
||||||
func (s *Show) imgFile(imgType string) string {
|
func (s *Show) imgFile(imgType string) string {
|
||||||
return filepath.Join(s.publicDir, "img", s.imgURL(imgType))
|
return filepath.Join(models.PublicDir, "img", s.imgURL(imgType))
|
||||||
}
|
}
|
||||||
|
|
||||||
// getPolochonShows returns all the Shows from the polochon of a user
|
// getPolochonShows returns all the Shows from the polochon of a user
|
||||||
@ -248,7 +242,7 @@ func getPolochonShows(env *web.Env, user *models.User) ([]*Show, error) {
|
|||||||
// Create Shows objects from the shows retrieved
|
// Create Shows objects from the shows retrieved
|
||||||
for _, pShow := range pshows.List() {
|
for _, pShow := range pshows.List() {
|
||||||
wShow, _ := wShows.IsShowInWishlist(pShow.ImdbID)
|
wShow, _ := wShows.IsShowInWishlist(pShow.ImdbID)
|
||||||
show := NewWithClient(&polochon.Show{ImdbID: pShow.ImdbID}, client, pShow, wShow, env.Config.PublicDir, env.Config.ImgURLPrefix)
|
show := NewWithClient(&polochon.Show{ImdbID: pShow.ImdbID}, client, pShow, wShow)
|
||||||
shows = append(shows, show)
|
shows = append(shows, show)
|
||||||
}
|
}
|
||||||
return shows, nil
|
return shows, nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user