|
|
@ -35,12 +35,12 @@ module Mastodon::CLI
|
|
|
|
say('--prune-profiles and --remove-headers should not be specified simultaneously', :red, true)
|
|
|
|
say('--prune-profiles and --remove-headers should not be specified simultaneously', :red, true)
|
|
|
|
exit(1)
|
|
|
|
exit(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if options[:include_follows] && !(options[:prune_profiles] || options[:remove_headers])
|
|
|
|
if options[:include_follows] && !(options[:prune_profiles] || options[:remove_headers])
|
|
|
|
say('--include-follows can only be used with --prune-profiles or --remove-headers', :red, true)
|
|
|
|
say('--include-follows can only be used with --prune-profiles or --remove-headers', :red, true)
|
|
|
|
exit(1)
|
|
|
|
exit(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
time_ago = options[:days].days.ago
|
|
|
|
time_ago = options[:days].days.ago
|
|
|
|
dry_run = options[:dry_run] ? ' (DRY RUN)' : ''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if options[:prune_profiles] || options[:remove_headers]
|
|
|
|
if options[:prune_profiles] || options[:remove_headers]
|
|
|
|
processed, aggregate = parallelize_with_progress(Account.remote.where({ last_webfingered_at: ..time_ago, updated_at: ..time_ago })) do |account|
|
|
|
|
processed, aggregate = parallelize_with_progress(Account.remote.where({ last_webfingered_at: ..time_ago, updated_at: ..time_ago })) do |account|
|
|
|
@ -51,7 +51,7 @@ module Mastodon::CLI
|
|
|
|
size = (account.header_file_size || 0)
|
|
|
|
size = (account.header_file_size || 0)
|
|
|
|
size += (account.avatar_file_size || 0) if options[:prune_profiles]
|
|
|
|
size += (account.avatar_file_size || 0) if options[:prune_profiles]
|
|
|
|
|
|
|
|
|
|
|
|
unless options[:dry_run]
|
|
|
|
unless dry_run?
|
|
|
|
account.header.destroy
|
|
|
|
account.header.destroy
|
|
|
|
account.avatar.destroy if options[:prune_profiles]
|
|
|
|
account.avatar.destroy if options[:prune_profiles]
|
|
|
|
account.save!
|
|
|
|
account.save!
|
|
|
@ -60,7 +60,7 @@ module Mastodon::CLI
|
|
|
|
size
|
|
|
|
size
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
say("Visited #{processed} accounts and removed profile media totaling #{number_to_human_size(aggregate)}#{dry_run}", :green, true)
|
|
|
|
say("Visited #{processed} accounts and removed profile media totaling #{number_to_human_size(aggregate)}#{dry_run_mode_suffix}", :green, true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
unless options[:prune_profiles] || options[:remove_headers]
|
|
|
|
unless options[:prune_profiles] || options[:remove_headers]
|
|
|
@ -69,7 +69,7 @@ module Mastodon::CLI
|
|
|
|
|
|
|
|
|
|
|
|
size = (media_attachment.file_file_size || 0) + (media_attachment.thumbnail_file_size || 0)
|
|
|
|
size = (media_attachment.file_file_size || 0) + (media_attachment.thumbnail_file_size || 0)
|
|
|
|
|
|
|
|
|
|
|
|
unless options[:dry_run]
|
|
|
|
unless dry_run?
|
|
|
|
media_attachment.file.destroy
|
|
|
|
media_attachment.file.destroy
|
|
|
|
media_attachment.thumbnail.destroy
|
|
|
|
media_attachment.thumbnail.destroy
|
|
|
|
media_attachment.save
|
|
|
|
media_attachment.save
|
|
|
@ -78,7 +78,7 @@ module Mastodon::CLI
|
|
|
|
size
|
|
|
|
size
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
say("Removed #{processed} media attachments (approx. #{number_to_human_size(aggregate)})#{dry_run}", :green, true)
|
|
|
|
say("Removed #{processed} media attachments (approx. #{number_to_human_size(aggregate)})#{dry_run_mode_suffix}", :green, true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -97,7 +97,6 @@ module Mastodon::CLI
|
|
|
|
progress = create_progress_bar(nil)
|
|
|
|
progress = create_progress_bar(nil)
|
|
|
|
reclaimed_bytes = 0
|
|
|
|
reclaimed_bytes = 0
|
|
|
|
removed = 0
|
|
|
|
removed = 0
|
|
|
|
dry_run = options[:dry_run] ? ' (DRY RUN)' : ''
|
|
|
|
|
|
|
|
prefix = options[:prefix]
|
|
|
|
prefix = options[:prefix]
|
|
|
|
|
|
|
|
|
|
|
|
case Paperclip::Attachment.default_options[:storage]
|
|
|
|
case Paperclip::Attachment.default_options[:storage]
|
|
|
@ -123,7 +122,7 @@ module Mastodon::CLI
|
|
|
|
record_map = preload_records_from_mixed_objects(objects)
|
|
|
|
record_map = preload_records_from_mixed_objects(objects)
|
|
|
|
|
|
|
|
|
|
|
|
objects.each do |object|
|
|
|
|
objects.each do |object|
|
|
|
|
object.acl.put(acl: s3_permissions) if options[:fix_permissions] && !options[:dry_run]
|
|
|
|
object.acl.put(acl: s3_permissions) if options[:fix_permissions] && !dry_run?
|
|
|
|
|
|
|
|
|
|
|
|
path_segments = object.key.split('/')
|
|
|
|
path_segments = object.key.split('/')
|
|
|
|
path_segments.delete('cache')
|
|
|
|
path_segments.delete('cache')
|
|
|
@ -145,7 +144,7 @@ module Mastodon::CLI
|
|
|
|
next unless attachment.blank? || !attachment.variant?(file_name)
|
|
|
|
next unless attachment.blank? || !attachment.variant?(file_name)
|
|
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
object.delete unless options[:dry_run]
|
|
|
|
object.delete unless dry_run?
|
|
|
|
|
|
|
|
|
|
|
|
reclaimed_bytes += object.size
|
|
|
|
reclaimed_bytes += object.size
|
|
|
|
removed += 1
|
|
|
|
removed += 1
|
|
|
@ -194,7 +193,7 @@ module Mastodon::CLI
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
size = File.size(path)
|
|
|
|
size = File.size(path)
|
|
|
|
|
|
|
|
|
|
|
|
unless options[:dry_run]
|
|
|
|
unless dry_run?
|
|
|
|
File.delete(path)
|
|
|
|
File.delete(path)
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
FileUtils.rmdir(File.dirname(path), parents: true)
|
|
|
|
FileUtils.rmdir(File.dirname(path), parents: true)
|
|
|
@ -216,7 +215,7 @@ module Mastodon::CLI
|
|
|
|
progress.total = progress.progress
|
|
|
|
progress.total = progress.progress
|
|
|
|
progress.finish
|
|
|
|
progress.finish
|
|
|
|
|
|
|
|
|
|
|
|
say("Removed #{removed} orphans (approx. #{number_to_human_size(reclaimed_bytes)})#{dry_run}", :green, true)
|
|
|
|
say("Removed #{removed} orphans (approx. #{number_to_human_size(reclaimed_bytes)})#{dry_run_mode_suffix}", :green, true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
option :account, type: :string
|
|
|
|
option :account, type: :string
|
|
|
@ -246,8 +245,6 @@ module Mastodon::CLI
|
|
|
|
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
|
|
|
|
def refresh
|
|
|
|
def refresh
|
|
|
|
dry_run = options[:dry_run] ? ' (DRY RUN)' : ''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if options[:status]
|
|
|
|
if options[:status]
|
|
|
|
scope = MediaAttachment.where(status_id: options[:status])
|
|
|
|
scope = MediaAttachment.where(status_id: options[:status])
|
|
|
|
elsif options[:account]
|
|
|
|
elsif options[:account]
|
|
|
@ -274,7 +271,7 @@ module Mastodon::CLI
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
unless options[:dry_run]
|
|
|
|
unless dry_run?
|
|
|
|
media_attachment.reset_file!
|
|
|
|
media_attachment.reset_file!
|
|
|
|
media_attachment.reset_thumbnail!
|
|
|
|
media_attachment.reset_thumbnail!
|
|
|
|
media_attachment.save
|
|
|
|
media_attachment.save
|
|
|
@ -283,7 +280,7 @@ module Mastodon::CLI
|
|
|
|
media_attachment.file_file_size + (media_attachment.thumbnail_file_size || 0)
|
|
|
|
media_attachment.file_file_size + (media_attachment.thumbnail_file_size || 0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
say("Downloaded #{processed} media attachments (approx. #{number_to_human_size(aggregate)})#{dry_run}", :green, true)
|
|
|
|
say("Downloaded #{processed} media attachments (approx. #{number_to_human_size(aggregate)})#{dry_run_mode_suffix}", :green, true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
desc 'usage', 'Calculate disk space consumed by Mastodon'
|
|
|
|
desc 'usage', 'Calculate disk space consumed by Mastodon'
|
|
|
|