/iqdb_queries: include full data for each post in api response.

This commit is contained in:
evazion
2017-04-05 17:26:15 -05:00
parent e15f955677
commit 423dd0b848
3 changed files with 9 additions and 3 deletions

View File

@@ -33,7 +33,13 @@ module Iqdb
if resp.is_a?(Net::HTTPSuccess)
json = JSON.parse(resp.body)
if json.is_a?(Array)
@matches = json
post_ids = json.map { |match| match["post_id"] }
posts = Post.find(post_ids)
@matches = json.map do |match|
post = posts.find { |post| post.id == match["post_id"] }
match.with_indifferent_access.merge({ post: post })
end
else
@matches = []
end

View File

@@ -1,7 +1,7 @@
var html = '';
<% if @results.any? %>
<% @results.each do |match| %>
html += '<%= j PostPresenter.preview(Post.find(match["post_id"]), :tags => "status:any") %>';
html += '<%= j PostPresenter.preview(match[:post], :tags => "status:any") %>';
<% end %>
<% else %>
html += '<p>No matches found</p>';

View File

@@ -1,7 +1,7 @@
<% if @results.any? %>
<h3>Similar</h3>
<% @results.each do |match| %>
<%= PostPresenter.preview(Post.find(match["post_id"]), :tags => "status:any", :size => true) %>
<%= PostPresenter.preview(match[:post], :tags => "status:any", :size => true) %>
<% end %>
<% else %>
<h3>Similar</h3>