iqdb: update API client to use new version of IQDB.
Replace the old IQDB API client with a new client for the new forked version of IQDB at https://github.com/danbooru/iqdb. Changes: * The /iqdb_queries endpoint now returns `hash` and `signature` fields. The `signature` is the full decoded Haar signature, while the `hash` is a encoded version of the signature. * The /iqdb_queries endpoint no longer returns `width` and `height` fields in the response (these were always 128x128). * We no longer need the IQDBs frontend server, now we talk to the IQDB instance directly. * We no longer send add/remove image commands to IQDB through AWS SQS, now we send them to IQDB directly. They are sent in a delayed job so that if IQDB is down, uploading images is still possible, the add image commands will just get queued up. * Fix a bug where regenerating an image's thumbnails didn't regenerate IQDB, because IQDB silently ignored add image commands when the image already existed in the database.
This commit is contained in:
@@ -11,7 +11,7 @@ class IqdbQueriesControllerTest < ActionDispatch::IntegrationTest
|
||||
context "with a url parameter" do
|
||||
should "render a response" do
|
||||
@url = "https://google.com"
|
||||
@matches = [{ "post_id" => @post.id, "width" => 128, "height" => 128, "score" => 95.0 }]
|
||||
@matches = [{ post_id: @post.id, score: 95.0 }]
|
||||
mock_iqdb_matches(@matches)
|
||||
|
||||
get_auth iqdb_queries_path, @user, as: :javascript, params: { url: @url }
|
||||
@@ -22,10 +22,13 @@ class IqdbQueriesControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
context "with a post_id parameter" do
|
||||
should "redirect to iqdbs" do
|
||||
@matches = [{ "post_id" => @post.id, "width" => 128, "height" => 128, "score" => 95.0 }]
|
||||
should "render a response" do
|
||||
@matches = [{ post_id: @post.id, score: 95.0 }]
|
||||
mock_iqdb_matches(@matches)
|
||||
|
||||
# Make the call to `@post.file(:preview)` work.
|
||||
Post.any_instance.stubs(:file).returns(File.open("test/files/test.jpg"))
|
||||
|
||||
get_auth iqdb_queries_path, @user, params: { post_id: @post.id }
|
||||
|
||||
assert_response :success
|
||||
|
||||
@@ -15,7 +15,7 @@ class MockServicesControllerTest < ActionDispatch::IntegrationTest
|
||||
mock_reportbooru_missed_searches_path,
|
||||
mock_reportbooru_post_searches_path,
|
||||
mock_reportbooru_post_views_path,
|
||||
mock_iqdbs_similar_path,
|
||||
mock_iqdb_query_path,
|
||||
]
|
||||
|
||||
paths.each do |path|
|
||||
|
||||
@@ -6,6 +6,7 @@ class PostRegenerationsControllerTest < ActionDispatch::IntegrationTest
|
||||
@mod = create(:moderator_user, name: "yukari", created_at: 1.month.ago)
|
||||
@upload = assert_successful_upload("test/files/test.jpg", user: @mod)
|
||||
@post = @upload.post
|
||||
perform_enqueued_jobs # add post to iqdb
|
||||
end
|
||||
|
||||
context "create action" do
|
||||
@@ -23,9 +24,6 @@ class PostRegenerationsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "for an IQDB regeneration" do
|
||||
should "regenerate IQDB" do
|
||||
mock_iqdb_service!
|
||||
Post.iqdb_sqs_service.expects(:send_message).with("update\n#{@post.id}\n#{@post.preview_file_url}")
|
||||
|
||||
post_auth post_regenerations_path, @mod, params: { post_id: @post.id, category: "iqdb" }
|
||||
perform_enqueued_jobs
|
||||
end
|
||||
|
||||
@@ -4,7 +4,6 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "The uploads controller" do
|
||||
setup do
|
||||
@user = create(:contributor_user, name: "marisa")
|
||||
mock_iqdb_service!
|
||||
end
|
||||
|
||||
context "image proxy action" do
|
||||
|
||||
@@ -1,28 +1,6 @@
|
||||
module IqdbTestHelper
|
||||
def mock_iqdb_service!
|
||||
mock_sqs_service = Class.new do
|
||||
def initialize
|
||||
@commands = []
|
||||
end
|
||||
|
||||
def commands
|
||||
@commands
|
||||
end
|
||||
|
||||
def send_message(msg)
|
||||
@commands << msg.split(/\n/).first
|
||||
end
|
||||
end
|
||||
|
||||
service = mock_sqs_service.new
|
||||
Post.stubs(:iqdb_sqs_service).returns(service)
|
||||
Post.stubs(:iqdb_enabled?).returns(true)
|
||||
|
||||
Danbooru.config.stubs(:iqdbs_server).returns("http://localhost:3004")
|
||||
end
|
||||
|
||||
def mock_iqdb_matches(matches)
|
||||
Danbooru.config.stubs(:iqdbs_server).returns("http://localhost:3004")
|
||||
Danbooru.config.stubs(:iqdb_url).returns("http://localhost:5588")
|
||||
response = HTTP::Response.new(status: 200, body: matches.to_json, headers: { "Content-Type": "application/json" }, version: "1.1")
|
||||
HTTP::Client.any_instance.stubs(:post).returns(response)
|
||||
end
|
||||
|
||||
@@ -35,6 +35,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
@post = @upload.post
|
||||
Favorite.add(post: @post, user: @user)
|
||||
create(:favorite_group, post_ids: [@post.id])
|
||||
perform_enqueued_jobs # perform IqdbAddPostJob
|
||||
end
|
||||
|
||||
should "delete the files" do
|
||||
@@ -85,10 +86,9 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "remove the post from iqdb" do
|
||||
mock_iqdb_service!
|
||||
Post.iqdb_sqs_service.expects(:send_message).with("remove\n#{@post.id}")
|
||||
|
||||
@post.expunge!
|
||||
perform_enqueued_jobs
|
||||
assert_performed_jobs(1, only: IqdbRemovePostJob)
|
||||
end
|
||||
|
||||
context "that is status locked" do
|
||||
|
||||
Reference in New Issue
Block a user