You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
711 B

  1. # frozen_string_literal: true
  2. class Settings::ExportsController < Settings::BaseController
  3. include Authorization
  4. def show
  5. @export = Export.new(current_account)
  6. @backups = current_user.backups
  7. end
  8. def create
  9. raise Mastodon::NotPermittedError unless user_signed_in?
  10. backup = nil
  11. RedisLock.acquire(lock_options) do |lock|
  12. if lock.acquired?
  13. authorize :backup, :create?
  14. backup = current_user.backups.create!
  15. else
  16. raise Mastodon::RaceConditionError
  17. end
  18. end
  19. BackupWorker.perform_async(backup.id)
  20. redirect_to settings_export_path
  21. end
  22. def lock_options
  23. { redis: Redis.current, key: "backup:#{current_user.id}" }
  24. end
  25. end