fix iqdbproxy

This commit is contained in:
r888888888
2018-06-23 11:09:03 -07:00
parent 3ba5c6fb51
commit 8f2f418613
2 changed files with 10 additions and 6 deletions

View File

@@ -53,7 +53,7 @@ class CurrentUser
end
def self.root_url
Thread.current[:current_root_url] || "http://#{Danbooru.config.hostname}/"
Thread.current[:current_root_url] || "https://#{Danbooru.config.hostname}/"
end
def self.root_url=(root_url)

View File

@@ -1,18 +1,22 @@
class IqdbProxy
def self.query(url)
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: url}.to_query
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|
x["post"] = Post.find(x["id"])
x
end
begin
x["post"] = Post.find(x["id"])
x
rescue ActiveRecord::RecordNotFound
nil
end
end.compact
end
end