add iqdb preview

This commit is contained in:
Albert Yi
2018-06-22 15:56:15 -07:00
parent bf9750c826
commit 56b40a0255
7 changed files with 44 additions and 17 deletions

View File

@@ -154,7 +154,7 @@
Danbooru.Post.initialize_similar = function() {
$("#similar-button").click(function(e) {
$.post("/iqdb_queries", {"url": $("#post_source").val()}).done(function(html) {$("#iqdb-similar").html(html).show()});
$.get("/iqdb_queries/preview", {"url": $("#post_source").val()}).done(function(html) {$("#iqdb-similar").html(html).show()});
e.preventDefault();
});
}

View File

@@ -61,7 +61,7 @@
Danbooru.Upload.initialize_iqdb_source = function() {
if (/^https?:\/\//.test($("#normalized_url").val())) {
$.post("/iqdb_queries", {"url": $("#normalized_url").val()}).done(function(html) {$("#iqdb-similar").html(html)});
$.get("/iqdb_queries/preview", {"url": $("#normalized_url").val()}).done(function(html) {$("#iqdb-similar").html(html)});
}
}
@@ -77,7 +77,7 @@
Danbooru.Upload.initialize_similar = function() {
$("#similar-button").click(function(e) {
$.post("/iqdb_queries", {"url": $("#upload_source").val()}).done(function(html) {$("#iqdb-similar").html(html).show()});
$.get("/iqdb_queries/preview", {"url": $("#upload_source").val()}).done(function(html) {$("#iqdb-similar").html(html).show()});
e.preventDefault();
});
}

View File

@@ -138,24 +138,34 @@
article.post-preview {
margin: 0.5vw;
width: 32vw;
height: 32vw;
width: 48vw;
height: 48vw;
text-align: center;
vertical-align: middle;
display: inline-block;
&.cropped {
width: 32vw;
height: 32vw;
}
a {
//width: 48.5vw;
//display: block;
margin: 0 auto;
}
img.cropped {
img {
//object-fit: contain;
width: 32vw;
height: 32vw;
margin: 0 auto;
border: none !important;
&.cropped {
width: 32vw;
height: 32vw;
}
}
&[data-tags~=animated]:before, &[data-file-ext=swf]:before, &[data-file-ext=webm]:before, &[data-file-ext=mp4]:before, &[data-file-ext=zip]:before {
@include animated-icon;
}

View File

@@ -26,4 +26,12 @@ class IqdbQueriesController < ApplicationController
respond_with(@matches)
end
def preview
url = URI.parse(Danbooru.config.iqdbs_server)
url.path = "/similar"
url.query = {url: params[:url]}.to_query
@results = HTTParty.get(url.to_s).parsed_response
render layout: false
end
end

View File

@@ -21,8 +21,15 @@ class PostPresenter < Presenter
end
path = options[:path_prefix] || "/posts"
if CurrentUser.id == 1 && options[:show_cropped] && post.has_cropped? && !CurrentUser.user.disable_cropped_thumbnails?
src = post.crop_file_url
imgClass = "cropped"
else
src = post.preview_file_url
imgClass = nil
end
html = %{<article itemscope itemtype="http://schema.org/ImageObject" id="post_#{post.id}" class="#{preview_class(post, options[:pool], options)}" #{data_attributes(post)}>}
html = %{<article itemscope itemtype="http://schema.org/ImageObject" id="post_#{post.id}" class="#{imgClass} #{preview_class(post, options[:pool], options)}" #{data_attributes(post)}>}
if options[:tags].present? && !CurrentUser.is_anonymous?
tag_param = "?tags=#{CGI::escape(options[:tags])}"
elsif options[:pool_id] || options[:pool]
@@ -34,14 +41,6 @@ class PostPresenter < Presenter
end
html << %{<a href="#{path}/#{post.id}#{tag_param}">}
if CurrentUser.id == 1 && options[:show_cropped] && post.has_cropped? && !CurrentUser.user.disable_cropped_thumbnails?
src = post.crop_file_url
imgClass = "cropped"
else
src = post.preview_file_url
imgClass = nil
end
tooltip = "#{post.tag_string} rating:#{post.rating} score:#{post.score}"
html << %{<img class="#{imgClass}" itemprop="thumbnailUrl" src="#{src}" title="#{h(tooltip)}" alt="#{h(post.tag_string)}">}
html << %{</a>}

View File

@@ -0,0 +1,9 @@
<% if @results.any? %>
<h3>Similar</h3>
<% @results.each do |match| %>
<%= PostPresenter.preview(Post.find(match["post_id"]), :tags => "status:any", :similarity => match["score"]) %>
<% end %>
<% else %>
<h3>Similar</h3>
<p>No matches found</p>
<% end %>

View File

@@ -157,6 +157,7 @@ Rails.application.routes.draw do
resources :ip_bans
resource :iqdb_queries, :only => [:show] do
collection do
get :preview
get :check, to: redirect {|path_params, req| "/iqdb_queries?#{req.query_string}"}
end
end