API: remove various associated fields included by default.

Remove various associated fields that were included by default on
certain endpoints. API users can use the only param to include the
full association if they need these fields.

* /artists.json: urls.
* /artist_urls.json: artist.
* /comments.json: creator_name and updater_name.
* /notes.json: creator_name.
* /pools.json: creator_name.
* /posts.json: uploader_name, children_ids, pixiv_ugoira_frame_data.
* /post_appeals.json: is_resolved.
* /post_versions.json: updater_name.
* /uploads.json: uploader_name.
This commit is contained in:
evazion
2020-02-14 20:15:51 -06:00
parent c5bcfb962f
commit 8649ff6dbe
15 changed files with 10 additions and 84 deletions

View File

@@ -971,10 +971,6 @@ class Post < ApplicationRecord
self.uploader_ip_addr = CurrentUser.ip_addr
end
end
def uploader_name
uploader.name
end
end
module PoolMethods
@@ -1220,12 +1216,6 @@ class Post < ApplicationRecord
def has_visible_children
has_visible_children?
end
def children_ids
if has_children?
children.map(&:id).join(' ')
end
end
end
module DeletionMethods
@@ -1382,24 +1372,13 @@ class Post < ApplicationRecord
module ApiMethods
def api_attributes
attributes = super
attributes += [:uploader_name, :has_large, :has_visible_children, :children_ids, :is_favorited?] + TagCategory.categories.map {|x| "tag_string_#{x}".to_sym}
attributes += [:has_large, :has_visible_children, :is_favorited?] + TagCategory.categories.map {|x| "tag_string_#{x}".to_sym}
attributes += [:file_url, :large_file_url, :preview_file_url] if visible?
attributes -= [:md5, :file_ext] if !visible?
attributes -= [:fav_string] if !CurrentUser.is_moderator?
attributes
end
def associated_attributes
[:pixiv_ugoira_frame_data]
end
def as_json(options = {})
options ||= {}
options[:include] ||= []
options[:include] += associated_attributes
super(options)
end
def legacy_attributes
hash = {
"has_comments" => last_commented_at.present?,