From 1c9014a5bbd20413448a901cce844ad8982b6c9d Mon Sep 17 00:00:00 2001 From: nonamethanks Date: Sat, 5 Feb 2022 09:43:17 +0100 Subject: [PATCH] Fix lofter not working with iqdb --- app/logical/sources/strategies/lofter.rb | 16 ++++++---------- test/unit/sources/lofter_test.rb | 3 ++- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/app/logical/sources/strategies/lofter.rb b/app/logical/sources/strategies/lofter.rb index 810afdd77..870c945a5 100644 --- a/app/logical/sources/strategies/lofter.rb +++ b/app/logical/sources/strategies/lofter.rb @@ -40,17 +40,13 @@ module Sources parsed_url.domain.in?(domains) || parsed_url.host =~ IMAGE_HOST end - def image_url - if url =~ IMAGE_HOST - get_full_version(url) - else - image_urls.first - end - end - def image_urls - images = page&.search(".imgclasstag img") - images.to_a.map { |img| get_full_version(img["src"]) } + if url =~ IMAGE_HOST + [get_full_version(url)] + else + images = page&.search(".imgclasstag img") + images.to_a.map { |img| get_full_version(img["src"]) } + end end def get_full_version(url) diff --git a/test/unit/sources/lofter_test.rb b/test/unit/sources/lofter_test.rb index eb71a7b49..17ae09bb9 100644 --- a/test/unit/sources/lofter_test.rb +++ b/test/unit/sources/lofter_test.rb @@ -7,6 +7,7 @@ module Sources @img = "https://imglf4.lf127.net/img/S1d2QlVsWkJhSW1qcnpIS0ZSa3ZJUFczb2RKSVlpMHJkNy9kc3BSQVQvQm5DNzB4eVhxay9nPT0.png?imageView&thumbnail=1680x0&quality=96&stripmeta=0" @ref = "https://gengar563.lofter.com/post/1e82da8c_1c98dae1b" @source = Sources::Strategies.find(@img, @ref) + @source2 = Sources::Strategies.find(@ref) end should "get the artist name" do @@ -31,7 +32,7 @@ module Sources https://imglf3.lf127.net/img/S1d2QlVsWkJhSW1qcnpIS0ZSa3ZJSzFCWFlnUWgzb01DcUdpT1lreG5yQjJVMkhGS09HNGR3PT0.png ] - assert_equal(images, @source.image_urls) + assert_equal(images, @source2.image_urls) end should "download the full-size image" do