Merge branch 'master' of github.com:r888888888/danbooru

This commit is contained in:
Toks
2015-11-26 19:36:23 -05:00
14 changed files with 215 additions and 30 deletions

View File

@@ -101,6 +101,21 @@ class PostQueryBuilder
relation
end
def add_saved_search_relation(saved_searches, relation)
saved_searches.each do |saved_search|
if saved_search == "all"
post_ids = SavedSearch.post_ids(CurrentUser.id)
else
post_ids = SavedSearch.post_ids(CurrentUser.id, saved_search)
end
post_ids = [0] if post_ids.empty?
relation = relation.where(["posts.id IN (?)", post_ids])
end
relation
end
def build(relation = nil)
unless query_string.is_a?(Hash)
q = Tag.parse_query(query_string)
@@ -208,6 +223,11 @@ class PostQueryBuilder
has_constraints!
end
if q[:saved_searches]
relation = add_saved_search_relation(q[:saved_searches], relation)
has_constraints!
end
if q[:uploader_id_neg]
relation = relation.where("posts.uploader_id not in (?)", q[:uploader_id_neg])
end

View File

@@ -3,11 +3,13 @@ class SavedSearch < ActiveRecord::Base
extend ActiveSupport::Concern
module ClassMethods
def refresh_listbooru(user_id, name)
def refresh_listbooru(user_id)
return unless Danbooru.config.listbooru_auth_key
user = User.find(user_id)
return unless user.is_gold?
params = {
:user_id => user_id,
:name => name,
:key => Danbooru.config.listbooru_auth_key
}
uri = URI.parse("#{Danbooru.config.listbooru_server}/users")
@@ -87,7 +89,27 @@ class SavedSearch < ActiveRecord::Base
Tag.scan_query(tag_query).join(" ")
end
def self.post_ids(user_id, name = nil)
params = {
"key" => Danbooru.config.listbooru_auth_key,
"user_id" => user_id,
"name" => name
}
uri = URI.parse("#{Danbooru.config.listbooru_server}/users")
uri.query = URI.encode_www_form(params)
Net::HTTP.start(uri.host, uri.port) do |http|
resp = http.request_get(uri.request_uri)
if resp.is_a?(Net::HTTPSuccess)
resp.body.scan(/\d+/).map(&:to_i)
else
raise "HTTP error code: #{resp.code} #{resp.message}"
end
end
end
def normalize
self.category = category.strip.gsub(/\s+/, "_").downcase if category
self.tag_query = SavedSearch.normalize(tag_query)
end
@@ -108,23 +130,4 @@ class SavedSearch < ActiveRecord::Base
user.update_attribute(:has_saved_searches, false)
end
end
def post_ids
params = {
"key" => Danbooru.config.listbooru_auth_key,
"user_id" => user_id,
"name" => category
}
uri = URI.parse("#{Danbooru.config.listbooru_server}/users")
uri.query = URI.encode_www_form(params)
Net::HTTP.start(uri.host, uri.port) do |http|
resp = http.request_get(uri.request_uri)
if resp.is_a?(Net::HTTPSuccess)
resp.body.scan(/\d+/)
else
raise "HTTP error code: #{resp.code} #{resp.message}"
end
end
end
end

View File

@@ -1,5 +1,5 @@
class Tag < ActiveRecord::Base
METATAGS = "-user|user|-approver|approver|commenter|comm|noter|noteupdater|artcomm|-pool|pool|ordpool|-favgroup|favgroup|-fav|fav|ordfav|sub|md5|-rating|rating|-locked|locked|width|height|mpixels|ratio|score|favcount|filesize|source|-source|id|-id|date|age|order|limit|-status|status|tagcount|gentags|arttags|chartags|copytags|parent|-parent|child|pixiv_id|pixiv"
METATAGS = "-user|user|-approver|approver|commenter|comm|noter|noteupdater|artcomm|-pool|pool|ordpool|-favgroup|favgroup|-fav|fav|ordfav|sub|md5|-rating|rating|-locked|locked|width|height|mpixels|ratio|score|favcount|filesize|source|-source|id|-id|date|age|order|limit|-status|status|tagcount|gentags|arttags|chartags|copytags|parent|-parent|child|pixiv_id|pixiv|search"
SUBQUERY_METATAGS = "commenter|comm|noter|noteupdater|artcomm"
attr_accessible :category, :as => [:moderator, :janitor, :gold, :member, :anonymous, :default, :builder, :admin]
attr_accessible :is_locked, :as => [:moderator, :admin]
@@ -493,6 +493,10 @@ class Tag < ActiveRecord::Base
q[:subscriptions] ||= []
q[:subscriptions] << $2
when "search"
q[:saved_searches] ||= []
q[:saved_searches] << $2
when "md5"
q[:md5] = $2.downcase.split(/,/)

View File

@@ -460,10 +460,8 @@ class User < ActiveRecord::Base
def max_saved_searches
if is_platinum?
1_000
elsif is_gold?
200
else
100
250
end
end

View File

@@ -0,0 +1,6 @@
<% content_for(:secondary_links) do %>
<menu>
<li><%= link_to "Gallery", posts_path(:tags => "search:all") %></li>
<li><%= link_to "Listing", saved_searches_path %></li>
</menu>
<% end %>

View File

@@ -12,7 +12,7 @@
</div>
</div>
<%= render "users/secondary_links" %>
<%= render "secondary_links" %>
<% content_for(:page_title) do %>
Edit Saved Search - <%= Danbooru.config.app_name %>

View File

@@ -3,7 +3,13 @@
<h1>Saved Searches</h1>
<% @categories.each do |category, saved_searches| %>
<h2><%= category.present? ? category : "Uncategorized" %></h2>
<h2>
<% if category.present? %>
<%= link_to category.tr("_", " "), posts_path(:tags => "search:#{category}") %>
<% else %>
Uncategorized
<% end %>
</h2>
<table class="striped" width="100%">
<thead>
<tr>
@@ -17,7 +23,8 @@
<tr id="saved-search-<%= saved_search.id %>">
<td><%= link_to saved_search.tag_query, posts_path(:tags => saved_search.tag_query) %></td>
<td>
<%= link_to "delete", saved_search_path(saved_search), :method => :delete, :remote => true %>
<%= link_to "edit", edit_saved_search_path(saved_search) %>
| <%= link_to "delete", saved_search_path(saved_search), :method => :delete, :remote => true %>
</td>
</tr>
<% end %>
@@ -27,7 +34,7 @@
</div>
</div>
<%= render "users/secondary_links" %>
<%= render "secondary_links" %>
<% content_for(:page_title) do %>
Saved Searches - <%= Danbooru.config.app_name %>