このコミットが含まれているのは:
@@ -175,15 +175,23 @@ class PostsController < ApplicationController
|
||||
return head :unauthorized unless current_user
|
||||
return head :forbidden unless current_user.gte_member?
|
||||
|
||||
if bool?(:dry)
|
||||
preflight = PostCreatePreflight.new(
|
||||
attributes: post_create_attributes,
|
||||
thumbnail: params[:thumbnail]).run
|
||||
return render json: preflight
|
||||
end
|
||||
preflight = PostCreatePreflight.new(
|
||||
attributes: post_create_attributes,
|
||||
thumbnail: params[:thumbnail]).run
|
||||
return render json: preflight if bool?(:dry)
|
||||
|
||||
post = PostCreator.new(actor: current_user,
|
||||
attributes: post_create_attributes.merge(
|
||||
preflight.slice(
|
||||
:url,
|
||||
:title,
|
||||
:thumbnail_base,
|
||||
:tags,
|
||||
:parent_post_ids,
|
||||
:original_created_from,
|
||||
:original_created_before,
|
||||
:duration,
|
||||
:video_ms).symbolize_keys).merge(
|
||||
thumbnail: params[:thumbnail])).create!
|
||||
|
||||
post.reload
|
||||
@@ -532,6 +540,7 @@ class PostsController < ApplicationController
|
||||
def parse_bulk_posts_manifest
|
||||
manifest = params[:posts]
|
||||
raise ArgumentError, 'posts は必須です.' if manifest.blank?
|
||||
raise ArgumentError, 'posts は JSON 文字列で指定してください.' unless manifest.is_a?(String)
|
||||
|
||||
posts = JSON.parse(manifest)
|
||||
raise ArgumentError, 'posts は配列で指定してください.' unless posts.is_a?(Array)
|
||||
@@ -569,15 +578,7 @@ class PostsController < ApplicationController
|
||||
return nil if post_id.blank?
|
||||
|
||||
post = Post.with_attached_thumbnail.find_by(id: post_id)
|
||||
return nil if post.nil?
|
||||
|
||||
{ id: post.id,
|
||||
title: post.title,
|
||||
url: post.url,
|
||||
thumbnail_url:
|
||||
if post.thumbnail.attached?
|
||||
rails_storage_proxy_url(post.thumbnail, only_path: false)
|
||||
end }
|
||||
PostCompactRepr.base(post)
|
||||
end
|
||||
|
||||
def sync_parent_posts! post, parent_post_ids
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
|
||||
module PostCompactRepr
|
||||
module_function
|
||||
|
||||
def base post
|
||||
return nil if post.nil?
|
||||
|
||||
{
|
||||
id: post.id,
|
||||
title: post.title,
|
||||
url: post.url,
|
||||
thumbnail_url: thumbnail_url(post) }
|
||||
end
|
||||
|
||||
def thumbnail_url post
|
||||
return nil unless post.thumbnail.attached?
|
||||
|
||||
Rails.application.routes.url_helpers.rails_storage_proxy_url(
|
||||
post.thumbnail,
|
||||
only_path: false)
|
||||
rescue
|
||||
nil
|
||||
end
|
||||
end
|
||||
@@ -55,14 +55,21 @@ class PostBulkCreator
|
||||
errors: e.record.errors.to_hash,
|
||||
base_errors: e.record.errors[:base] }
|
||||
rescue ActiveRecord::RecordNotUnique => e
|
||||
raise unless e.message.include?('index_posts_on_url')
|
||||
|
||||
existing_post = existing_post_for_race(attributes)
|
||||
raise if existing_post.nil?
|
||||
if e.message.include?('index_posts_on_url')
|
||||
existing_post = existing_post_for_race(attributes)
|
||||
return {
|
||||
status: 'skipped',
|
||||
existing_post: existing_post } if existing_post.present?
|
||||
end
|
||||
|
||||
Rails.logger.error(
|
||||
"post_bulk_creator_record_not_unique #{ { error: e.class.name,
|
||||
message: e.message }.to_json }")
|
||||
{
|
||||
status: 'skipped',
|
||||
existing_post: existing_post }
|
||||
status: 'failed',
|
||||
recoverable: false,
|
||||
errors: { base: ['登録中にエラーが発生しました.'] },
|
||||
base_errors: [] }
|
||||
rescue Tag::NicoTagNormalisationError
|
||||
{
|
||||
status: 'failed',
|
||||
@@ -134,17 +141,6 @@ class PostBulkCreator
|
||||
end
|
||||
|
||||
def compact_existing_post post
|
||||
return nil if post.nil?
|
||||
|
||||
{
|
||||
id: post.id,
|
||||
title: post.title,
|
||||
url: post.url,
|
||||
thumbnail_url:
|
||||
if post.thumbnail.attached?
|
||||
Rails.application.routes.url_helpers.rails_storage_proxy_url(
|
||||
post.thumbnail,
|
||||
only_path: false)
|
||||
end }
|
||||
PostCompactRepr.base(post)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -88,17 +88,6 @@ class PostCreatePreflight
|
||||
return nil if post_id.blank?
|
||||
|
||||
post = Post.with_attached_thumbnail.find_by(id: post_id)
|
||||
return nil if post.nil?
|
||||
|
||||
{
|
||||
id: post.id,
|
||||
title: post.title,
|
||||
url: post.url,
|
||||
thumbnail_url:
|
||||
if post.thumbnail.attached?
|
||||
Rails.application.routes.url_helpers.rails_storage_proxy_url(
|
||||
post.thumbnail,
|
||||
only_path: false)
|
||||
end }
|
||||
PostCompactRepr.base(post)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -255,7 +255,15 @@ class PostImportPreviewer
|
||||
def sanitise_metadata_url value
|
||||
return nil unless value.is_a?(String)
|
||||
|
||||
PostUrlNormaliser.normalise(value)
|
||||
stripped = value.strip
|
||||
return nil if stripped.blank?
|
||||
|
||||
uri = URI.parse(stripped)
|
||||
return nil unless uri.is_a?(URI::HTTP) && uri.host.present?
|
||||
|
||||
stripped
|
||||
rescue URI::InvalidURIError
|
||||
nil
|
||||
end
|
||||
|
||||
def sanitise_metadata_time value
|
||||
|
||||
新しい課題から参照
ユーザをブロックする