pl-api: Support session management on Mitra

Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
nicole mikołajczyk
2025-11-26 07:15:53 +01:00
parent ecfe7564c9
commit 66b993faa1
3 changed files with 29 additions and 5 deletions

View File

@ -1475,11 +1475,23 @@ class PlApiClient {
* Requires features{@link Features.sessions}.
* @see {@link https://docs.pleroma.social/backend/development/API/pleroma_api/#get-apioauth_tokens}
*/
getOauthTokens: () => this.#paginatedGet(
this.features.version.software === GOTOSOCIAL ? '/api/v1/tokens' : '/api/oauth_tokens',
{},
oauthTokenSchema,
),
getOauthTokens: () => {
let url;
switch (this.features.version.software) {
case GOTOSOCIAL:
url = '/api/v1/tokens';
break;
case MITRA:
url = '/api/v1/settings/sessions';
break;
default:
url = '/api/oauth_tokens';
break;
}
return this.#paginatedGet(url, {}, oauthTokenSchema);
},
/**
* Revoke a user session by its ID
@ -1494,6 +1506,9 @@ class PlApiClient {
case GOTOSOCIAL:
response = await this.request(`/api/v1/tokens/${oauthTokenId}/invalidate`, { method: 'POST' });
break;
case MITRA:
response = await this.request(`/api/v1/settings/sessions/${oauthTokenId}`, { method: 'DELETE' });
break;
default:
response = await this.request(`/api/oauth_tokens/${oauthTokenId}`, { method: 'DELETE' });
break;

View File

@ -9,6 +9,13 @@ import { datetimeSchema } from './utils';
const oauthTokenSchema = v.pipe(
v.any(),
v.transform((token: any) => {
if (token.client_name) {
return {
...token,
app_name: token.client_name,
};
}
if (token.application) {
return {
...token,
@ -31,6 +38,7 @@ const oauthTokenSchema = v.pipe(
valid_until: v.fallback(v.nullable(datetimeSchema), null),
last_used: v.fallback(v.nullable(datetimeSchema), null),
scopes: v.fallback(v.array(v.string()), []),
is_current: v.fallback(v.nullable(v.boolean()), null),
}),
);

View File

@ -1696,6 +1696,7 @@ const getFeatures = (instance: Instance) => {
sessions: any([
v.software === AKKOMA,
v.software === ICESHRIMP_NET,
v.software === MITRA && gt(v.version, '4.13.1'),
v.software === PLEROMA,
v.software === GOTOSOCIAL && gte(v.version, '0.18.2'),
]),