このコミットが含まれているのは:
2026-09-28 00:30:03 +09:00
コミット 28e638e360
18個のファイルの変更、209行の追加、68行の削除
+14 -10
ファイルの表示
@@ -92,7 +92,8 @@ class PostsController < ApplicationController
q = q.except(:select, :order)
render json: { posts: posts.map { |post|
PostRepr.base(post).merge(updated_at: post.updated_at_all).tap do |json|
PostRepr.base(post, language_code: locale.language_code)
.merge(updated_at: post.updated_at_all).tap do |json|
json['thumbnail'] =
if post.thumbnail.attached?
rails_storage_proxy_url(post.thumbnail, only_path: false)
@@ -116,7 +117,7 @@ class PostsController < ApplicationController
.first
return head :not_found unless post
render json: PostRepr.base(post, current_user)
render json: PostRepr.base(post, current_user, language_code: locale.language_code)
end
def metadata
@@ -191,6 +192,8 @@ class PostsController < ApplicationController
end
def show
locale = resolve_locale!
post =
Post
.includes(:uploaded_user, :parents, :children,
@@ -209,8 +212,9 @@ class PostsController < ApplicationController
parent_posts:,
child_posts:,
sibling_posts:,
related:)
.merge(tags: build_tag_tree_for(post))
related:,
language_code: locale.language_code)
.merge(tags: build_tag_tree_for(post, locale.language_code))
end
def create
@@ -251,7 +255,7 @@ class PostsController < ApplicationController
thumbnail: params[:thumbnail])).create!(locale)
post.reload
render json: PostRepr.base(post), status: :created
render json: PostRepr.base(post, language_code: locale.language_code), status: :created
rescue PostCreatePreflight::ValidationFailed => e
render_validation_error fields: e.fields, base: e.base_errors
rescue Tag::NicoTagNormalisationError
@@ -379,8 +383,8 @@ class PostsController < ApplicationController
return render json: conflict_json, status: :conflict if conflict_json
post.reload
json = PostRepr.base(post, current_user)
json['tags'] = build_tag_tree_for(post)
json = PostRepr.base(post, current_user, language_code: locale.language_code)
json['tags'] = build_tag_tree_for(post, locale.language_code)
render json:, status: :ok
rescue Tag::NicoTagNormalisationError
render_validation_error fields: { tags: ['ニコニコ・タグは直接指定できません.'] }
@@ -487,7 +491,7 @@ class PostsController < ApplicationController
end
end
def build_tag_tree_for post
def build_tag_tree_for post, language_code = 'ja'
post_tags = post.post_tags.reject { |post_tag| post_tag.tag.deprecated? }
tags = post_tags.map(&:tag)
tag_ids = tags.map(&:id)
@@ -517,7 +521,7 @@ class PostsController < ApplicationController
sections = sections_by_tag_id.fetch(tag_id, [])
if path.include?(tag_id)
return TagRepr.inline(tag).merge(children: [], sections:)
return TagRepr.inline(tag, language_code:).merge(children: [], sections:)
end
if memo.key?(tag_id)
@@ -529,7 +533,7 @@ class PostsController < ApplicationController
children = child_ids.filter_map { |cid| build_node.(cid, new_path) }
memo[tag_id] = TagRepr.inline(tag).merge(children:, sections:)
memo[tag_id] = TagRepr.inline(tag, language_code:).merge(children:, sections:)
end
internal_tags = root_ids.filter_map { |id| build_node.call(id, []) }