fix iqdbproxy
This commit is contained in:
@@ -53,7 +53,7 @@ class CurrentUser
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.root_url
|
def self.root_url
|
||||||
Thread.current[:current_root_url] || "http://#{Danbooru.config.hostname}/"
|
Thread.current[:current_root_url] || "https://#{Danbooru.config.hostname}/"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.root_url=(root_url)
|
def self.root_url=(root_url)
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
class IqdbProxy
|
class IqdbProxy
|
||||||
def self.query(url)
|
def self.query(image_url)
|
||||||
raise NotImplementedError unless Danbooru.config.iqdbs_server.present?
|
raise NotImplementedError unless Danbooru.config.iqdbs_server.present?
|
||||||
|
|
||||||
url = URI.parse(Danbooru.config.iqdbs_server)
|
url = URI.parse(Danbooru.config.iqdbs_server)
|
||||||
url.path = "/similar"
|
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
|
json = HTTParty.get(url.to_s, Danbooru.config.httparty_options).parsed_response
|
||||||
decorate_posts(json)
|
decorate_posts(json)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.decorate_posts(json)
|
def self.decorate_posts(json)
|
||||||
json.map do |x|
|
json.map do |x|
|
||||||
x["post"] = Post.find(x["id"])
|
begin
|
||||||
x
|
x["post"] = Post.find(x["id"])
|
||||||
end
|
x
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end.compact
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user