From c1ff4c516d436ee296129e1750c41a5454d6a969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicole=20Miko=C5=82ajczyk?= Date: Fri, 4 Apr 2025 22:01:29 +0200 Subject: [PATCH] pl-api: support importing mutes on gotosocial 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 | 25 ++++++++++++++----- packages/pl-api/lib/features.ts | 2 ++ packages/pl-api/package.json | 2 +- packages/pl-fe/package.json | 2 +- .../pl-fe/src/features/import-data/index.tsx | 2 +- packages/pl-fe/yarn.lock | 8 +++--- 6 files changed, 28 insertions(+), 13 deletions(-) diff --git a/packages/pl-api/lib/client.ts b/packages/pl-api/lib/client.ts index 522afdedc..a56df96a1 100644 --- a/packages/pl-api/lib/client.ts +++ b/packages/pl-api/lib/client.ts @@ -1581,14 +1581,27 @@ class PlApiClient { * Imports your mutes. * * Requires features{@link Features['importMutes']}. + * `overwrite` mode requires features{@link Features['importOverwrite']}. * @see {@link https://docs.pleroma.social/backend/development/API/pleroma_api/#apipleromamutes_import} */ - importMutes: async (list: File | string) => { - const response = await this.request('/api/pleroma/mutes_import', { - method: 'POST', - body: { list }, - contentType: '', - }); + importMutes: async (list: File | string, mode?: 'merge' | 'overwrite') => { + let response; + + switch (this.features.version.software) { + case GOTOSOCIAL: + response = await this.request('/api/v1/import', { + method: 'POST', + body: { data: list, type: 'blocks', mode }, + contentType: '', + }); + break; + default: + response = await this.request('/api/pleroma/mutes_import', { + method: 'POST', + body: { list }, + contentType: '', + }); + } return response.json; }, diff --git a/packages/pl-api/lib/features.ts b/packages/pl-api/lib/features.ts index 86d90cb18..f380bc7f8 100644 --- a/packages/pl-api/lib/features.ts +++ b/packages/pl-api/lib/features.ts @@ -837,9 +837,11 @@ const getFeatures = (instance: Instance) => { /** * Import a .csv file with a list of muted users. * @see POST /api/pleroma/mutes_import + * @see POST /api/v1/import */ importMutes: any([ v.software === AKKOMA, + v.software === GOTOSOCIAL && gte(v.version, '0.19.0'), v.software === PLEROMA, ]), diff --git a/packages/pl-api/package.json b/packages/pl-api/package.json index 413c92501..e40853aa0 100644 --- a/packages/pl-api/package.json +++ b/packages/pl-api/package.json @@ -1,6 +1,6 @@ { "name": "pl-api", - "version": "1.0.0-rc.39", + "version": "1.0.0-rc.40", "type": "module", "homepage": "https://github.com/mkljczk/pl-fe/tree/develop/packages/pl-api", "repository": { diff --git a/packages/pl-fe/package.json b/packages/pl-fe/package.json index 591cda997..f40bde379 100644 --- a/packages/pl-fe/package.json +++ b/packages/pl-fe/package.json @@ -104,7 +104,7 @@ "multiselect-react-dropdown": "^2.0.25", "mutative": "^1.1.0", "path-browserify": "^1.0.1", - "pl-api": "^1.0.0-rc.39", + "pl-api": "^1.0.0-rc.40", "postcss": "^8.4.49", "process": "^0.11.10", "punycode": "^2.1.1", diff --git a/packages/pl-fe/src/features/import-data/index.tsx b/packages/pl-fe/src/features/import-data/index.tsx index d46c9b6da..ef322cb4f 100644 --- a/packages/pl-fe/src/features/import-data/index.tsx +++ b/packages/pl-fe/src/features/import-data/index.tsx @@ -42,7 +42,7 @@ const ImportData = () => { {features.importFollows && } {features.importBlocks && } - {features.importMutes && } + {features.importMutes && } ); }; diff --git a/packages/pl-fe/yarn.lock b/packages/pl-fe/yarn.lock index 824380d49..9574494a6 100644 --- a/packages/pl-fe/yarn.lock +++ b/packages/pl-fe/yarn.lock @@ -6833,10 +6833,10 @@ pkg-dir@^4.1.0: dependencies: find-up "^4.0.0" -pl-api@^1.0.0-rc.39: - version "1.0.0-rc.39" - resolved "https://registry.yarnpkg.com/pl-api/-/pl-api-1.0.0-rc.39.tgz#47ed57e0ea0602c45b7105d1727b3ff52e09dbba" - integrity sha512-5U1ni9+HQrG9xVcNdlw4VSUJoxcqdgLXUttAH7gxo9jdMMqPLK/c4WLKbyERTM0jn1HubrTPSnDCFZpyvO68hA== +pl-api@^1.0.0-rc.40: + version "1.0.0-rc.40" + resolved "https://registry.yarnpkg.com/pl-api/-/pl-api-1.0.0-rc.40.tgz#ae2596a15d28a8662d1a5de083b9596a8b6c00b3" + integrity sha512-4X7va+KXOcXAOD02W+4e6NHgD+pbxhIoeHxT9rcWdHDjxmWiCapBoxxxa88ASPZKZFoiXZAktsFRSEs9yM3Z6A== dependencies: blurhash "^2.0.5" http-link-header "^1.1.3"