このコミットが含まれているのは:
2026-07-11 23:21:59 +09:00
コミット 440d3d38be
5個のファイルの変更63行の追加27行の削除
+17 -5
ファイルの表示
@@ -19,6 +19,8 @@ class PostImportPreviewer
values = row[:values] || []
attributes = row[:attributes]&.stringify_keys || FIELDS.to_h { |field| [field, mapped_value(field, values)] }
provenance = row[:provenance]&.stringify_keys || mapped_provenance(attributes)
tag_sources = row[:tag_sources]&.stringify_keys || initial_tag_sources(attributes, provenance)
tag_sources['manual'] = attributes['tags'].to_s if provenance['tags'] == 'manual'
url = row[:url].presence || values[@url_column].to_s.strip
provenance['url'] ||= row[:url].present? ? 'manual' : 'mapped'
attributes['url'] = url
@@ -27,9 +29,8 @@ class PostImportPreviewer
metadata, fetch_warnings = metadata_for(url, should_fetch, metadata_cache, fetch_warnings)
metadata.each do |field, value|
if field == 'tags' && provenance[field] != 'manual'
previous_origin = provenance[field]
attributes[field] = [attributes[field], value].compact.join(' ').split.uniq.join(' ')
provenance[field] = previous_origin == 'automatic' ? 'automatic' : previous_origin
tag_sources['automatic'] = value.to_s
attributes[field] = merged_tags(tag_sources)
next
end
next unless provenance[field] == 'automatic' || attributes[field].blank?
@@ -48,10 +49,11 @@ class PostImportPreviewer
@existing == 'error' ? errors[:url] = ['既存投稿です.'] : validation_warnings << '既存投稿のためスキップします.'
end
validate_basic_data(attributes, errors)
validate_preview_tags(attributes['tags'], errors, validation_warnings)
validate_preview_tags(merged_tags(tag_sources), errors, validation_warnings)
validate_parents(attributes['parent_post_ids'], errors)
attributes.delete('url')
{ source_row: row[:source_row], url: normal_url || url, attributes:, provenance:,
attributes['tags'] = merged_tags(tag_sources)
{ source_row: row[:source_row], url: normal_url || url, attributes:, provenance:, tag_sources:,
fetch_warnings:, validation_warnings:, warnings: fetch_warnings + validation_warnings, errors:,
status: errors.present? ? 'error' : ((fetch_warnings + validation_warnings).present? ? 'warning' : 'ready'),
existing: normal_url.present? && Post.exists?(url: normal_url) }
@@ -89,6 +91,16 @@ class PostImportPreviewer
}
end
def initial_tag_sources attributes, provenance
origin = provenance['tags'] == 'fixed' ? 'fixed' : 'mapped'
{ 'automatic' => '', 'mapped' => origin == 'mapped' ? attributes['tags'].to_s : '',
'fixed' => origin == 'fixed' ? attributes['tags'].to_s : '', 'manual' => '' }
end
def merged_tags sources
%w[automatic mapped fixed manual].flat_map { sources[_1].to_s.split }.uniq.join(' ')
end
def fetch_metadata url
return [{ }, ['URL が空です.']] if url.blank?