add iqdb preview
This commit is contained in:
@@ -154,7 +154,7 @@
|
|||||||
|
|
||||||
Danbooru.Post.initialize_similar = function() {
|
Danbooru.Post.initialize_similar = function() {
|
||||||
$("#similar-button").click(function(e) {
|
$("#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();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@
|
|||||||
|
|
||||||
Danbooru.Upload.initialize_iqdb_source = function() {
|
Danbooru.Upload.initialize_iqdb_source = function() {
|
||||||
if (/^https?:\/\//.test($("#normalized_url").val())) {
|
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() {
|
Danbooru.Upload.initialize_similar = function() {
|
||||||
$("#similar-button").click(function(e) {
|
$("#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();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,24 +138,34 @@
|
|||||||
|
|
||||||
article.post-preview {
|
article.post-preview {
|
||||||
margin: 0.5vw;
|
margin: 0.5vw;
|
||||||
width: 32vw;
|
width: 48vw;
|
||||||
height: 32vw;
|
height: 48vw;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
|
||||||
|
&.cropped {
|
||||||
|
width: 32vw;
|
||||||
|
height: 32vw;
|
||||||
|
}
|
||||||
|
|
||||||
a {
|
a {
|
||||||
//width: 48.5vw;
|
//width: 48.5vw;
|
||||||
//display: block;
|
//display: block;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
}
|
}
|
||||||
img.cropped {
|
|
||||||
|
img {
|
||||||
//object-fit: contain;
|
//object-fit: contain;
|
||||||
width: 32vw;
|
|
||||||
height: 32vw;
|
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
border: none !important;
|
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 {
|
&[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;
|
@include animated-icon;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,4 +26,12 @@ class IqdbQueriesController < ApplicationController
|
|||||||
|
|
||||||
respond_with(@matches)
|
respond_with(@matches)
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -21,8 +21,15 @@ class PostPresenter < Presenter
|
|||||||
end
|
end
|
||||||
|
|
||||||
path = options[:path_prefix] || "/posts"
|
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?
|
if options[:tags].present? && !CurrentUser.is_anonymous?
|
||||||
tag_param = "?tags=#{CGI::escape(options[:tags])}"
|
tag_param = "?tags=#{CGI::escape(options[:tags])}"
|
||||||
elsif options[:pool_id] || options[:pool]
|
elsif options[:pool_id] || options[:pool]
|
||||||
@@ -34,14 +41,6 @@ class PostPresenter < Presenter
|
|||||||
end
|
end
|
||||||
html << %{<a href="#{path}/#{post.id}#{tag_param}">}
|
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}"
|
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 << %{<img class="#{imgClass}" itemprop="thumbnailUrl" src="#{src}" title="#{h(tooltip)}" alt="#{h(post.tag_string)}">}
|
||||||
html << %{</a>}
|
html << %{</a>}
|
||||||
|
|||||||
9
app/views/iqdb_queries/preview.html.erb
Normal file
9
app/views/iqdb_queries/preview.html.erb
Normal 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 %>
|
||||||
@@ -157,6 +157,7 @@ Rails.application.routes.draw do
|
|||||||
resources :ip_bans
|
resources :ip_bans
|
||||||
resource :iqdb_queries, :only => [:show] do
|
resource :iqdb_queries, :only => [:show] do
|
||||||
collection do
|
collection do
|
||||||
|
get :preview
|
||||||
get :check, to: redirect {|path_params, req| "/iqdb_queries?#{req.query_string}"}
|
get :check, to: redirect {|path_params, req| "/iqdb_queries?#{req.query_string}"}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user