From d924964b3639d9f74bcb425d2ef90a622b2c679e Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Sat, 20 Jan 2018 15:54:30 -0500 Subject: [PATCH] Make thumbnails host configurable --- README.md | 1 + config.go | 7 ++++--- construction.go | 2 +- models.go | 17 +++++++++-------- templates/browse.html | 2 +- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index a92bc3a..1050ad1 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ DB_USER=dbuser DB_PASSWORD=pass DB_DB=htmlhouse PRIVATE_KEY=keys/dev PUBLIC_KEY= | `PORT` | Port to run app on | `8080` | | `STATIC_DIR` | Relative dir where static files are stored | `static` | | `AUTO_APPROVE` | Automatically approves public posts | false | +| `PREVIEWS_HOST` | Fully-qualified URL (without trailing slash) of screenshot server | None. | | `TWITTER_KEY` | Twitter consumer key | `notreal` | | `TWITTER_SECRET` | Twitter consumer secret | `notreal` | | `TWITTER_TOKEN` | Twitter access token of the posting Twitter account | `notreal` | diff --git a/config.go b/config.go index 0827736..41e64b5 100644 --- a/config.go +++ b/config.go @@ -18,9 +18,10 @@ type config struct { HostName string `env:"key=HOST default=https://html.house"` ServerPort int `env:"key=PORT default=8080"` - AutoApprove bool `env:"key=AUTO_APPROVE default=false"` - AdminPass string `env:"key=ADMIN_PASS default=uhoh"` - BrowseItems int `env:"key=BROWSE_ITEMS default=10"` + AutoApprove bool `env:"key=AUTO_APPROVE default=false"` + PreviewsHost string `env:"key=PREVIEWS_HOST` + AdminPass string `env:"key=ADMIN_PASS default=uhoh"` + BrowseItems int `env:"key=BROWSE_ITEMS default=10"` // Twitter configuration TwitterConsumerKey string `env:"key=TWITTER_KEY default=notreal"` diff --git a/construction.go b/construction.go index d44d16c..9e6d69d 100644 --- a/construction.go +++ b/construction.go @@ -89,7 +89,7 @@ func addPublicAccess(app *app, houseID, html string) error { data := url.Values{} data.Set("url", fmt.Sprintf("%s/%s.html", app.cfg.HostName, houseID)) - u, err := url.ParseRequestURI("https://peeper.html.house") + u, err := url.ParseRequestURI(app.cfg.PreviewsHost) u.Path = "/" urlStr := fmt.Sprintf("%v", u) diff --git a/models.go b/models.go index d3c9e4e..ecc7eee 100644 --- a/models.go +++ b/models.go @@ -7,13 +7,14 @@ import ( type ( PublicHouse struct { - ID string `json:"id"` - Title string `json:"title"` - URL string `json:"url"` - ThumbURL string `json:"thumb_url"` - Created time.Time `json:"created"` - Updated time.Time `json:"updated"` - Views int `json:"views"` + ID string `json:"id"` + Title string `json:"title"` + URL string `json:"url"` + thumbHost string `json:"-"` + ThumbURL string `json:"thumb_url"` + Created time.Time `json:"created"` + Updated time.Time `json:"updated"` + Views int `json:"views"` } HouseStats struct { @@ -30,6 +31,6 @@ type ( func (h *PublicHouse) process(app *app) { h.URL = fmt.Sprintf("%s/%s.html", app.cfg.HostName, h.ID) if h.ThumbURL != "" { - h.ThumbURL = "https://peeper.html.house/" + h.ThumbURL + h.ThumbURL = fmt.Sprintf("%s/%s", app.cfg.PreviewsHost, h.ThumbURL) } } diff --git a/templates/browse.html b/templates/browse.html index b23cf9a..aaad09f 100644 --- a/templates/browse.html +++ b/templates/browse.html @@ -39,7 +39,7 @@ {{ range .Houses }}
- +
{{.Title}}
{{end}}