Fix getting unsplash thumbnails for non "photo-*" urls
This commit is contained in:
parent
d8a6acda96
commit
d63666cece
2 changed files with 2 additions and 7 deletions
|
@ -72,5 +72,5 @@ func ProxyUnsplashThumb(c echo.Context) error {
|
||||||
return handler.HandleHTTPError(err, c)
|
return handler.HandleHTTPError(err, c)
|
||||||
}
|
}
|
||||||
pingbackByPhotoID(photo.ID)
|
pingbackByPhotoID(photo.ID)
|
||||||
return unsplashImage("https://images.unsplash.com/photo-"+getImageID(photo.Urls.Raw)+"?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=200&fit=max&ixid=eyJhcHBfaWQiOjcyODAwfQ", c)
|
return unsplashImage("https://images.unsplash.com/"+getImageID(photo.Urls.Raw)+"?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=200&fit=max&ixid=eyJhcHBfaWQiOjcyODAwfQ", c)
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,12 +114,7 @@ func getImageID(fullURL string) string {
|
||||||
// Unsplash image urls have the form
|
// Unsplash image urls have the form
|
||||||
// https://images.unsplash.com/photo-1590622878565-c662a7fd1394?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=200&fit=max&ixid=eyJhcHBfaWQiOjcyODAwfQ
|
// https://images.unsplash.com/photo-1590622878565-c662a7fd1394?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=200&fit=max&ixid=eyJhcHBfaWQiOjcyODAwfQ
|
||||||
// We only need the "photo-*" part of it.
|
// We only need the "photo-*" part of it.
|
||||||
parts := strings.Split(strings.Split(fullURL, "?")[0], "photo-")
|
return strings.Replace(strings.Split(fullURL, "?")[0], "https://images.unsplash.com/", "", 1)
|
||||||
if len(parts) < 2 {
|
|
||||||
log.Errorf("Unsplash thumb url does not contain enough parts [parts: %v]", parts)
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
return parts[1]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets an unsplash photo either from cache or directly from the unsplash api
|
// Gets an unsplash photo either from cache or directly from the unsplash api
|
||||||
|
|
Loading…
Reference in a new issue