Merge branch 'imgURL' into 'master'

Add the image URL prefix in the configuration

See merge request !64
This commit is contained in:
Lucas 2017-05-05 11:27:49 +00:00
commit d7c1d0a63a
9 changed files with 53 additions and 43 deletions

View File

@ -5,6 +5,8 @@ authorizer:
pgdsn: postgres://test:test@127.0.0.1:5432/dev?sslmode=disable pgdsn: postgres://test:test@127.0.0.1:5432/dev?sslmode=disable
listen_port: 3000 listen_port: 3000
public_dir: build/public public_dir: build/public
# default prefix, will be served by the go http server
img_url_prefix: img/
movie: movie:
detailers: detailers:

View File

@ -17,6 +17,7 @@ type Config struct {
PGDSN string `yaml:"pgdsn"` PGDSN string `yaml:"pgdsn"`
Port string `yaml:"listen_port"` Port string `yaml:"listen_port"`
PublicDir string `yaml:"public_dir"` PublicDir string `yaml:"public_dir"`
ImgURLPrefix string `yaml:"img_url_prefix"`
MovieExplorers []polochon.Explorer MovieExplorers []polochon.Explorer
MovieDetailers []polochon.Detailer MovieDetailers []polochon.Detailer

View File

@ -116,7 +116,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) show := shows.New(id, env.Config.PublicDir, env.Config.ImgURLPrefix)
// Refresh the shows // Refresh the shows
err := show.Refresh(env, env.Config.ShowDetailers) err := show.Refresh(env, env.Config.ShowDetailers)
if err != nil { if err != nil {
@ -161,7 +161,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(id, nil, nil, false, env.Config.PublicDir) movie := movies.New(id, nil, nil, false, env.Config.PublicDir, env.Config.ImgURLPrefix)
// Refresh the movie // Refresh the movie
err := movie.Refresh(env, env.Config.MovieDetailers) err := movie.Refresh(env, env.Config.MovieDetailers)
if err != nil { if err != nil {

View File

@ -83,7 +83,7 @@ func GetMovies(env *web.Env, user *users.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(id, client, pMovie, moviesWishlist.IsMovieInWishlist(id), env.Config.PublicDir) movie := movies.New(id, client, pMovie, moviesWishlist.IsMovieInWishlist(id), env.Config.PublicDir, env.Config.ImgURLPrefix)
// 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
@ -144,7 +144,7 @@ func GetShows(env *web.Env, user *users.User, source string, category string, fo
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(id, client, pShow, wShow, env.Config.PublicDir) show := shows.NewWithClient(id, client, pShow, wShow, env.Config.PublicDir, env.Config.ImgURLPrefix)
// First check in the DB // First check in the DB
before := []polochon.Detailer{env.Backend.Detailer} before := []polochon.Detailer{env.Backend.Detailer}

View File

@ -87,7 +87,7 @@ func RefreshMovieHandler(env *web.Env, w http.ResponseWriter, r *http.Request) e
} }
// Create a new movie // Create a new movie
m := New(id, client, pMovie, isWishlisted, env.Config.PublicDir) m := New(id, client, pMovie, isWishlisted, env.Config.PublicDir, env.Config.ImgURLPrefix)
// Refresh the movie's infos // Refresh the movie's infos
if err := m.Refresh(env, env.Config.MovieDetailers); err != nil { if err := m.Refresh(env, env.Config.MovieDetailers); err != nil {
@ -163,6 +163,7 @@ func SearchMovie(env *web.Env, w http.ResponseWriter, r *http.Request) error {
pMovie, pMovie,
moviesWishlist.IsMovieInWishlist(m.ImdbID), moviesWishlist.IsMovieInWishlist(m.ImdbID),
env.Config.PublicDir, env.Config.PublicDir,
env.Config.ImgURLPrefix,
) )
// First check in the DB // First check in the DB
@ -289,6 +290,7 @@ func GetWishlistHandler(env *web.Env, w http.ResponseWriter, r *http.Request) er
pMovie, pMovie,
moviesWishlist.IsMovieInWishlist(imdbID), moviesWishlist.IsMovieInWishlist(imdbID),
env.Config.PublicDir, env.Config.PublicDir,
env.Config.ImgURLPrefix,
) )
// First check in the DB // First check in the DB
before := []polochon.Detailer{env.Backend.Detailer} before := []polochon.Detailer{env.Backend.Detailer}

View File

@ -22,6 +22,7 @@ type Movie struct {
client *papi.Client client *papi.Client
pMovie *papi.Movie pMovie *papi.Movie
publicDir string publicDir string
imgURLPrefix string
Wishlisted bool `json:"wishlisted"` Wishlisted bool `json:"wishlisted"`
} }
@ -50,11 +51,12 @@ 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(imdbID string, client *papi.Client, pMovie *papi.Movie, isWishlisted bool, publicDir string) *Movie { func New(imdbID string, client *papi.Client, pMovie *papi.Movie, isWishlisted bool, publicDir, imgURLPrefix string) *Movie {
return &Movie{ return &Movie{
client: client, client: client,
pMovie: pMovie, pMovie: pMovie,
publicDir: publicDir, publicDir: publicDir,
imgURLPrefix: imgURLPrefix,
Wishlisted: isWishlisted, Wishlisted: isWishlisted,
Movie: &polochon.Movie{ Movie: &polochon.Movie{
ImdbID: imdbID, ImdbID: imdbID,
@ -205,12 +207,12 @@ func (m *Movie) RefreshTorrents(env *web.Env, torrenters []polochon.Torrenter) e
// imgURL returns the default image url // imgURL returns the default image url
func (m *Movie) imgURL() string { func (m *Movie) imgURL() string {
return fmt.Sprintf("img/movies/%s.jpg", m.ImdbID) return fmt.Sprintf("movies/%s.jpg", m.ImdbID)
} }
// 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, m.imgURL()) return filepath.Join(m.publicDir, "img", m.imgURL())
} }
// PosterURL returns the image URL or the default image if the poster is not yet downloaded // PosterURL returns the image URL or the default image if the poster is not yet downloaded
@ -218,9 +220,9 @@ func (m *Movie) PosterURL() string {
// Check if the movie image exists // Check if the movie image exists
if _, err := os.Stat(m.imgFile()); os.IsNotExist(err) { if _, err := os.Stat(m.imgFile()); os.IsNotExist(err) {
// TODO image in the config ? // TODO image in the config ?
return "img/noimage.png" return m.imgURLPrefix + "noimage.png"
} }
return m.imgURL() return m.imgURLPrefix + m.imgURL()
} }
// getPolochonMovies returns an array of the user's polochon movies // getPolochonMovies returns an array of the user's polochon movies
@ -253,6 +255,7 @@ func getPolochonMovies(user *users.User, env *web.Env) ([]*Movie, error) {
pmovie, pmovie,
moviesWishlist.IsMovieInWishlist(pmovie.ImdbID), moviesWishlist.IsMovieInWishlist(pmovie.ImdbID),
env.Config.PublicDir, env.Config.PublicDir,
env.Config.ImgURLPrefix,
) )
movies = append(movies, movie) movies = append(movies, movie)
} }

View File

@ -48,7 +48,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(id, client, pShow, wShow, env.Config.PublicDir) s := NewWithClient(id, client, pShow, wShow, env.Config.PublicDir, env.Config.ImgURLPrefix)
// 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
@ -98,7 +98,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(id, client, pShow, wShow, env.Config.PublicDir) s := NewWithClient(id, client, pShow, wShow, env.Config.PublicDir, env.Config.ImgURLPrefix)
// Refresh the polochon detailers // Refresh the polochon detailers
detailers := env.Config.ShowDetailers detailers := env.Config.ShowDetailers
err = s.Refresh(env, detailers) err = s.Refresh(env, detailers)
@ -177,7 +177,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.ImdbID, client, pShow, wShow, env.Config.PublicDir) show := NewWithClient(s.ImdbID, client, pShow, wShow, env.Config.PublicDir, env.Config.ImgURLPrefix)
// First try from the db // First try from the db
first := []polochon.Detailer{env.Backend.Detailer} first := []polochon.Detailer{env.Backend.Detailer}
@ -268,7 +268,7 @@ func GetWishlistHandler(env *web.Env, w http.ResponseWriter, r *http.Request) er
showList := []*Show{} showList := []*Show{}
for _, wishedShow := range wShows.List() { for _, wishedShow := range wShows.List() {
pShow, _ := pShows.Has(wishedShow.ImdbID) pShow, _ := pShows.Has(wishedShow.ImdbID)
show := NewWithClient(wishedShow.ImdbID, client, pShow, wishedShow, env.Config.PublicDir) show := NewWithClient(wishedShow.ImdbID, client, pShow, wishedShow, env.Config.PublicDir, env.Config.ImgURLPrefix)
// First check in the DB // First check in the DB
before := []polochon.Detailer{env.Backend.Detailer} before := []polochon.Detailer{env.Backend.Detailer}

View File

@ -24,6 +24,7 @@ type Show struct {
TrackedSeason *int `json:"tracked_season"` TrackedSeason *int `json:"tracked_season"`
TrackedEpisode *int `json:"tracked_episode"` TrackedEpisode *int `json:"tracked_episode"`
publicDir string publicDir string
imgURLPrefix string
} }
// MarshalJSON implements the Marshal interface // MarshalJSON implements the Marshal interface
@ -56,17 +57,18 @@ 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 string) *Show { func New(imdbID string, publicDir, imgURLPrefix string) *Show {
return &Show{ return &Show{
Show: &polochon.Show{ Show: &polochon.Show{
ImdbID: imdbID, ImdbID: imdbID,
}, },
publicDir: publicDir, publicDir: publicDir,
imgURLPrefix: imgURLPrefix,
} }
} }
// NewWithClient returns a new Show with a polochon ShowConfig // NewWithClient returns a new Show with a polochon ShowConfig
func NewWithClient(imdbID string, client *papi.Client, pShow *papi.Show, wShow *backend.WishedShow, publicDir string) *Show { func NewWithClient(imdbID string, client *papi.Client, pShow *papi.Show, wShow *backend.WishedShow, publicDir, imgURLPrefix string) *Show {
s := &Show{ s := &Show{
Show: &polochon.Show{ Show: &polochon.Show{
ImdbID: imdbID, ImdbID: imdbID,
@ -74,6 +76,7 @@ func NewWithClient(imdbID string, client *papi.Client, pShow *papi.Show, wShow *
client: client, client: client,
pShow: pShow, pShow: pShow,
publicDir: publicDir, publicDir: publicDir,
imgURLPrefix: imgURLPrefix,
} }
if wShow != nil { if wShow != nil {
s.TrackedSeason = &wShow.Season s.TrackedSeason = &wShow.Season
@ -153,9 +156,9 @@ func (s *Show) GetImageURL(imgType string) string {
// Check if the show image exists // Check if the show image exists
if _, err := os.Stat(s.imgFile(imgType)); os.IsNotExist(err) { if _, err := os.Stat(s.imgFile(imgType)); os.IsNotExist(err) {
// TODO image in the config ? // TODO image in the config ?
return "img/noimage.png" return s.imgURLPrefix + "noimage.png"
} }
return s.imgURL(imgType) return s.imgURLPrefix + s.imgURL(imgType)
} }
// downloadImages will download the show images // downloadImages will download the show images
@ -175,15 +178,14 @@ func (s *Show) downloadImages(env *web.Env) {
} }
} }
// imgFile returns the image location on disk
func (s *Show) imgFile(imgType string) string {
fileURL := fmt.Sprintf("img/shows/%s-%s.jpg", s.ImdbID, imgType)
return filepath.Join(s.publicDir, fileURL)
}
// imgURL returns the default image url // imgURL returns the default image url
func (s *Show) imgURL(imgType string) string { func (s *Show) imgURL(imgType string) string {
return fmt.Sprintf("img/shows/%s-%s.jpg", s.ImdbID, imgType) return fmt.Sprintf("shows/%s-%s.jpg", s.ImdbID, imgType)
}
// imgFile returns the image location on disk
func (s *Show) imgFile(imgType string) string {
return filepath.Join(s.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
@ -209,7 +211,7 @@ func getPolochonShows(env *web.Env, user *users.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(pShow.ImdbID, client, pShow, wShow, env.Config.PublicDir) show := NewWithClient(pShow.ImdbID, client, pShow, wShow, env.Config.PublicDir, env.Config.ImgURLPrefix)
shows = append(shows, show) shows = append(shows, show)
} }
return shows, nil return shows, nil

View File

@ -11,7 +11,7 @@ export default function ActionsButton(props) {
resourceId={props.movieId} resourceId={props.movieId}
getDetails={props.getDetails} getDetails={props.getDetails}
/> />
{(props.isUserAdmin && props.hasMovie) && {props.hasMovie &&
<DeleteButton <DeleteButton
resourceId={props.movieId} resourceId={props.movieId}
deleteFunc={props.deleteMovie} deleteFunc={props.deleteMovie}