広場投稿追加画面の刷新 (#399) #413

マージ済み
みてるぞ が 103 個のコミットを feature/399 から main へマージ 2026-07-19 00:03:11 +09:00
5個のファイルの変更39行の追加28行の削除
コミット 74b1ada0dd の変更だけを表示してゐます - すべてのコミットを表示
+8 -3
ファイルの表示
@@ -216,7 +216,8 @@ class PostsController < ApplicationController
preflight = PostCreatePreflight.new( preflight = PostCreatePreflight.new(
attributes: post_create_attributes, attributes: post_create_attributes,
thumbnail: params[:thumbnail]).run thumbnail: params[:thumbnail],
host: request.base_url).run
return render json: dry_run_json(preflight) if bool?(:dry) return render json: dry_run_json(preflight) if bool?(:dry)
if preflight[:existing_post_id].present? if preflight[:existing_post_id].present?
post = Post.new(url: preflight[:url]) post = Post.new(url: preflight[:url])
@@ -273,7 +274,11 @@ class PostsController < ApplicationController
return head :payload_too_large if request.content_length.to_i > MAX_BULK_REQUEST_BYTES return head :payload_too_large if request.content_length.to_i > MAX_BULK_REQUEST_BYTES
posts = parse_bulk_posts_manifest posts = parse_bulk_posts_manifest
thumbnails = parse_bulk_thumbnails(posts.length) thumbnails = parse_bulk_thumbnails(posts.length)
result = PostBulkCreator.new(actor: current_user, posts:, thumbnails:).run result = PostBulkCreator.new(
actor: current_user,
posts:,
thumbnails:,
host: request.base_url).run
render json: result render json: result
rescue JSON::ParserError rescue JSON::ParserError
render_bad_request 'posts manifest の JSON が不正です.' render_bad_request 'posts manifest の JSON が不正です.'
@@ -627,7 +632,7 @@ class PostsController < ApplicationController
return nil if post_id.blank? return nil if post_id.blank?
post = Post.with_attached_thumbnail.find_by(id: post_id) post = Post.with_attached_thumbnail.find_by(id: post_id)
PostCompactRepr.base(post) PostCompactRepr.base(post, host: request.base_url)
end end
def dry_run_json preflight def dry_run_json preflight
+2 -2
ファイルの表示
@@ -4,11 +4,11 @@
module PostCompactRepr module PostCompactRepr
module_function module_function
def base post def base post, host: nil
return nil if post.nil? return nil if post.nil?
PostRepr PostRepr
.common(post) .common(post, host:)
.slice( .slice(
'id', 'id',
'title', 'title',
+21 -18
ファイルの表示
@@ -17,8 +17,8 @@ module PostRepr
module_function module_function
def base post, current_user = nil def base post, current_user = nil, host: nil
json = common(post) json = common(post, host:)
json['tags'] = tag_json(post) json['tags'] = tag_json(post)
json['uploaded_user'] = post.uploaded_user && UserRepr.base(post.uploaded_user) json['uploaded_user'] = post.uploaded_user && UserRepr.base(post.uploaded_user)
json['viewed'] = current_user ? current_user.viewed?(post) : false json['viewed'] = current_user ? current_user.viewed?(post) : false
@@ -26,31 +26,31 @@ module PostRepr
end end
def detail post, current_user = nil, parent_posts: [], child_posts: [], def detail post, current_user = nil, parent_posts: [], child_posts: [],
sibling_posts: { }, related: [] sibling_posts: { }, related: [], host: nil
base(post, current_user).merge( base(post, current_user, host:).merge(
'parent_posts' => cards(parent_posts), 'parent_posts' => cards(parent_posts, host:),
'child_posts' => cards(child_posts), 'child_posts' => cards(child_posts, host:),
'sibling_posts' => sibling_posts.transform_keys(&:to_s).transform_values { |posts| 'sibling_posts' => sibling_posts.transform_keys(&:to_s).transform_values { |posts|
cards(posts) cards(posts, host:)
}, },
'related' => cards(related)) 'related' => cards(related, host:))
end end
def card post def card post, host: nil
common(post).merge('parent_posts' => [], 'child_posts' => []) common(post, host:).merge('parent_posts' => [], 'child_posts' => [])
end end
def cards posts def cards posts, host: nil
posts.map { |post| card(post) } posts.map { |post| card(post, host:) }
end end
def many posts, current_user = nil def many posts, current_user = nil, host: nil
posts.map { |p| base(p, current_user) } posts.map { |p| base(p, current_user, host:) }
end end
def common post def common post, host: nil
BASE_FIELDS.to_h { |field| [field.to_s, post.public_send(field)] } BASE_FIELDS.to_h { |field| [field.to_s, post.public_send(field)] }
.merge('thumbnail' => thumbnail_url(post)) .merge('thumbnail' => thumbnail_url(post, host:))
end end
def tag_json post def tag_json post
@@ -65,10 +65,13 @@ module PostRepr
} }
end end
def thumbnail_url post def thumbnail_url post, host: nil
return nil unless post.thumbnail.attached? 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 rescue ActionController::UrlGenerationError, ArgumentError, URI::InvalidURIError => e
Rails.logger.warn( Rails.logger.warn(
"PostRepr.thumbnail_url failed post_id=#{post.id} " \ "PostRepr.thumbnail_url failed post_id=#{post.id} " \
+5 -3
ファイルの表示
@@ -1,8 +1,9 @@
class PostBulkCreator class PostBulkCreator
def initialize actor:, posts:, thumbnails: def initialize actor:, posts:, thumbnails:, host: nil
@actor_id = actor.id @actor_id = actor.id
@posts = posts @posts = posts
@thumbnails = thumbnails @thumbnails = thumbnails
@host = host
end end
def run def run
@@ -64,7 +65,8 @@ class PostBulkCreator
preflight = preflight =
PostCreatePreflight.new( PostCreatePreflight.new(
attributes: attributes, attributes: attributes,
thumbnail: thumbnail_for(index, attributes)).run thumbnail: thumbnail_for(index, attributes),
host: @host).run
if preflight[:existing_post_id].present? if preflight[:existing_post_id].present?
return { return {
status: 'skipped', status: 'skipped',
@@ -195,6 +197,6 @@ class PostBulkCreator
end end
def compact_existing_post post def compact_existing_post post
PostCompactRepr.base(post) PostCompactRepr.base(post, host: @host)
end end
end end
+3 -2
ファイルの表示
@@ -9,9 +9,10 @@ class PostCreatePreflight
end end
end end
def initialize attributes:, thumbnail: nil def initialize attributes:, thumbnail: nil, host: nil
@attributes = attributes.symbolize_keys @attributes = attributes.symbolize_keys
@thumbnail = thumbnail @thumbnail = thumbnail
@host = host
end end
def run def run
@@ -124,7 +125,7 @@ class PostCreatePreflight
return nil if post_id.blank? return nil if post_id.blank?
post = Post.with_attached_thumbnail.find_by(id: post_id) post = Post.with_attached_thumbnail.find_by(id: post_id)
PostCompactRepr.base(post) PostCompactRepr.base(post, host: @host)
end end
def final_field_warnings field_warnings def final_field_warnings field_warnings