This commit is contained in:
2026-04-09 22:44:09 +09:00
parent 7b15cb2c5a
commit b2d72ffcb0
7 changed files with 218 additions and 16 deletions
+21 -15
View File
@@ -127,17 +127,20 @@ class PostsController < ApplicationController
post = Post.new(title:, url:, thumbnail_base: nil, uploaded_user: current_user,
original_created_from:, original_created_before:)
post.thumbnail.attach(thumbnail)
if post.save
post.resized_thumbnail!
ActiveRecord::Base.transaction do
post.save!
tags = Tag.normalise_tags(tag_names)
tags = Tag.expand_parent_tags(tags)
sync_post_tags!(post, tags)
post.reload
render json: PostRepr.base(post), status: :created
else
render json: { errors: post.errors.full_messages }, status: :unprocessable_entity
post.resized_thumbnail!
PostVersionRecorder.record!(post:, event_type: :create, created_by_user: current_user)
end
post.reload
render json: PostRepr.base(post), status: :created
rescue ActiveRecord::RecordInvalid
render json: { errors: post.errors.full_messages }, status: :unprocessable_entity
rescue Tag::NicoTagNormalisationError
head :bad_request
end
@@ -166,19 +169,22 @@ class PostsController < ApplicationController
original_created_before = params[:original_created_before]
post = Post.find(params[:id].to_i)
if post.update(title:, original_created_from:, original_created_before:)
ActiveRecord::Base.transaction do
post.update!(title:, original_created_from:, original_created_before:)
tags = post.tags.where(category: 'nico').to_a +
Tag.normalise_tags(tag_names, with_tagme: false)
tags = Tag.expand_parent_tags(tags)
sync_post_tags!(post, tags)
post.reload
json = post.as_json
json['tags'] = build_tag_tree_for(post.tags)
render json:, status: :ok
else
render json: post.errors, status: :unprocessable_entity
PostVersionRecorder.record!(post:, event_type: :update, created_by_user: current_user)
end
post.reload
json = post.as_json
json['tags'] = build_tag_tree_for(post.tags)
render json:, status: :ok
rescue ActiveRecord::RecordInvalid
render json: post.errors, status: :unprocessable_entity
rescue Tag::NicoTagNormalisationError
head :bad_request
end