Add API endpoint /api/pleroma/follow_export to get your followers in Mastodon-compatible CSV format

This is the same format we support for importing users.
This commit is contained in:
Mark Felder 2022-11-17 14:24:14 -05:00
parent 1aa54da4d9
commit 53b1b1a529
2 changed files with 30 additions and 0 deletions

View file

@ -0,0 +1,28 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaAPI.UserExportController do
use Pleroma.Web, :controller
require Logger
alias Pleroma.User
alias Pleroma.Web.Plugs.OAuthScopesPlug
plug(OAuthScopesPlug, %{scopes: ["follow", "read:follows"]} when action == :following)
@following_accounts_header "Account address,Show boosts,Notify on new posts,Languages\n"
def following(%{assigns: %{user: follower}} = conn, _) do
friends = User.get_friends_nicknames(follower) |> Enum.join(",true,false,\n")
csv_data = @following_accounts_header <> friends <> ",true,false,"
conn
|> put_resp_content_type("text/csv")
|> put_resp_header("content-disposition", "attachment; filename=\"following_accounts.csv\"")
|> put_root_layout(false)
|> send_resp(200, csv_data)
end
end

View file

@ -364,6 +364,8 @@ defmodule Pleroma.Web.Router do
post("/blocks_import", UserImportController, :blocks)
post("/follow_import", UserImportController, :follow)
get("/follow_export", UserExportController, :following)
get("/accounts/mfa", TwoFactorAuthenticationController, :settings)
get("/accounts/mfa/backup_codes", TwoFactorAuthenticationController, :backup_codes)
get("/accounts/mfa/setup/:method", TwoFactorAuthenticationController, :setup)