このコミットが含まれているのは:
2026-07-11 23:21:59 +09:00
コミット 440d3d38be
5個のファイルの変更63行の追加27行の削除
+7 -4
ファイルの表示
@@ -1,9 +1,10 @@
class PostImportRunner
MAX_ROWS = PostImportSourceParser::MAX_ROWS
ATTRIBUTE_KEYS = %w[title thumbnail_base original_created_from original_created_before duration tags parent_post_ids video_ms].freeze
def initialize actor:, rows:
def initialize actor:, rows:, existing: 'skip'
@actor = actor
@rows = rows
@existing = existing == 'error' ? 'error' : 'skip'
end
def run
@@ -22,12 +23,14 @@ class PostImportRunner
raise ArgumentError, '取込項目が大きすぎます.' if attributes.values.any? { _1.to_s.bytesize > PostImportSourceParser::MAX_CELL_BYTES }
raise ArgumentError, 'URL が長すぎます.' if row['url'].to_s.bytesize > PostImportSourceParser::MAX_CELL_BYTES
preview = PostImportPreviewer.new(parsed: { columns: [], rows: [] }, url_column: 0,
mappings: {}, existing: 'error').preview_rows(
mappings: {}, existing: @existing).preview_rows(
rows: [{ source_row: row['source_row'], url: row['url'],
attributes:, provenance: row['provenance'] }],
attributes:, provenance: row['provenance'],
tag_sources: row['tag_sources'] }],
fetch_metadata: false).first
return { source_row: row['source_row'], status: 'failed', errors: preview[:errors] } if preview[:errors].present?
return row.slice('source_row').merge(status: 'skipped') if row['status'] == 'skipped' || preview[:existing]
return row.slice('source_row').merge(status: 'skipped') if @existing == 'skip' && preview[:existing]
attributes['tags'] = preview[:attributes]['tags']
attributes['url'] = row['url']
post = PostCreator.new(actor: @actor, attributes:).create!
{ source_row: row['source_row'], status: 'created', post: PostRepr.base(post) }