From ccfe65a6a4343f19a22af749bb25b75fb09f3c2b Mon Sep 17 00:00:00 2001 From: miteruzo Date: Sun, 12 Jul 2026 02:01:25 +0900 Subject: [PATCH] #399 --- backend/app/controllers/post_imports_controller.rb | 7 +++++-- backend/app/services/post_import_previewer.rb | 5 ++++- backend/app/services/post_import_runner.rb | 7 ++++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/backend/app/controllers/post_imports_controller.rb b/backend/app/controllers/post_imports_controller.rb index 1d8abe6..582d589 100644 --- a/backend/app/controllers/post_imports_controller.rb +++ b/backend/app/controllers/post_imports_controller.rb @@ -107,11 +107,14 @@ class PostImportsController < ApplicationController raise ArgumentError, 'タグ由来が大きすぎます.' end + source_row = Integer(normalised['source_row'], exception: false) + raise ArgumentError, '元行番号が不正です.' if source_row.nil? || source_row <= 0 + + normalised['source_row'] = source_row normalised.symbolize_keys 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 + if source_rows.uniq.length != source_rows.length raise ArgumentError, '元行番号が不正です.' end diff --git a/backend/app/services/post_import_previewer.rb b/backend/app/services/post_import_previewer.rb index 307c243..3ec1625 100644 --- a/backend/app/services/post_import_previewer.rb +++ b/backend/app/services/post_import_previewer.rb @@ -164,7 +164,10 @@ class PostImportPreviewer video_ms: parse_duration(attributes['duration'], errors)) post.valid? post.errors.each { |error| (errors[error.attribute] ||= []) << error.message } - errors.delete(:url) + if errors[:url] + errors[:url].reject! { |message| message.include?('すでに存在') || message.include?('taken') } + errors.delete(:url) if errors[:url].empty? + end end def parse_duration value, errors diff --git a/backend/app/services/post_import_runner.rb b/backend/app/services/post_import_runner.rb index 2b20dff..9b9a15a 100644 --- a/backend/app/services/post_import_runner.rb +++ b/backend/app/services/post_import_runner.rb @@ -90,6 +90,11 @@ class PostImportRunner raise ArgumentError, '取込行の形式が不正です.' end - row.to_h.deep_transform_keys { _1.to_s.underscore } + normalised = row.to_h.deep_transform_keys { _1.to_s.underscore } + source_row = Integer(normalised['source_row'], exception: false) + raise ArgumentError, '元行番号が不正です.' if source_row.nil? || source_row <= 0 + + normalised['source_row'] = source_row + normalised end end