hook in listbooru #2523
This commit is contained in:
@@ -5,6 +5,8 @@ class SavedSearch < ActiveRecord::Base
|
|||||||
attr_accessible :tag_query, :category
|
attr_accessible :tag_query, :category
|
||||||
before_create :update_user_on_create
|
before_create :update_user_on_create
|
||||||
after_destroy :update_user_on_destroy
|
after_destroy :update_user_on_destroy
|
||||||
|
before_create :update_listbooru_on_create
|
||||||
|
after_destroy :update_listbooru_on_destroy
|
||||||
validates_uniqueness_of :tag_query, :scope => :user_id
|
validates_uniqueness_of :tag_query, :scope => :user_id
|
||||||
before_validation :normalize
|
before_validation :normalize
|
||||||
|
|
||||||
@@ -37,4 +39,19 @@ class SavedSearch < ActiveRecord::Base
|
|||||||
user.update_attribute(:has_saved_searches, false)
|
user.update_attribute(:has_saved_searches, false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_listbooru_on_create
|
||||||
|
return unless Danbooru.config.listbooru_auth_key
|
||||||
|
Net::HTTP.post_form(Danbooru.config.listbooru_server, {"user_id" => user_id, "query" => tag_query, "key" => Danbooru.config.listbooru_auth_key})
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_listbooru_on_destroy
|
||||||
|
return unless Danbooru.config.listbooru_auth_key
|
||||||
|
uri = URI.parse(Danbooru.config.listbooru_server)
|
||||||
|
Net::HTTP.start(uri.host, uri.port) do |http|
|
||||||
|
req = Net::HTTP::Delete.new("/searches")
|
||||||
|
req.set_form_data("user_id" => user_id, "query" => tag_query, "key" => Danbooru.config.listbooru_auth_key)
|
||||||
|
http.request(req)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ class TagSubscription < ActiveRecord::Base
|
|||||||
before_validation :initialize_post_ids, :on => :create
|
before_validation :initialize_post_ids, :on => :create
|
||||||
before_save :normalize_name
|
before_save :normalize_name
|
||||||
before_save :limit_tag_count
|
before_save :limit_tag_count
|
||||||
|
before_create :update_listbooru_on_create
|
||||||
|
before_update :update_listbooru_on_update
|
||||||
|
after_destroy :update_listbooru_on_destroy
|
||||||
attr_accessible :name, :tag_query, :post_ids, :is_public, :is_visible_on_profile
|
attr_accessible :name, :tag_query, :post_ids, :is_public, :is_visible_on_profile
|
||||||
validates_presence_of :name, :tag_query, :creator_id
|
validates_presence_of :name, :tag_query, :creator_id
|
||||||
validate :validate_number_of_queries
|
validate :validate_number_of_queries
|
||||||
@@ -75,6 +78,26 @@ class TagSubscription < ActiveRecord::Base
|
|||||||
post_ids.split(/,/)
|
post_ids.split(/,/)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_listbooru_on_create
|
||||||
|
return unless Danbooru.config.listbooru_auth_key
|
||||||
|
Net::HTTP.post_form(Danbooru.config.listbooru_server, {"user_id" => user_id, "query" => tag_query, "name" => "sub:#{id}", "key" => Danbooru.config.listbooru_auth_key})
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_listbooru_on_update
|
||||||
|
update_listbooru_on_destroy
|
||||||
|
update_listbooru_on_create
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_listbooru_on_destroy
|
||||||
|
return unless Danbooru.config.listbooru_auth_key
|
||||||
|
uri = URI.parse(Danbooru.config.listbooru_server)
|
||||||
|
Net::HTTP.start(uri.host, uri.port) do |http|
|
||||||
|
req = Net::HTTP::Delete.new("/searches")
|
||||||
|
req.set_form_data("user_id" => user_id, "query" => tag_query, "key" => Danbooru.config.listbooru_auth_key, "name" => "sub:#{id}")
|
||||||
|
http.request(req)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
module SearchMethods
|
module SearchMethods
|
||||||
def visible_to(user)
|
def visible_to(user)
|
||||||
where("(is_public = TRUE OR creator_id = ? OR ?)", user.id, user.is_moderator?)
|
where("(is_public = TRUE OR creator_id = ? OR ?)", user.id, user.is_moderator?)
|
||||||
|
|||||||
@@ -404,5 +404,13 @@ module Danbooru
|
|||||||
def addthis_key
|
def addthis_key
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def listbooru_server
|
||||||
|
"http://miura.donmai.us"
|
||||||
|
end
|
||||||
|
|
||||||
|
def listbooru_auth_key
|
||||||
|
ENV["LISTBOORU_AUTH_KEY"]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user