uploads: show similar images for disk uploads.
Fix the upload page so that it shows similar images (IQDB matches) for files uploaded from your computer. Before this only worked for files uploaded from a source.
This commit is contained in:
@@ -5,7 +5,7 @@ class IqdbQueriesController < ApplicationController
|
|||||||
|
|
||||||
def show
|
def show
|
||||||
# XXX allow bare search params for backwards compatibility.
|
# XXX allow bare search params for backwards compatibility.
|
||||||
search_params.merge!(params.slice(:url, :hash, :image_url, :file_url, :post_id, :limit, :similarity, :high_similarity).permit!)
|
search_params.merge!(params.slice(:url, :hash, :image_url, :file_url, :post_id, :media_asset_id, :limit, :similarity, :high_similarity).permit!)
|
||||||
|
|
||||||
iqdb_params = search_params.to_h.symbolize_keys
|
iqdb_params = search_params.to_h.symbolize_keys
|
||||||
@high_similarity_matches, @low_similarity_matches, @matches = IqdbClient.new.search(**iqdb_params)
|
@high_similarity_matches, @low_similarity_matches, @matches = IqdbClient.new.search(**iqdb_params)
|
||||||
|
|||||||
@@ -26,18 +26,16 @@ Upload.initialize_all = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Upload.initialize_similar = function() {
|
Upload.initialize_similar = function() {
|
||||||
let source = $("#post_source").val();
|
let media_asset_id = $("input[name='post[media_asset_id]']").val();
|
||||||
|
|
||||||
if (/^https?:\/\//.test(source)) {
|
$.get("/iqdb_queries.js", {
|
||||||
$.get("/iqdb_queries.js", {
|
limit: Upload.IQDB_LIMIT,
|
||||||
limit: Upload.IQDB_LIMIT,
|
search: {
|
||||||
search: {
|
media_asset_id: media_asset_id,
|
||||||
url: source,
|
similarity: Upload.IQDB_MIN_SIMILARITY,
|
||||||
similarity: Upload.IQDB_MIN_SIMILARITY,
|
high_similarity: Upload.IQDB_HIGH_SIMILARITY
|
||||||
high_similarity: Upload.IQDB_HIGH_SIMILARITY
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Upload.initialize_image = function() {
|
Upload.initialize_image = function() {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class IqdbClient
|
|||||||
|
|
||||||
concerning :QueryMethods do
|
concerning :QueryMethods do
|
||||||
# Search for an image by file, URL, hash, or post ID.
|
# Search for an image by file, URL, hash, or post ID.
|
||||||
def search(post_id: nil, file: nil, hash: nil, url: nil, image_url: nil, file_url: nil, similarity: 0.0, high_similarity: 65.0, limit: 20)
|
def search(post_id: nil, media_asset_id: nil, file: nil, hash: nil, url: nil, image_url: nil, file_url: nil, similarity: 0.0, high_similarity: 65.0, limit: 20)
|
||||||
limit = limit.to_i.clamp(1, 1000)
|
limit = limit.to_i.clamp(1, 1000)
|
||||||
similarity = similarity.to_f.clamp(0.0, 100.0)
|
similarity = similarity.to_f.clamp(0.0, 100.0)
|
||||||
high_similarity = high_similarity.to_f.clamp(0.0, 100.0)
|
high_similarity = high_similarity.to_f.clamp(0.0, 100.0)
|
||||||
@@ -33,6 +33,8 @@ class IqdbClient
|
|||||||
file = download(file_url, :image_url)
|
file = download(file_url, :image_url)
|
||||||
elsif post_id.present?
|
elsif post_id.present?
|
||||||
file = Post.find(post_id).file(:preview)
|
file = Post.find(post_id).file(:preview)
|
||||||
|
elsif media_asset_id.present?
|
||||||
|
file = MediaAsset.find(media_asset_id).variant("360x360").open_file
|
||||||
end
|
end
|
||||||
|
|
||||||
if hash.present?
|
if hash.present?
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Upload < ApplicationRecord
|
class Upload < ApplicationRecord
|
||||||
|
extend Memoist
|
||||||
|
|
||||||
MAX_VIDEO_DURATION = 140
|
MAX_VIDEO_DURATION = 140
|
||||||
|
|
||||||
attr_accessor :file
|
attr_accessor :file
|
||||||
@@ -76,7 +78,14 @@ class Upload < ApplicationRecord
|
|||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def source_strategy
|
||||||
|
return nil if source.blank?
|
||||||
|
Sources::Strategies.find(source, referer_url)
|
||||||
|
end
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:uploader, :upload_media_assets, :media_assets]
|
[:uploader, :upload_media_assets, :media_assets]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
memoize :source_strategy
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -71,9 +71,9 @@ class PostPolicy < ApplicationPolicy
|
|||||||
end
|
end
|
||||||
|
|
||||||
def permitted_attributes_for_create
|
def permitted_attributes_for_create
|
||||||
%i[upload_media_asset_id tag_string rating parent_id source is_pending
|
%i[upload_id media_asset_id upload_media_asset_id tag_string rating
|
||||||
artist_commentary_desc artist_commentary_title translated_commentary_desc
|
parent_id source is_pending artist_commentary_desc artist_commentary_title
|
||||||
translated_commentary_title]
|
translated_commentary_desc translated_commentary_title]
|
||||||
end
|
end
|
||||||
|
|
||||||
def permitted_attributes_for_update
|
def permitted_attributes_for_update
|
||||||
|
|||||||
@@ -16,12 +16,4 @@
|
|||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if Danbooru.config.iqdb_url %>
|
<div class="input" id="iqdb-similar" style="display: none;"></div>
|
||||||
<% if params[:url] %>
|
|
||||||
<div class="input" id="iqdb-similar">
|
|
||||||
<p><em>Loading similar...</em></p>
|
|
||||||
</div>
|
|
||||||
<% else %>
|
|
||||||
<div class="input" id="iqdb-similar" style="display: none;"></div>
|
|
||||||
<% end %>
|
|
||||||
<% end %>
|
|
||||||
|
|||||||
@@ -45,13 +45,15 @@
|
|||||||
<%= tag.img src: @media_asset.variant("original").file_url, title: "Preview", id: "image", class: "fit-width fit-height", "data-shortcut": "z" %>
|
<%= tag.img src: @media_asset.variant("original").file_url, title: "Preview", id: "image", class: "fit-width fit-height", "data-shortcut": "z" %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% if @upload.source.present? %>
|
<%= render "uploads/related_posts", source: @upload.source_strategy %>
|
||||||
<% @source = ::Sources::Strategies.find(@upload.source, @upload.referer_url) %>
|
|
||||||
<%= render "uploads/related_posts", source: @source %>
|
<% if @upload.source_strategy.present? %>
|
||||||
<%= render_source_data(@source) %>
|
<%= render_source_data(@upload.source_strategy) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= edit_form_for(@post, html: { id: "form" }) do |f| %>
|
<%= edit_form_for(@post, html: { id: "form" }) do |f| %>
|
||||||
|
<%= f.input :upload_id, as: :hidden, input_html: { value: @upload.id } %>
|
||||||
|
<%= f.input :media_asset_id, as: :hidden, input_html: { value: @media_asset.id } %>
|
||||||
<%= f.input :upload_media_asset_id, as: :hidden, input_html: { value: @upload_media_asset.id } %>
|
<%= f.input :upload_media_asset_id, as: :hidden, input_html: { value: @upload_media_asset.id } %>
|
||||||
|
|
||||||
<%= f.input :source, as: :string %>
|
<%= f.input :source, as: :string %>
|
||||||
|
|||||||
Reference in New Issue
Block a user