diff --git a/src/milia/utils/images.cljc b/src/milia/utils/images.cljc index 743515e3..a456902c 100644 --- a/src/milia/utils/images.cljc +++ b/src/milia/utils/images.cljc @@ -1,5 +1,6 @@ (ns milia.utils.images (:require [chimera.urls :refer [url]] + [clojure.string :refer [starts-with?]] [milia.utils.remote :refer [thumbor-server]])) (defn resize-image @@ -9,6 +10,11 @@ ([image-url width-px height-px] (resize-image image-url width-px height-px thumbor-server)) ([image-url width-px height-px image-server-url] - (str image-server-url - (url "unsafe" - (str width-px "x" height-px) "smart" image-url)))) + (let [thumbor-server-prefix (str image-server-url "/image/")] + (str image-server-url + (url + "unsafe" + (str width-px "x" height-px) "smart" + (if (starts-with? image-url thumbor-server-prefix) + (subs image-url (count thumbor-server-prefix)) + image-url)))))) diff --git a/test/clj/milia/utils/images_test.clj b/test/clj/milia/utils/images_test.clj index 16719fb8..a2b8b9e7 100644 --- a/test/clj/milia/utils/images_test.clj +++ b/test/clj/milia/utils/images_test.clj @@ -1,17 +1,27 @@ (ns milia.utils.images-test + #_{:clj-kondo/ignore [:refer-all]} (:require [midje.sweet :refer :all] - [milia.utils.images :refer :all])) + [milia.utils.images :refer [resize-image]])) -(facts "about resize-image" - (fact "should return with image-url and edge dimension" - (resize-image "s3.aws.org" 80) => - "https://images.ona.io/unsafe/80x80/smart/s3.aws.org") +(facts + "about resize-image" + (fact "should return with image-url and edge dimension" + (resize-image "s3.aws.org" 80) => + "https://images.ona.io/unsafe/80x80/smart/s3.aws.org") - (fact "should return with image-url, width and height dimension" - (resize-image "s3.aws.org" 80 56) - => "https://images.ona.io/unsafe/80x56/smart/s3.aws.org") + (fact "should return with image-url, width and height dimension" + (resize-image "s3.aws.org" 80 56) + => "https://images.ona.io/unsafe/80x56/smart/s3.aws.org") - (fact "should return with image-url, width and height dimension as well + (fact "should return with image-url, width and height dimension as well as optional image-server-url" - (resize-image "s3.aws.org" 80 56 "https://images.test.org") - => "https://images.test.org/unsafe/80x56/smart/s3.aws.org")) \ No newline at end of file + (resize-image "s3.aws.org" 80 56 "https://images.test.org") + => "https://images.test.org/unsafe/80x56/smart/s3.aws.org") + (fact + "Works with thumbor 7.5.0" + (resize-image + "https://images.test.org/image/some-hash/image-name.jpg" + 80 + 56 + "https://images.test.org") + => "https://images.test.org/unsafe/80x56/smart/some-hash/image-name.jpg"))