Files
danbooru/app/logical/iqdb_proxy.rb
r888888888 62235e215e iqdb fixes
2018-06-23 11:15:14 -07:00

23 lines
562 B
Ruby

class IqdbProxy
def self.query(image_url)
raise NotImplementedError unless Danbooru.config.iqdbs_server.present?
url = URI.parse(Danbooru.config.iqdbs_server)
url.path = "/similar"
url.query = {url: image_url}.to_query
json = HTTParty.get(url.to_s, Danbooru.config.httparty_options).parsed_response
decorate_posts(json)
end
def self.decorate_posts(json)
json.map do |x|
begin
x["post"] = Post.find(x["post_id"])
x
rescue ActiveRecord::RecordNotFound
nil
end
end.compact
end
end