/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) if resp.is_a?(Net::HTTPSuccess)
json = JSON.parse(resp.body) json = JSON.parse(resp.body)
if json.is_a?(Array) 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 else
@matches = [] @matches = []
end end

View File

@@ -1,7 +1,7 @@
var html = ''; var html = '';
<% if @results.any? %> <% if @results.any? %>
<% @results.each do |match| %> <% @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 %> <% end %>
<% else %> <% else %>
html += '<p>No matches found</p>'; html += '<p>No matches found</p>';

View File

@@ -1,7 +1,7 @@
<% if @results.any? %> <% if @results.any? %>
<h3>Similar</h3> <h3>Similar</h3>
<% @results.each do |match| %> <% @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 %> <% end %>
<% else %> <% else %>
<h3>Similar</h3> <h3>Similar</h3>