added more legacy api endpoints
This commit is contained in:
@@ -171,12 +171,14 @@ div#c-post-versions {
|
|||||||
color: green;
|
color: green;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
margin-right: 0.5em;
|
margin-right: 0.5em;
|
||||||
|
word-wrap: break-word
|
||||||
}
|
}
|
||||||
|
|
||||||
del, del a {
|
del, del a {
|
||||||
color: red;
|
color: red;
|
||||||
text-decoration: line-through;
|
text-decoration: line-through;
|
||||||
margin-right: 0.5em;
|
margin-right: 0.5em;
|
||||||
|
word-wrap: break-word
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,14 @@ class LegacyController < ApplicationController
|
|||||||
@post_set = PostSets::Post.new(tag_query, params[:page], params[:limit])
|
@post_set = PostSets::Post.new(tag_query, params[:page], params[:limit])
|
||||||
@posts = @post_set.posts
|
@posts = @post_set.posts
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def users
|
||||||
|
@users = User.search(params).limit(100)
|
||||||
|
end
|
||||||
|
|
||||||
|
def tags
|
||||||
|
@tags = Tag.search(params).limit(100)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def tag_query
|
def tag_query
|
||||||
|
|||||||
@@ -97,4 +97,7 @@ class PostVersion < ActiveRecord::Base
|
|||||||
PostVersion.where("post_id = ? and id < ?", post_id, id).order("id desc").first
|
PostVersion.where("post_id = ? and id < ?", post_id, id).order("id desc").first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def truncated_source
|
||||||
|
source.gsub(/^http:\/\//, "").sub(/\/.+/, "")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,6 +3,19 @@ class Tag < ActiveRecord::Base
|
|||||||
after_save :update_category_cache
|
after_save :update_category_cache
|
||||||
has_one :wiki_page, :foreign_key => "name", :primary_key => "title"
|
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
|
class CategoryMapping
|
||||||
Danbooru.config.reverse_tag_category_mapping.each do |value, category|
|
Danbooru.config.reverse_tag_category_mapping.each do |value, category|
|
||||||
define_method(category.downcase) do
|
define_method(category.downcase) do
|
||||||
@@ -399,6 +412,7 @@ class Tag < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
include ApiMethods
|
||||||
extend CountMethods
|
extend CountMethods
|
||||||
extend ViewCountMethods
|
extend ViewCountMethods
|
||||||
include CategoryMethods
|
include CategoryMethods
|
||||||
|
|||||||
@@ -411,6 +411,15 @@ class User < ActiveRecord::Base
|
|||||||
options[:except] += hidden_attributes
|
options[:except] += hidden_attributes
|
||||||
super(options, &block)
|
super(options, &block)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
module SearchMethods
|
module SearchMethods
|
||||||
@@ -446,6 +455,10 @@ class User < ActiveRecord::Base
|
|||||||
q = scoped
|
q = scoped
|
||||||
return q if params.blank?
|
return q if params.blank?
|
||||||
|
|
||||||
|
if params[:name]
|
||||||
|
q = q.name_matches(params[:name])
|
||||||
|
end
|
||||||
|
|
||||||
if params[:name_matches]
|
if params[:name_matches]
|
||||||
q = q.name_matches(params[:name_matches])
|
q = q.name_matches(params[:name_matches])
|
||||||
end
|
end
|
||||||
|
|||||||
6
app/views/legacy/tags.xml.erb
Normal file
6
app/views/legacy/tags.xml.erb
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<tags type="array">
|
||||||
|
<% @tags.each do |tag| %>
|
||||||
|
<tag name="<%= tag.name %>" id="<%= tag.id %>" ambiguous="false" created_at="<%= tag.created_at.strftime('%Y-%m-%d %H:%M') %>" count="<%= tag.post_count %>" type="<%= tag.category %>"></user>
|
||||||
|
<% end %>
|
||||||
|
</tags>
|
||||||
1
app/views/legacy/users.json.erb
Normal file
1
app/views/legacy/users.json.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
[<%= @users.map {|x| x.to_legacy_json}.join(", ").html_safe %>]
|
||||||
6
app/views/legacy/users.xml.erb
Normal file
6
app/views/legacy/users.xml.erb
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<users type="array">
|
||||||
|
<% @users.each do |user| %>
|
||||||
|
<user name="<%= user.name %>" id="<%= user.id %>" created_at="<%= user.created_at.strftime('%Y-%m-%d %H:%M') %>" level="<%= user.level %>"></user>
|
||||||
|
<% end %>
|
||||||
|
</users>
|
||||||
@@ -236,9 +236,13 @@ Danbooru::Application.routes.draw do
|
|||||||
match "/post_tag_history" => redirect {|params, req| "/post_versions?page=#{req.params[:page]}"}
|
match "/post_tag_history" => redirect {|params, req| "/post_versions?page=#{req.params[:page]}"}
|
||||||
match "/post_tag_history/index" => redirect {|params, req| "/post_versions?page=#{req.params[:page]}"}
|
match "/post_tag_history/index" => redirect {|params, req| "/post_versions?page=#{req.params[:page]}"}
|
||||||
|
|
||||||
|
match "/tag/index.xml", :controller => "legacy", :action => "tags", :format => "xml"
|
||||||
|
match "/tag/index.json", :controller => "legacy", :action => "tags", :format => "json"
|
||||||
match "/tag" => redirect {|params, req| "/tags?page=#{req.params[:page]}"}
|
match "/tag" => redirect {|params, req| "/tags?page=#{req.params[:page]}"}
|
||||||
match "/tag/index" => redirect {|params, req| "/tags?page=#{req.params[:page]}"}
|
match "/tag/index" => redirect {|params, req| "/tags?page=#{req.params[:page]}"}
|
||||||
|
|
||||||
|
match "/user/index.xml", :controller => "legacy", :action => "users", :format => "xml"
|
||||||
|
match "/user/index.json", :controller => "legacy", :action => "users", :format => "json"
|
||||||
match "/user" => redirect {|params, req| "/users?page=#{req.params[:page]}"}
|
match "/user" => redirect {|params, req| "/users?page=#{req.params[:page]}"}
|
||||||
match "/user/index" => redirect {|params, req| "/users?page=#{req.params[:page]}"}
|
match "/user/index" => redirect {|params, req| "/users?page=#{req.params[:page]}"}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user