Commit 24993284 authored by Petter Goksøyr Åsen's avatar Petter Goksøyr Åsen
Browse files

DEICH-0000 fix some forgotten TODOs in image-api

parent 2b7c09c1
......@@ -205,8 +205,11 @@ func (s *server) getResizedImage(w http.ResponseWriter, r *http.Request) {
staticImgUrl := ""
if bucket == "cover-images" {
idWithoutSuffix := id[:strings.LastIndex(id, ".")]
// TODO guard against len(idWithoutSuffix) < 4
staticImgUrl = fmt.Sprintf("https://static.deichman.no/images/%s/%s/full.jpg", idWithoutSuffix[len(idWithoutSuffix)-4:], idWithoutSuffix)
l := 4
if len(idWithoutSuffix) < 4 {
l = len(idWithoutSuffix)
}
staticImgUrl = fmt.Sprintf("https://static.deichman.no/images/%s/%s/full.jpg", idWithoutSuffix[len(idWithoutSuffix)-l:], idWithoutSuffix)
}
if res, err := http.Head(staticImgUrl); err == nil && res.StatusCode == http.StatusOK {
s.getStaticResizedImage(w, staticImgUrl, sizeInt)
......@@ -214,10 +217,7 @@ func (s *server) getResizedImage(w http.ResponseWriter, r *http.Request) {
} else if os.Getenv("FAILOVER_IMAGE_URL") != "" {
// For dev/test environments we set this environment variable, so that
// images are served from prod if not found locally
// TEMPORARY FIX: since image url now has bucket name prefixed, we need to
// undo that for prod to resolve. Remove once we migrate prod and deploy.
http.Redirect(w, r, fmt.Sprintf("%s/api/images/%s/resize/%d/%s", os.Getenv("FAILOVER_IMAGE_URL"), bucket, sizeInt, id), 302)
http.Redirect(w, r, fmt.Sprintf("%s/api/images/resize/%d/%s/%s", os.Getenv("FAILOVER_IMAGE_URL"), sizeInt, bucket, id), 302)
} else {
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment