From 501a8882fc1e0a5e33dc75827f4f751228986dab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicole=20Miko=C5=82ajczyk?= Date: Sat, 31 May 2025 22:30:15 +0200 Subject: [PATCH] pl-api: support gotosocial csv exports api MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicole Mikołajczyk --- packages/pl-api/lib/client.ts | 67 +++++++++++++++++++++++++++++++-- packages/pl-api/lib/features.ts | 30 ++++++++++++++- 2 files changed, 91 insertions(+), 6 deletions(-) diff --git a/packages/pl-api/lib/client.ts b/packages/pl-api/lib/client.ts index d98d3b748..1a7dfe840 100644 --- a/packages/pl-api/lib/client.ts +++ b/packages/pl-api/lib/client.ts @@ -1859,9 +1859,19 @@ class PlApiClient { * Requires features{@link Features.exportFollowers}. */ exportFollowers: async () => { - const response = await this.request('/api/v1/settings/export_followers', { - method: 'GET', - }); + let response; + + switch (this.features.version.software) { + case GOTOSOCIAL: + response = await this.request('/api/v1/exports/followers.csv', { + method: 'GET', + }); + break; + default: + response = await this.request('/api/v1/settings/export_followers', { + method: 'GET', + }); + } return response.data; }, @@ -1872,7 +1882,56 @@ class PlApiClient { * Requires features{@link Features.exportFollows}. */ exportFollows: async () => { - const response = await this.request('/api/v1/settings/export_follows', { + let response; + + switch (this.features.version.software) { + case GOTOSOCIAL: + response = await this.request('/api/v1/exports/following.csv', { + method: 'GET', + }); + break; + default: + response = await this.request('/api/v1/settings/export_follows', { + method: 'GET', + }); + } + + return response.data; + }, + + /** + * Export lists to CSV file + * + * Requires features{@link Features.exportLists}. + */ + exportLists: async () => { + const response = await this.request('/api/v1/exports/lists.csv', { + method: 'GET', + }); + + return response.data; + }, + + /** + * Export blocks to CSV file + * + * Requires features{@link Features.exportBlocks}. + */ + exportBlocks: async () => { + const response = await this.request('/api/v1/exports/blocks.csv', { + method: 'GET', + }); + + return response.data; + }, + + /** + * Export mutes to CSV file + * + * Requires features{@link Features.exportMutes}. + */ + exportMutes: async () => { + const response = await this.request('/api/v1/exports/mutes.csv', { method: 'GET', }); diff --git a/packages/pl-api/lib/features.ts b/packages/pl-api/lib/features.ts index bffe9e883..2c5602b7e 100644 --- a/packages/pl-api/lib/features.ts +++ b/packages/pl-api/lib/features.ts @@ -693,17 +693,43 @@ const getFeatures = (instance: Instance) => { */ events: instance.api_versions['events.pleroma.pl-api'] >= 1, + /** + * Export blocks to CSV file + * @see GET /api/v1/exports/blocks.csv + */ + exportBlocks: v.software === GOTOSOCIAL && gte(v.version, '0.17.0'), + /** * Export followers to CSV file + * @see GET /api/v1/exports/followers.csv * @see GET /api/v1/settings/export_followers */ - exportFollowers: v.software === MITRA && gte(v.version, '1.27.0'), + exportFollowers: any([ + v.software === GOTOSOCIAL && gte(v.version, '0.17.0'), + v.software === MITRA && gte(v.version, '1.27.0'), + ]), /** * Export follows to CSV file + * @see GET /api/v1/exports/following.csv * @see GET /api/v1/settings/export_follows */ - exportFollows: v.software === MITRA && gte(v.version, '1.27.0'), + exportFollows: any([ + v.software === GOTOSOCIAL && gte(v.version, '0.17.0'), + v.software === MITRA && gte(v.version, '1.27.0'), + ]), + + /** + * Export lists to CSV file + * @see GET /api/v1/exports/lists.csv + */ + exportLists: v.software === GOTOSOCIAL && gte(v.version, '0.17.0'), + + /** + * Export mutes to CSV file + * @see GET /api/v1/exports/mutes.csv + */ + exportMutes: v.software === GOTOSOCIAL && gte(v.version, '0.17.0'), /** Whether the accounts who favourited or emoji-reacted to a status can be viewed through the API. */ exposableReactions: any([