Add '--days' option to tootctl media refresh (#18425)

* Add '--days' option to tootctl media refresh

* Fix undefined scope
This commit is contained in:
Jeong Arm 2022-08-25 11:40:17 +09:00 committed by GitHub
parent 63a5514b29
commit e682975afd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -187,6 +187,7 @@ module Mastodon
option :account, type: :string option :account, type: :string
option :domain, type: :string option :domain, type: :string
option :status, type: :numeric option :status, type: :numeric
option :days, type: :numeric
option :concurrency, type: :numeric, default: 5, aliases: [:c] option :concurrency, type: :numeric, default: 5, aliases: [:c]
option :verbose, type: :boolean, default: false, aliases: [:v] option :verbose, type: :boolean, default: false, aliases: [:v]
option :dry_run, type: :boolean, default: false option :dry_run, type: :boolean, default: false
@ -204,6 +205,8 @@ module Mastodon
Use the --domain option to download attachments from a specific domain. Use the --domain option to download attachments from a specific domain.
Use the --days option to limit attachments created within days.
By default, attachments that are believed to be already downloaded will By default, attachments that are believed to be already downloaded will
not be re-downloaded. To force re-download of every URL, use --force. not be re-downloaded. To force re-download of every URL, use --force.
DESC DESC
@ -224,10 +227,16 @@ module Mastodon
scope = MediaAttachment.where(account_id: account.id) scope = MediaAttachment.where(account_id: account.id)
elsif options[:domain] elsif options[:domain]
scope = MediaAttachment.joins(:account).merge(Account.by_domain_and_subdomains(options[:domain])) scope = MediaAttachment.joins(:account).merge(Account.by_domain_and_subdomains(options[:domain]))
elsif options[:days].present?
scope = MediaAttachment.remote
else else
exit(1) exit(1)
end end
if options[:days].present?
scope = scope.where('id > ?', Mastodon::Snowflake.id_at(options[:days].days.ago, with_random: false))
end
processed, aggregate = parallelize_with_progress(scope) do |media_attachment| processed, aggregate = parallelize_with_progress(scope) do |media_attachment|
next if media_attachment.remote_url.blank? || (!options[:force] && media_attachment.file_file_name.present?) next if media_attachment.remote_url.blank? || (!options[:force] && media_attachment.file_file_name.present?)
next if DomainBlock.reject_media?(media_attachment.account.domain) next if DomainBlock.reject_media?(media_attachment.account.domain)