Skip to content

Commit

Permalink
Add ability to export bookmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire committed Oct 7, 2020
1 parent 5a9ad22 commit dcd8620
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
19 changes: 19 additions & 0 deletions app/controllers/settings/exports/bookmarks_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Settings
module Exports
class BookmarksController < BaseController
include ExportControllerConcern

def index
send_export_file
end

private

def export_data
@export.to_bookmarks_csv
end
end
end
end
12 changes: 12 additions & 0 deletions app/models/export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ def initialize(account)
@account = account
end

def to_bookmarks_csv
CSV.generate do |csv|
account.bookmarks.includes(:status).reorder(id: :desc).each do |bookmark|
csv << [ActivityPub::TagManager.instance.uri_for(bookmark.status)]
end
end
end

def to_blocked_accounts_csv
to_csv account.blocking.select(:username, :domain)
end
Expand Down Expand Up @@ -55,6 +63,10 @@ def total_statuses
account.statuses_count
end

def total_bookmarks
account.bookmarks.count
end

def total_follows
account.following_count
end
Expand Down
4 changes: 4 additions & 0 deletions app/views/settings/exports/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
%th= t('exports.domain_blocks')
%td= number_with_delimiter @export.total_domain_blocks
%td= table_link_to 'download', t('exports.csv'), settings_exports_domain_blocks_path(format: :csv)
%tr
%th= t('exports.bookmarks')
%td= number_with_delimiter @export.total_bookmarks
%td= table_link_to 'download', t('bookmarks.csv'), settings_exports_bookmarks_path(format: :csv)

%hr.spacer/

Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ en:
request: Request your archive
size: Size
blocks: You block
bookmarks: Bookmarks
csv: CSV
domain_blocks: Domain blocks
lists: Lists
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
resources :mutes, only: :index, controller: :muted_accounts
resources :lists, only: :index, controller: :lists
resources :domain_blocks, only: :index, controller: :blocked_domains
resources :bookmarks, only: :index, controller: :bookmarks
end

resources :two_factor_authentication_methods, only: [:index] do
Expand Down

0 comments on commit dcd8620

Please sign in to comment.