このコミットが含まれているのは:
2026-07-14 19:12:23 +09:00
コミット 6d037192c4
9個のファイルの変更108行の追加72行の削除
+23 -21
ファイルの表示
@@ -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
+2 -3
ファイルの表示
@@ -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: ['入力値が不正です.'] } }
+5 -4
ファイルの表示
@@ -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
+1 -1
ファイルの表示
@@ -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
+3 -1
ファイルの表示
@@ -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)