From bdeb4b3501a1f32a1b515b076cace5cc6f3906d0 Mon Sep 17 00:00:00 2001 From: Earlopain Date: Sat, 2 Oct 2021 21:15:48 +0200 Subject: [PATCH] [IQDB] Remove dead code --- .env | 1 - app/logical/iqdb/download.rb | 47 --------------------------- config/danbooru_default_config.rb | 11 ------- test/test_helpers/iqdb_test_helper.rb | 1 - 4 files changed, 60 deletions(-) delete mode 100644 app/logical/iqdb/download.rb diff --git a/.env b/.env index 08f7601dc..8d352469e 100644 --- a/.env +++ b/.env @@ -78,7 +78,6 @@ # export DANBOORU_AWS_ACCESS_KEY_ID= # export DANBOORU_AWS_SECRET_ACCESS_KEY= # export DANBOORU_AWS_SQS_REGION= -# export DANBOORU_IQDBS_AUTH_KEY= # export DANBOORU_IQDBS_SERVER= # export DANBOORU_CLOUDFLARE_KEY= # export DANBOORU_CLOUDFLARE_EMAIL= diff --git a/app/logical/iqdb/download.rb b/app/logical/iqdb/download.rb deleted file mode 100644 index 200f17572..000000000 --- a/app/logical/iqdb/download.rb +++ /dev/null @@ -1,47 +0,0 @@ -module Iqdb - class Download - class Error < StandardError; end - - def self.enabled? - Danbooru.config.iqdbs_server.present? && Danbooru.config.iqdbs_auth_key.present? - end - - def self.get_referer(url) - headers = {} - datums = {} - - strategy = Sources::Strategies.find(url) - - [strategy.image_url, strategy.headers["Referer"]] - end - - def self.find_similar(source) - raise NotImplementedError, "the IQDBs service isn't configured. Similarity searches are not available." unless enabled? - - url, ref = get_referer(source) - params = { - "key" => Danbooru.config.iqdbs_auth_key, - "url" => url, - "ref" => ref - } - uri = URI.parse("#{Danbooru.config.iqdbs_server}/similar") - uri.query = URI.encode_www_form(params) - - resp = HTTParty.get(uri, Danbooru.config.httparty_options) - raise "HTTP error code: #{resp.code} #{resp.message}" unless resp.success? - - json = JSON.parse(resp.body) - raise "IQDB error: #{json["error"]}" unless json.is_a?(Array) - - post_ids = json.map { |match| match["post_id"] } - posts = Post.find(post_ids) - - json.map do |match| - post = posts.find { |post| post.id == match["post_id"] } - match.with_indifferent_access.merge({ post: post }) - end - rescue => e - raise Error, { message: e.message, iqdb_response: json } - end - end -end diff --git a/config/danbooru_default_config.rb b/config/danbooru_default_config.rb index e9329efe8..f0e68c542 100644 --- a/config/danbooru_default_config.rb +++ b/config/danbooru_default_config.rb @@ -118,13 +118,6 @@ fart' true end - # What method to use to store images. - # local_flat: Store every image in one directory. - # local_hierarchy: Store every image in a hierarchical directory, based on the post's MD5 hash. On some file systems this may be faster. - def image_store - :local_flat - end - # This allows using statically linked copies of ffmpeg in non default locations. Not universally supported across # the codebase at this time. def ffmpeg_path @@ -867,10 +860,6 @@ fart' false end - # iqdbs options - see https://github.com/r888888888/iqdbs - def iqdbs_auth_key - end - def iqdbs_server end diff --git a/test/test_helpers/iqdb_test_helper.rb b/test/test_helpers/iqdb_test_helper.rb index edd941f6e..1feeffabc 100644 --- a/test/test_helpers/iqdb_test_helper.rb +++ b/test/test_helpers/iqdb_test_helper.rb @@ -18,7 +18,6 @@ module IqdbTestHelper Post.stubs(:iqdb_sqs_service).returns(service) Post.stubs(:iqdb_enabled?).returns(true) - Danbooru.config.stubs(:iqdbs_auth_key).returns("hunter2") Danbooru.config.stubs(:iqdbs_server).returns("http://localhost:3004") end