From d8a2a33306aa460f6fb33153d30cb53137990092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Tue, 3 Sep 2024 00:35:06 +0200 Subject: [PATCH] pl-api: support /api/v1/akkoma/preferred_frontend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- packages/pl-api/lib/client.ts | 24 ++++++++++++++++++++++++ packages/pl-api/lib/features.ts | 6 ++++++ packages/pl-api/package.json | 2 +- packages/pl-fe/package.json | 2 +- packages/pl-fe/yarn.lock | 8 ++++---- 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/packages/pl-api/lib/client.ts b/packages/pl-api/lib/client.ts index ac6a7c65a..b94415319 100644 --- a/packages/pl-api/lib/client.ts +++ b/packages/pl-api/lib/client.ts @@ -1406,6 +1406,30 @@ class PlApiClient { return interactionPoliciesSchema.parse(response.json); }, + + /** + * List frontend setting profiles + * + * Requires features{@link Features['preferredFrontends']}. + */ + getAvailableFrontends: async () => { + const response = await this.request('/api/v1/akkoma/preferred_frontend/available'); + + return z.array(z.string()).parse(response.json); + }, + + /** + * Update preferred frontend setting + * + * Store preferred frontend in cookies + * + * Requires features{@link Features['preferredFrontends']}. + */ + setPreferredFrontend: async (frontendName: string) => { + const response = await this.request('/api/v1/akkoma/preferred_frontend', { method: 'PUT', body: { frontend_name: frontendName } }); + + return z.object({ frontend_name: z.string() }).parse(response.json); + }, }; public readonly filtering = { diff --git a/packages/pl-api/lib/features.ts b/packages/pl-api/lib/features.ts index 553a7ae05..3b0da4188 100644 --- a/packages/pl-api/lib/features.ts +++ b/packages/pl-api/lib/features.ts @@ -876,6 +876,12 @@ const getFeatures = (instance?: Instance) => { v.software === GOTOSOCIAL, ]), + /** + * @see GET /api/v1/akkoma/preferred_frontend/available + * @see PUT /api/v1/akkoma/preferred_frontend + */ + preferredFrontends: v.software === PLEROMA && v.build === AKKOMA, + /** * Can set privacy scopes on statuses. * @see POST /api/v1/statuses diff --git a/packages/pl-api/package.json b/packages/pl-api/package.json index 4375fa3c5..c44d9242f 100644 --- a/packages/pl-api/package.json +++ b/packages/pl-api/package.json @@ -1,6 +1,6 @@ { "name": "pl-api", - "version": "0.0.26", + "version": "0.0.27", "type": "module", "homepage": "https://github.com/mkljczk/pl-fe/tree/fork/packages/pl-api", "repository": { diff --git a/packages/pl-fe/package.json b/packages/pl-fe/package.json index f9141205f..1169e5d90 100644 --- a/packages/pl-fe/package.json +++ b/packages/pl-fe/package.json @@ -133,7 +133,7 @@ "multiselect-react-dropdown": "^2.0.25", "object-to-formdata": "^4.5.1", "path-browserify": "^1.0.1", - "pl-api": "^0.0.26", + "pl-api": "^0.0.27", "postcss": "^8.4.29", "process": "^0.11.10", "punycode": "^2.1.1", diff --git a/packages/pl-fe/yarn.lock b/packages/pl-fe/yarn.lock index 56a476de8..70ca27281 100644 --- a/packages/pl-fe/yarn.lock +++ b/packages/pl-fe/yarn.lock @@ -8378,10 +8378,10 @@ pkg-types@^1.0.3: mlly "^1.2.0" pathe "^1.1.0" -pl-api@^0.0.26: - version "0.0.26" - resolved "https://registry.yarnpkg.com/pl-api/-/pl-api-0.0.26.tgz#82b20fa0500a22efaae643782ac917c725eef4ff" - integrity sha512-vbH11YmElHNpQZWM5G6nvgyQDp4q+G6IoMKqa7ek156UbuDBuZx/de2LYjlCJQ9nGtTzwNoOYRdtbLcshDKyiw== +pl-api@^0.0.27: + version "0.0.27" + resolved "https://registry.yarnpkg.com/pl-api/-/pl-api-0.0.27.tgz#8a9d52594a0d35da9364bbf769b84233827366e1" + integrity sha512-7u/mUexOcBwCa1d4LKZzhFp2bAYqGzfxVXh/RmgMVFd5+d57Kx6Itpzk3dHBJ4aHiE7NV2llEeG/SaYr7mUzuA== dependencies: blurhash "^2.0.5" http-link-header "^1.1.3"