added legacy api for posts
This commit is contained in:
11
app/controllers/legacy_controller.rb
Normal file
11
app/controllers/legacy_controller.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
class LegacyController < ApplicationController
|
||||
def posts
|
||||
@post_set = PostSets::Post.new(tag_query, params[:page])
|
||||
@posts = @post_set.posts
|
||||
end
|
||||
|
||||
private
|
||||
def tag_query
|
||||
params[:tags] || (params[:post] && params[:post][:tags])
|
||||
end
|
||||
end
|
||||
@@ -1058,6 +1058,42 @@ class Post < ActiveRecord::Base
|
||||
options[:except] += hidden_attributes
|
||||
super(options, &block)
|
||||
end
|
||||
|
||||
def to_legacy_json
|
||||
return {
|
||||
"has_comments" => last_commented_at.present?,
|
||||
"parent_id" => parent_id,
|
||||
"status" => status,
|
||||
"has_children" => has_children?,
|
||||
"created_at" => created_at.to_formatted_s(:db),
|
||||
"md5" => md5,
|
||||
"has_notes" => last_noted_at.present?,
|
||||
"rating" => rating,
|
||||
"author" => uploader.name,
|
||||
"creator_id" => uploader_id,
|
||||
"width" => image_width,
|
||||
"source" => source,
|
||||
"preview_url" => preview_file_url,
|
||||
"score" => score,
|
||||
"tags" => tag_string,
|
||||
"height" => image_height,
|
||||
"file_size" => file_size,
|
||||
"id" => id,
|
||||
"file_url" => file_url
|
||||
}.to_json
|
||||
end
|
||||
|
||||
def status
|
||||
if is_pending?
|
||||
"pending"
|
||||
elsif is_deleted?
|
||||
"deleted"
|
||||
elsif is_flagged?
|
||||
"flagged"
|
||||
else
|
||||
"active"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
include FileMethods
|
||||
|
||||
1
app/views/legacy/posts.json.erb
Normal file
1
app/views/legacy/posts.json.erb
Normal file
@@ -0,0 +1 @@
|
||||
[<%= @posts.map {|x| x.to_legacy_json}.join(", ").html_safe %>]
|
||||
6
app/views/legacy/posts.xml.erb
Normal file
6
app/views/legacy/posts.xml.erb
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<posts>
|
||||
<% @posts.each do |post| %>
|
||||
<post preview_url="<%= post.preview_file_url %>" file_size="<%= post.file_size %>" status="<%= post.status %>" score="<%= post.score %>" file_url="<%= post.file_url %>" height="<%= post.image_height %>" has_comments="<%= post.last_commented_at.present? %>" tags="<%= post.tag_string %>" source="<%= post.source %>" parent_id="<%= post.parent_id %>" created_at="<%= post.created_at.to_formatted_s(:db) %>" rating="<%= post.rating %>" has_notes="<%= post.last_noted_at.present? %>" id="<%= post.id %>" md5="<%= post.md5 %>" has_children="<%= post.has_children? %>" creator_id="<%= post.uploader_id %>" author="<%= post.uploader.name %>" width="<%= post.image_width %>"/>
|
||||
<% end %>
|
||||
</posts>
|
||||
@@ -205,7 +205,9 @@ Danbooru::Application.routes.draw do
|
||||
match "/pool/history/:id" => redirect("/pool_versions?search[pool_id]=%{id}")
|
||||
match "/pool/recent_changes" => redirect("/pool_versions")
|
||||
|
||||
match "/post/index" => redirect {|params, req| "/posts?tags=#{params[:tags]}&page=#{req.params[:page]}"}
|
||||
match "/post/index.xml", :controller => "legacy", :action => "posts", :format => "xml"
|
||||
match "/post/index.json", :controller => "legacy", :action => "posts", :format => "json"
|
||||
match "/post/index" => redirect {|params, req| "/posts?tags=#{req.params[:tags]}&page=#{req.params[:page]}"}
|
||||
match "/post" => redirect {|params, req| "/posts?tags=#{req.params[:tags]}&page=#{req.params[:page]}"}
|
||||
match "/post/upload" => redirect("/uploads/new")
|
||||
match "/post/moderate" => redirect("/moderator/post/queue")
|
||||
|
||||
Reference in New Issue
Block a user