闭社主体 forked from https://github.com/tootsuite/mastodon
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.

87 lines
1.5 KiB

  1. # frozen_string_literal: true
  2. require 'csv'
  3. class Export
  4. attr_reader :account
  5. def initialize(account)
  6. @account = account
  7. end
  8. def to_blocked_accounts_csv
  9. to_csv account.blocking.select(:username, :domain)
  10. end
  11. def to_muted_accounts_csv
  12. to_csv account.muting.select(:username, :domain)
  13. end
  14. def to_following_accounts_csv
  15. to_csv account.following.select(:username, :domain)
  16. end
  17. def to_lists_csv
  18. CSV.generate do |csv|
  19. account.owned_lists.select(:title, :id).each do |list|
  20. list.accounts.select(:username, :domain).each do |account|
  21. csv << [list.title, acct(account)]
  22. end
  23. end
  24. end
  25. end
  26. def to_blocked_domains_csv
  27. CSV.generate do |csv|
  28. account.domain_blocks.pluck(:domain).each do |domain|
  29. csv << [domain]
  30. end
  31. end
  32. end
  33. def total_storage
  34. account.media_attachments.sum(:file_file_size)
  35. end
  36. def total_statuses
  37. account.statuses_count
  38. end
  39. def total_follows
  40. account.following_count
  41. end
  42. def total_lists
  43. account.owned_lists.count
  44. end
  45. def total_followers
  46. account.followers_count
  47. end
  48. def total_blocks
  49. account.blocking.count
  50. end
  51. def total_mutes
  52. account.muting.count
  53. end
  54. def total_domain_blocks
  55. account.domain_blocks.count
  56. end
  57. private
  58. def to_csv(accounts)
  59. CSV.generate do |csv|
  60. accounts.each do |account|
  61. csv << [acct(account)]
  62. end
  63. end
  64. end
  65. def acct(account)
  66. account.local? ? account.local_username_and_domain : account.acct
  67. end
  68. end