added more legacy api endpoints
This commit is contained in:
@@ -97,4 +97,7 @@ class PostVersion < ActiveRecord::Base
|
||||
PostVersion.where("post_id = ? and id < ?", post_id, id).order("id desc").first
|
||||
end
|
||||
|
||||
def truncated_source
|
||||
source.gsub(/^http:\/\//, "").sub(/\/.+/, "")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,6 +3,19 @@ class Tag < ActiveRecord::Base
|
||||
after_save :update_category_cache
|
||||
has_one :wiki_page, :foreign_key => "name", :primary_key => "title"
|
||||
|
||||
module ApiMethods
|
||||
def to_legacy_json
|
||||
return {
|
||||
"name" => name,
|
||||
"id" => id,
|
||||
"created_at" => created_at.strftime("%Y-%m-%d %H:%M"),
|
||||
"count" => post_count,
|
||||
"type" => category,
|
||||
"ambiguous" => false
|
||||
}.to_json
|
||||
end
|
||||
end
|
||||
|
||||
class CategoryMapping
|
||||
Danbooru.config.reverse_tag_category_mapping.each do |value, category|
|
||||
define_method(category.downcase) do
|
||||
@@ -399,6 +412,7 @@ class Tag < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
include ApiMethods
|
||||
extend CountMethods
|
||||
extend ViewCountMethods
|
||||
include CategoryMethods
|
||||
|
||||
@@ -411,6 +411,15 @@ class User < ActiveRecord::Base
|
||||
options[:except] += hidden_attributes
|
||||
super(options, &block)
|
||||
end
|
||||
|
||||
def to_legacy_json
|
||||
return {
|
||||
"name" => name,
|
||||
"id" => id,
|
||||
"level" => level,
|
||||
"created_at" => created_at.strftime("%Y-%m-%d %H:%M")
|
||||
}.to_json
|
||||
end
|
||||
end
|
||||
|
||||
module SearchMethods
|
||||
@@ -446,6 +455,10 @@ class User < ActiveRecord::Base
|
||||
q = scoped
|
||||
return q if params.blank?
|
||||
|
||||
if params[:name]
|
||||
q = q.name_matches(params[:name])
|
||||
end
|
||||
|
||||
if params[:name_matches]
|
||||
q = q.name_matches(params[:name_matches])
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user