Import seems to work!

This commit is contained in:
Evan Summers 2025-08-07 22:28:58 +02:00
parent dbdf20b373
commit d8725ea554
3 changed files with 19 additions and 2 deletions

View File

@ -57,6 +57,8 @@ class Settings::ImportsController < Settings::BaseController
csv << [row.data['uri']]
when :lists
csv << [row.data['list_name'], row.data['acct']]
when :filters
csv << [row.data['title'], row.data['context'], row.data['keywords'], row.data['action'], row.data['expires_at']]
end
end
end

View File

@ -33,6 +33,13 @@ class Form::Import
'#domain' => 'domain',
'#uri' => 'uri',
'List name' => 'list_name',
# Filters
'Title' => 'title',
'Context' => 'context',
'Keywords' => 'keywords',
'Action' => 'action',
'Expire after' => 'expires_at',
}.freeze
class EmptyFileError < StandardError; end
@ -114,10 +121,11 @@ class Form::Import
return @csv_data if defined?(@csv_data)
csv_converter = lambda do |field, field_info|
if :type == :filters
case type.to_sym
when :filters
case field_info.header
when 'Context', 'Keywords'
field&.split(',')&.map(&:strip)&.presence
Oj.load(field)
when 'Expire after'
field.blank? ? nil : Time.zone.parse(field)
else

View File

@ -39,6 +39,13 @@ class BulkImportRowService
FollowService.new.call(@account, @target_account) unless @account.id == @target_account.id
list.accounts << @target_account
when :filters
filter = @account.custom_filters.find_or_initialize_by(title: @data['title'])
filter.context = @data['context']
filter.keywords = @data['keywords'].map { |keyword| CustomFilterKeyword.new(keyword: keyword) }
filter.action = @data['action'].to_sym
filter.expires_at = @data['expires_at']
filter.save!
end
true