Merge 2.5.0rc1 from upstream
This commit is contained in:
commit
c29f828897
520 changed files with 15340 additions and 5799 deletions
55
lib/mastodon/accounts_cli.rb
Normal file
55
lib/mastodon/accounts_cli.rb
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rubygems/package'
|
||||
require_relative '../../config/boot'
|
||||
require_relative '../../config/environment'
|
||||
require_relative 'cli_helper'
|
||||
|
||||
module Mastodon
|
||||
class AccountsCLI < Thor
|
||||
option :all, type: :boolean
|
||||
desc 'rotate [USERNAME]', 'Generate and broadcast new keys'
|
||||
long_desc <<-LONG_DESC
|
||||
Generate and broadcast new RSA keys as part of security
|
||||
maintenance.
|
||||
|
||||
With the --all option, all local accounts will be subject
|
||||
to the rotation. Otherwise, and by default, only a single
|
||||
account specified by the USERNAME argument will be
|
||||
processed.
|
||||
LONG_DESC
|
||||
def rotate(username = nil)
|
||||
if options[:all]
|
||||
processed = 0
|
||||
delay = 0
|
||||
|
||||
Account.local.without_suspended.find_in_batches do |accounts|
|
||||
accounts.each do |account|
|
||||
rotate_keys_for_account(account, delay)
|
||||
processed += 1
|
||||
say('.', :green, false)
|
||||
end
|
||||
|
||||
delay += 5.minutes
|
||||
end
|
||||
|
||||
say
|
||||
say("OK, rotated keys for #{processed} accounts", :green)
|
||||
elsif username.present?
|
||||
rotate_keys_for_account(Account.find_local(username))
|
||||
say('OK', :green)
|
||||
else
|
||||
say('No account(s) given', :red)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def rotate_keys_for_account(account, delay = 0)
|
||||
old_key = account.private_key
|
||||
new_key = OpenSSL::PKey::RSA.new(2048).to_pem
|
||||
account.update(private_key: new_key)
|
||||
ActivityPub::UpdateDistributionWorker.perform_in(delay, account.id, sign_with: old_key)
|
||||
end
|
||||
end
|
||||
end
|
||||
8
lib/mastodon/cli_helper.rb
Normal file
8
lib/mastodon/cli_helper.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
dev_null = Logger.new('/dev/null')
|
||||
|
||||
Rails.logger = dev_null
|
||||
ActiveRecord::Base.logger = dev_null
|
||||
HttpLog.configuration.logger = dev_null
|
||||
Paperclip.options[:log] = false
|
||||
81
lib/mastodon/emoji_cli.rb
Normal file
81
lib/mastodon/emoji_cli.rb
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rubygems/package'
|
||||
require_relative '../../config/boot'
|
||||
require_relative '../../config/environment'
|
||||
require_relative 'cli_helper'
|
||||
|
||||
# rubocop:disable Rails/Output
|
||||
|
||||
module Mastodon
|
||||
class EmojiCLI < Thor
|
||||
option :prefix
|
||||
option :suffix
|
||||
option :overwrite, type: :boolean
|
||||
option :unlisted, type: :boolean
|
||||
desc 'import PATH', 'Import emoji from a TAR archive at PATH'
|
||||
long_desc <<-LONG_DESC
|
||||
Imports custom emoji from a TAR archive specified by PATH.
|
||||
|
||||
Existing emoji will be skipped unless the --overwrite option
|
||||
is provided, in which case they will be overwritten.
|
||||
|
||||
With the --prefix option, a prefix can be added to all
|
||||
generated shortcodes. Likewise, the --suffix option controls
|
||||
the suffix of all shortcodes.
|
||||
|
||||
With the --unlisted option, the processed emoji will not be
|
||||
visible in the emoji picker (but still usable via other means)
|
||||
LONG_DESC
|
||||
def import(path)
|
||||
imported = 0
|
||||
skipped = 0
|
||||
failed = 0
|
||||
|
||||
Gem::Package::TarReader.new(Zlib::GzipReader.open(path)) do |tar|
|
||||
tar.each do |entry|
|
||||
next unless entry.file? && entry.full_name.end_with?('.png')
|
||||
|
||||
shortcode = [options[:prefix], File.basename(entry.full_name, '.*'), options[:suffix]].compact.join
|
||||
custom_emoji = CustomEmoji.local.find_by(shortcode: shortcode)
|
||||
|
||||
if custom_emoji && !options[:overwrite]
|
||||
skipped += 1
|
||||
next
|
||||
end
|
||||
|
||||
custom_emoji ||= CustomEmoji.new(shortcode: shortcode, domain: nil)
|
||||
custom_emoji.image = StringIO.new(entry.read)
|
||||
custom_emoji.image_file_name = File.basename(entry.full_name)
|
||||
custom_emoji.visible_in_picker = !options[:unlisted]
|
||||
|
||||
if custom_emoji.save
|
||||
imported += 1
|
||||
else
|
||||
failed += 1
|
||||
say('Failure/Error: ', :red)
|
||||
say(entry.full_name)
|
||||
say(' ' + custom_emoji.errors[:image].join(', '), :red)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
puts
|
||||
say("Imported #{imported}, skipped #{skipped}, failed to import #{failed}", color(imported, skipped, failed))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def color(green, _yellow, red)
|
||||
if !green.zero? && red.zero?
|
||||
:green
|
||||
elsif red.zero?
|
||||
:yellow
|
||||
else
|
||||
:red
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# rubocop:enable Rails/Output
|
||||
55
lib/mastodon/media_cli.rb
Normal file
55
lib/mastodon/media_cli.rb
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../../config/boot'
|
||||
require_relative '../../config/environment'
|
||||
require_relative 'cli_helper'
|
||||
|
||||
# rubocop:disable Rails/Output
|
||||
|
||||
module Mastodon
|
||||
class MediaCLI < Thor
|
||||
option :days, type: :numeric, default: 7
|
||||
option :background, type: :boolean, default: false
|
||||
desc 'remove', 'Remove remote media files'
|
||||
long_desc <<-DESC
|
||||
Removes locally cached copies of media attachments from other servers.
|
||||
|
||||
The --days option specifies how old media attachments have to be before
|
||||
they are removed. It defaults to 7 days.
|
||||
|
||||
With the --background option, instead of deleting the files sequentially,
|
||||
they will be queued into Sidekiq and the command will exit as soon as
|
||||
possible. In Sidekiq they will be processed with higher concurrency, but
|
||||
it may impact other operations of the Mastodon server, and it may overload
|
||||
the underlying file storage.
|
||||
DESC
|
||||
def remove
|
||||
time_ago = options[:days].days.ago
|
||||
queued = 0
|
||||
processed = 0
|
||||
|
||||
MediaAttachment.where.not(remote_url: '').where.not(file_file_name: nil).where('created_at < ?', time_ago).select(:id).reorder(nil).find_in_batches do |media_attachments|
|
||||
if options[:background]
|
||||
queued += media_attachments.size
|
||||
Maintenance::UncacheMediaWorker.push_bulk(media_attachments.map(&:id))
|
||||
else
|
||||
media_attachments.each do |m|
|
||||
Maintenance::UncacheMediaWorker.new.perform(m)
|
||||
say('.', :green, false)
|
||||
processed += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
say
|
||||
|
||||
if options[:background]
|
||||
say("Scheduled the deletion of #{queued} media attachments", :green)
|
||||
else
|
||||
say("Removed #{processed} media attachments", :green)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# rubocop:enable Rails/Output
|
||||
|
|
@ -9,11 +9,11 @@ module Mastodon
|
|||
end
|
||||
|
||||
def minor
|
||||
4
|
||||
5
|
||||
end
|
||||
|
||||
def patch
|
||||
5
|
||||
0
|
||||
end
|
||||
|
||||
def pre
|
||||
|
|
@ -21,7 +21,7 @@ module Mastodon
|
|||
end
|
||||
|
||||
def flags
|
||||
''
|
||||
'rc1'
|
||||
end
|
||||
|
||||
def to_a
|
||||
|
|
@ -32,8 +32,12 @@ module Mastodon
|
|||
[to_a.join('.'), flags].join
|
||||
end
|
||||
|
||||
def repository
|
||||
'chinwagsocial/mastodon'
|
||||
end
|
||||
|
||||
def source_base_url
|
||||
'https://github.com/chinwagsocial/mastodon'
|
||||
"https://github.com/#{repository}"
|
||||
end
|
||||
|
||||
# specify git tag or commit hash here
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue