このコミットが含まれているのは:
@@ -17,8 +17,8 @@ module PostRepr
|
||||
|
||||
module_function
|
||||
|
||||
def base post, current_user = nil
|
||||
json = common(post)
|
||||
def base post, current_user = nil, host: nil
|
||||
json = common(post, host:)
|
||||
json['tags'] = tag_json(post)
|
||||
json['uploaded_user'] = post.uploaded_user && UserRepr.base(post.uploaded_user)
|
||||
json['viewed'] = current_user ? current_user.viewed?(post) : false
|
||||
@@ -26,31 +26,31 @@ module PostRepr
|
||||
end
|
||||
|
||||
def detail post, current_user = nil, parent_posts: [], child_posts: [],
|
||||
sibling_posts: { }, related: []
|
||||
base(post, current_user).merge(
|
||||
'parent_posts' => cards(parent_posts),
|
||||
'child_posts' => cards(child_posts),
|
||||
sibling_posts: { }, related: [], host: nil
|
||||
base(post, current_user, host:).merge(
|
||||
'parent_posts' => cards(parent_posts, host:),
|
||||
'child_posts' => cards(child_posts, host:),
|
||||
'sibling_posts' => sibling_posts.transform_keys(&:to_s).transform_values { |posts|
|
||||
cards(posts)
|
||||
cards(posts, host:)
|
||||
},
|
||||
'related' => cards(related))
|
||||
'related' => cards(related, host:))
|
||||
end
|
||||
|
||||
def card post
|
||||
common(post).merge('parent_posts' => [], 'child_posts' => [])
|
||||
def card post, host: nil
|
||||
common(post, host:).merge('parent_posts' => [], 'child_posts' => [])
|
||||
end
|
||||
|
||||
def cards posts
|
||||
posts.map { |post| card(post) }
|
||||
def cards posts, host: nil
|
||||
posts.map { |post| card(post, host:) }
|
||||
end
|
||||
|
||||
def many posts, current_user = nil
|
||||
posts.map { |p| base(p, current_user) }
|
||||
def many posts, current_user = nil, host: nil
|
||||
posts.map { |p| base(p, current_user, host:) }
|
||||
end
|
||||
|
||||
def common post
|
||||
def common post, host: nil
|
||||
BASE_FIELDS.to_h { |field| [field.to_s, post.public_send(field)] }
|
||||
.merge('thumbnail' => thumbnail_url(post))
|
||||
.merge('thumbnail' => thumbnail_url(post, host:))
|
||||
end
|
||||
|
||||
def tag_json post
|
||||
@@ -65,10 +65,13 @@ module PostRepr
|
||||
}
|
||||
end
|
||||
|
||||
def thumbnail_url post
|
||||
def thumbnail_url post, host: nil
|
||||
return nil unless post.thumbnail.attached?
|
||||
|
||||
Rails.application.routes.url_helpers.rails_blob_url(post.thumbnail, only_path: false)
|
||||
Rails.application.routes.url_helpers.rails_storage_proxy_url(
|
||||
post.thumbnail,
|
||||
only_path: false,
|
||||
host:)
|
||||
rescue ActionController::UrlGenerationError, ArgumentError, URI::InvalidURIError => e
|
||||
Rails.logger.warn(
|
||||
"PostRepr.thumbnail_url failed post_id=#{post.id} " \
|
||||
|
||||
新しい課題から参照
ユーザをブロックする