このコミットが含まれているのは:
@@ -78,7 +78,7 @@ class PostImportsController < ApplicationController
|
|||||||
rows = Array(params[:rows])
|
rows = Array(params[:rows])
|
||||||
raise ArgumentError, '取込件数が多すぎます.' if rows.length > PostImportSourceParser::MAX_ROWS
|
raise ArgumentError, '取込件数が多すぎます.' if rows.length > PostImportSourceParser::MAX_ROWS
|
||||||
|
|
||||||
rows.map do |row|
|
normalised_rows = rows.map do |row|
|
||||||
value = ActionController::Parameters.new(row).permit(:source_row, :sourceRow, :url, :metadata_url, :metadataUrl,
|
value = ActionController::Parameters.new(row).permit(:source_row, :sourceRow, :url, :metadata_url, :metadataUrl,
|
||||||
attributes: {}, provenance: {}, tag_sources: {},
|
attributes: {}, provenance: {}, tag_sources: {},
|
||||||
fetch_warnings: [], validation_warnings: [])
|
fetch_warnings: [], validation_warnings: [])
|
||||||
@@ -109,5 +109,12 @@ class PostImportsController < ApplicationController
|
|||||||
|
|
||||||
normalised.symbolize_keys
|
normalised.symbolize_keys
|
||||||
end
|
end
|
||||||
|
source_rows = normalised_rows.map { _1[:source_row] }
|
||||||
|
if source_rows.any? { |value| Integer(value, exception: false).to_i <= 0 } ||
|
||||||
|
source_rows.uniq.length != source_rows.length
|
||||||
|
raise ArgumentError, '元行番号が不正です.'
|
||||||
|
end
|
||||||
|
|
||||||
|
normalised_rows
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -47,10 +47,9 @@ class PostImportPreviewer
|
|||||||
attributes[field] = value
|
attributes[field] = value
|
||||||
provenance[field] = 'automatic'
|
provenance[field] = 'automatic'
|
||||||
end
|
end
|
||||||
post = Post.new(url:)
|
normal_url = normalised_url(url)
|
||||||
post.valid?
|
errors = { }
|
||||||
normal_url = post.url
|
errors[:url] = ['URL が不正です.'] if normal_url.blank?
|
||||||
errors = post.errors.to_hash.transform_values(&:dup)
|
|
||||||
validation_warnings = []
|
validation_warnings = []
|
||||||
errors[:url] = ['URL が重複しています.'] if normal_url.present? && urls.key?(normal_url)
|
errors[:url] = ['URL が重複しています.'] if normal_url.present? && urls.key?(normal_url)
|
||||||
urls[normal_url] = true if normal_url.present?
|
urls[normal_url] = true if normal_url.present?
|
||||||
@@ -165,6 +164,7 @@ class PostImportPreviewer
|
|||||||
video_ms: parse_duration(attributes['duration'], errors))
|
video_ms: parse_duration(attributes['duration'], errors))
|
||||||
post.valid?
|
post.valid?
|
||||||
post.errors.each { |error| (errors[error.attribute] ||= []) << error.message }
|
post.errors.each { |error| (errors[error.attribute] ||= []) << error.message }
|
||||||
|
errors.delete(:url)
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_duration value, errors
|
def parse_duration value, errors
|
||||||
|
|||||||
@@ -11,7 +11,11 @@ class PostImportRunner
|
|||||||
raise ArgumentError, "取込件数は #{ MAX_ROWS } 件までです." if @rows.length > MAX_ROWS
|
raise ArgumentError, "取込件数は #{ MAX_ROWS } 件までです." if @rows.length > MAX_ROWS
|
||||||
raise ArgumentError, '取込データが大きすぎます.' if @rows.sum { |row| row.to_json.bytesize } > PostImportSourceParser::MAX_BYTES
|
raise ArgumentError, '取込データが大きすぎます.' if @rows.sum { |row| row.to_json.bytesize } > PostImportSourceParser::MAX_BYTES
|
||||||
|
|
||||||
results = @rows.map { |row| run_row(normalise_row(row)) }
|
normalised_rows = @rows.map { |row| normalise_row(row) }
|
||||||
|
source_rows = normalised_rows.map { _1['source_row'] }
|
||||||
|
raise ArgumentError, '元行番号が重複しています.' if source_rows.uniq.length != source_rows.length
|
||||||
|
|
||||||
|
results = normalised_rows.map { |row| run_row(row) }
|
||||||
{ created: results.count { _1[:status] == 'created' }, skipped: results.count { _1[:status] == 'skipped' },
|
{ created: results.count { _1[:status] == 'created' }, skipped: results.count { _1[:status] == 'skipped' },
|
||||||
failed: results.count { _1[:status] == 'failed' }, rows: results }
|
failed: results.count { _1[:status] == 'failed' }, rows: results }
|
||||||
end
|
end
|
||||||
@@ -77,6 +81,8 @@ class PostImportRunner
|
|||||||
raise ArgumentError unless metadata_url.nil? || metadata_url.is_a?(String)
|
raise ArgumentError unless metadata_url.nil? || metadata_url.is_a?(String)
|
||||||
raise ArgumentError if metadata_url.to_s.bytesize > PostImportSourceParser::MAX_CELL_BYTES
|
raise ArgumentError if metadata_url.to_s.bytesize > PostImportSourceParser::MAX_CELL_BYTES
|
||||||
raise ArgumentError if row.to_json.bytesize > PostImportSourceParser::MAX_BYTES
|
raise ArgumentError if row.to_json.bytesize > PostImportSourceParser::MAX_BYTES
|
||||||
|
tag_sources = row['tag_sources']
|
||||||
|
raise ArgumentError unless tag_sources.nil? || tag_sources.is_a?(Hash)
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalise_row row
|
def normalise_row row
|
||||||
|
|||||||
新しい課題から参照
ユーザをブロックする