このコミットが含まれているのは:
2026-07-12 01:17:45 +09:00
コミット 10dc776313
3個のファイルの変更35行の追加16行の削除
+2 -1
ファイルの表示
@@ -57,7 +57,8 @@ class PostImportPreviewer
attributes['tags'] = merged_tags(tag_sources, provenance['tags'])
{ source_row: row[:source_row], url: normal_url || url, attributes:, provenance:, tag_sources:,
metadata_url: url,
fetch_warnings:, validation_warnings:, warnings: fetch_warnings + validation_warnings, errors:,
fetch_warnings:, validation_warnings:, warnings: fetch_warnings + validation_warnings,
validation_errors: errors, errors:,
status: errors.present? ? 'error' : ((fetch_warnings + validation_warnings).present? ? 'warning' : 'ready'),
existing: normal_url.present? && Post.exists?(url: normal_url) }
end
+9 -2
ファイルの表示
@@ -43,11 +43,18 @@ class PostImportSourceParser
raise ArgumentError, 'JSON の投稿候補は配列にしてください.' unless value.is_a?(Array)
ensure_limits!(value)
keys = value.grep(Hash).flat_map(&:keys).map(&:to_s).uniq
unless value.all?(Hash)
invalid = value.each_with_index.filter_map { |item, index| index + 1 unless item.is_a?(Hash) }
raise ArgumentError, "JSON の投稿候補は object の配列にしてください: 行 #{ invalid.join(', ') }"
end
keys = value.flat_map(&:keys).map(&:to_s).uniq
raise ArgumentError, "列数は #{ MAX_COLUMNS } 列までです." if keys.length > MAX_COLUMNS
{ columns: keys.each_with_index.map { |key, index| { key:, label: "#{ column_name(index) }#{ key }" } },
rows: value.each_with_index.map { |item, index| { source_row: index + 1,
values: keys.map { json_cell(item.is_a?(Hash) ? item[_1] || item[_1.to_sym] : nil) } } } }
values: keys.map { |key|
value = item.key?(key) ? item[key] : item[key.to_sym]
json_cell(value)
} } } }
rescue JSON::ParserError, KeyError, ArgumentError => e
raise ArgumentError, "JSON の形式が不正です: #{ e.message }"
end