このコミットが含まれているのは:
@@ -148,7 +148,8 @@ class PostsController < ApplicationController
|
||||
original_created_from: params[:original_created_from],
|
||||
original_created_before: params[:original_created_before],
|
||||
parent_post_ids: parse_parent_post_ids,
|
||||
video_ms: params[:video_ms], duration: params[:duration] }).create!
|
||||
video_ms: params[:video_ms],
|
||||
duration: params[:duration] }).create!
|
||||
|
||||
post.reload
|
||||
render json: PostRepr.base(post), status: :created
|
||||
|
||||
@@ -54,20 +54,25 @@ class PostImportPreviewer
|
||||
add_field_warning!(field_warnings, 'url', EXISTING_SKIP_WARNING)
|
||||
attributes['tags'] = merged_tags(tag_sources, provenance['tags'])
|
||||
warnings_present = field_warnings.values.any?(&:present?) || base_warnings.present?
|
||||
return {
|
||||
source_row: row[:source_row],
|
||||
url: normal_url,
|
||||
attributes:,
|
||||
provenance:,
|
||||
tag_sources:,
|
||||
metadata_url: url_for_metadata,
|
||||
skip_reason: 'existing',
|
||||
existing_post_id: existing_post.id,
|
||||
field_warnings:,
|
||||
base_warnings:,
|
||||
validation_errors:,
|
||||
status: validation_errors.present? ? 'error' : (warnings_present ? 'warning' : 'ready'),
|
||||
}
|
||||
return { source_row: row[:source_row],
|
||||
url: normal_url,
|
||||
attributes:,
|
||||
provenance:,
|
||||
tag_sources:,
|
||||
metadata_url: url_for_metadata,
|
||||
skip_reason: 'existing',
|
||||
existing_post_id: existing_post.id,
|
||||
field_warnings:,
|
||||
base_warnings:,
|
||||
validation_errors:,
|
||||
status:
|
||||
if validation_errors.present?
|
||||
'error'
|
||||
elsif warnings_present
|
||||
'warning'
|
||||
else
|
||||
'ready'
|
||||
end }
|
||||
end
|
||||
|
||||
should_fetch = should_fetch_metadata?(fetch_metadata, row[:source_row].to_i)
|
||||
@@ -88,8 +93,7 @@ class PostImportPreviewer
|
||||
attributes['tags'] = merged_tags(tag_sources, provenance['tags'])
|
||||
|
||||
warnings_present = field_warnings.values.any?(&:present?) || base_warnings.present?
|
||||
{
|
||||
source_row: row[:source_row],
|
||||
{ source_row: row[:source_row],
|
||||
url: normal_url || url,
|
||||
attributes:,
|
||||
provenance:,
|
||||
@@ -100,8 +104,7 @@ class PostImportPreviewer
|
||||
field_warnings:,
|
||||
base_warnings:,
|
||||
validation_errors:,
|
||||
status: validation_errors.present? ? 'error' : (warnings_present ? 'warning' : 'ready'),
|
||||
}
|
||||
status: validation_errors.present? ? 'error' : (warnings_present ? 'warning' : 'ready') }
|
||||
end
|
||||
|
||||
def should_fetch_metadata? fetch_metadata, source_row
|
||||
@@ -175,9 +178,8 @@ class PostImportPreviewer
|
||||
Preview::HttpFetcher::FetchFailed,
|
||||
Preview::HttpFetcher::ResponseTooLarge => e
|
||||
Rails.logger.info(
|
||||
"post_import_metadata_fetch_failure "\
|
||||
"#{ { error: e.class.name, message: e.message }.to_json }",
|
||||
)
|
||||
"post_import_metadata_fetch_failure "\
|
||||
"#{ { error: e.class.name, message: e.message }.to_json }")
|
||||
{ data: { }, warnings: { 'url' => [METADATA_FETCH_WARNING] } }
|
||||
end
|
||||
|
||||
|
||||
@@ -24,11 +24,10 @@ class PostImportRunner
|
||||
|
||||
def run_row row, preview
|
||||
attributes = row.fetch('attributes', { }).transform_keys { _1.to_s.underscore }
|
||||
return row.slice('source_row').merge(status: 'skipped') if preview[:skip_reason] == 'existing'
|
||||
|
||||
return { source_row: row['source_row'],
|
||||
status: 'failed',
|
||||
errors: preview[:validation_errors] } if preview[:validation_errors].present?
|
||||
return row.slice('source_row').merge(status: 'skipped') if preview[:skip_reason] == 'existing'
|
||||
|
||||
attributes['tags'] = preview[:attributes]['tags']
|
||||
attributes['url'] = row['url']
|
||||
@@ -44,7 +43,7 @@ class PostImportRunner
|
||||
{ source_row: row['source_row'],
|
||||
status: 'failed',
|
||||
errors: { tags: ['廃止済みタグは付与できません.'] } }
|
||||
rescue ArgumentError, PostCreator::VideoMsParseError
|
||||
rescue ArgumentError
|
||||
{ source_row: row['source_row'],
|
||||
status: 'failed',
|
||||
errors: { base: ['入力値が不正です.'] } }
|
||||
|
||||
@@ -2,9 +2,8 @@ class PostMetadataFetcher
|
||||
def self.fetch raw_url
|
||||
uri, = Preview::UrlSafety.validate(raw_url)
|
||||
response = Preview::HttpFetcher.fetch(
|
||||
uri.to_s,
|
||||
max_bytes: Preview::ThumbnailFetcher::HTML_MAX_BYTES,
|
||||
)
|
||||
uri.to_s,
|
||||
max_bytes: Preview::ThumbnailFetcher::HTML_MAX_BYTES)
|
||||
metadata = Preview::HtmlMetadataExtractor.extract(response)
|
||||
document = Nokogiri::HTML.parse(response.body)
|
||||
content = lambda { |name|
|
||||
@@ -19,7 +18,8 @@ class PostMetadataFetcher
|
||||
created_range = original_created_range(published)
|
||||
platform_tags = platform_tags(uri)
|
||||
{ title: metadata[:title],
|
||||
thumbnail_base: Preview::KnownSiteExtractor.thumbnail_url(uri) || metadata[:image_url],
|
||||
thumbnail_base:
|
||||
Preview::KnownSiteExtractor.thumbnail_url(uri) || metadata[:image_url],
|
||||
original_created_from: created_range&.first&.iso8601,
|
||||
original_created_before: created_range&.last&.iso8601,
|
||||
duration: duration&.to_f&.then { _1.positive? ? (_1 * 1_000).round : nil },
|
||||
@@ -56,5 +56,6 @@ class PostMetadataFetcher
|
||||
rescue ArgumentError, TypeError
|
||||
nil
|
||||
end
|
||||
|
||||
private_class_method :platform_tags, :original_created_range
|
||||
end
|
||||
|
||||
@@ -6,7 +6,7 @@ class PostUrlNormaliser
|
||||
|
||||
uri.host = uri.host.downcase
|
||||
uri.path = uri.path.sub(/\/\z/, '') if uri.path.present?
|
||||
uri.to_s
|
||||
PostUrlSanitisationRule.sanitise(uri.to_s)
|
||||
rescue URI::InvalidURIError
|
||||
nil
|
||||
end
|
||||
|
||||
@@ -12,7 +12,9 @@ module Preview
|
||||
|
||||
Response = Data.define(:body, :content_type, :url)
|
||||
|
||||
def self.fetch(raw_url, max_bytes: DEFAULT_MAX_BYTES, redirects: MAX_REDIRECTS,
|
||||
def self.fetch(raw_url,
|
||||
max_bytes: DEFAULT_MAX_BYTES,
|
||||
redirects: MAX_REDIRECTS,
|
||||
allowed_hosts: nil)
|
||||
uri, addresses = UrlSafety.validate(raw_url)
|
||||
if allowed_hosts && !allowed_hosts.include?(uri.host.downcase)
|
||||
|
||||
新しい課題から参照
ユーザをブロックする