pl-api: pleroma admin api fixes

Signed-off-by: Nicole Mikołajczyk <git@mkljczk.pl>
This commit is contained in:
Nicole Mikołajczyk
2025-05-30 00:23:18 +02:00
parent 62f65bfe9d
commit fe78471371
4 changed files with 32 additions and 20 deletions

View File

@ -3796,7 +3796,7 @@ class PlApiClient {
if (this.features.mastodonAdmin) {
response = await this.request(`/api/v1/admin/accounts/${accountId}`);
} else {
response = await this.request(`/api/v1/admin/users/${accountId}`);
response = await this.request(`/api/v1/pleroma/admin/users/${accountId}`);
}
return v.parse(adminAccountSchema, response.json);
@ -3815,7 +3815,7 @@ class PlApiClient {
} else {
const account = await this.admin.accounts.getAccount(accountId)!;
response = await this.request('/api/v1/pleroma/admin/users/approve', { body: { nicknames: [account.account!.username] } });
response = await this.request('/api/v1/pleroma/admin/users/approve', { method: 'PATCH', body: { nicknames: [account.username] } });
response.json = response.json?.users?.[0];
}
@ -3835,9 +3835,8 @@ class PlApiClient {
} else {
const account = await this.admin.accounts.getAccount(accountId)!;
response = await this.request('/api/v1/pleroma/admin/users/approve', { body: {
method: 'DELETE',
nicknames: [account.account!.username],
response = await this.request('/api/v1/pleroma/admin/users', { method: 'DELETE', body: {
nicknames: [account.username],
} });
}
@ -3848,20 +3847,33 @@ class PlApiClient {
* Requires features{@link Features.pleromaAdminAccounts}.
*/
createAccount: async (params: AdminCreateAccountParams) => {
const response = await this.request('/api/v1/admin/accounts', { method: 'POST', body: { users: [params] } });
const response = await this.request('/api/v1/pleroma/admin/users', { method: 'POST', body: { users: [params] } });
return v.parse(adminAccountSchema, response.json[0]);
return v.parse(v.object({
nickname: v.string(),
email: v.string(),
}), response.json[0]?.data);
},
/**
* Delete an account
* Permanently delete data for a suspended account.
* Permanently delete data for a suspended accountusers
* @see {@link https://docs.joinmastodon.org/methods/admin/accounts/#delete}
*/
deleteAccount: async (accountId: string) => {
const response = await this.request(`/api/v1/admin/accounts/${accountId}`, { method: 'DELETE' });
let response;
return v.parse(adminAccountSchema, response.json);
if (this.features.mastodonAdmin) {
response = await this.request(`/api/v1/admin/accounts/${accountId}`, { method: 'DELETE' });
} else {
const account = await this.admin.accounts.getAccount(accountId)!;
response = await this.request('/api/v1/pleroma/admin/users', { method: 'DELETE', body: {
nicknames: [account.username],
} });
}
return v.safeParse(adminAccountSchema, response.json).output || {};
},
/**
@ -3880,7 +3892,7 @@ class PlApiClient {
switch (type) {
case 'disable':
case 'suspend':
response = await this.request('/api/v1/pleroma/admin/users/deactivate', { body: { nicknames: [account.account!.username] } });
response = await this.request('/api/v1/pleroma/admin/users/deactivate', { body: { nicknames: [account.username] } });
break;
default:
response = { json: {} };
@ -3904,8 +3916,8 @@ class PlApiClient {
response = await this.request(`/api/v1/admin/accounts/${accountId}/enable`, { method: 'POST' });
} else {
const account = await this.admin.accounts.getAccount(accountId)!;
response = await this.request('/api/v1/pleroma/admin/users/activate', { body: { nicknames: [account.account!.username] } });
console.log(account);
response = await this.request('/api/v1/pleroma/admin/users/activate', { method: 'PATCH', body: { nicknames: [account.username] } });
response.json = response.json?.users?.[0];
}
@ -3936,7 +3948,7 @@ class PlApiClient {
} else {
const { account } = await this.admin.accounts.getAccount(accountId)!;
response = await this.request('/api/v1/pleroma/admin/users/activate', { body: { nicknames: [account!.acct] } });
response = await this.request('/api/v1/pleroma/admin/users/activate', { method: 'PATCH', body: { nicknames: [account!.acct] } });
response.json = response.json?.users?.[0];
}

View File

@ -1,6 +1,6 @@
{
"name": "pl-api",
"version": "1.0.0-rc.70",
"version": "1.0.0-rc.73",
"type": "module",
"homepage": "https://github.com/mkljczk/pl-fe/tree/develop/packages/pl-api",
"repository": {

View File

@ -105,7 +105,7 @@
"multiselect-react-dropdown": "^2.0.25",
"mutative": "^1.1.0",
"path-browserify": "^1.0.1",
"pl-api": "^1.0.0-rc.70",
"pl-api": "^1.0.0-rc.73",
"postcss": "^8.5.3",
"process": "^0.11.10",
"punycode": "^2.1.1",

View File

@ -6875,10 +6875,10 @@ pkg-dir@^4.1.0:
dependencies:
find-up "^4.0.0"
pl-api@^1.0.0-rc.70:
version "1.0.0-rc.70"
resolved "https://registry.yarnpkg.com/pl-api/-/pl-api-1.0.0-rc.70.tgz#0f140b780fad2628746b021a0f8a384b1eb7323c"
integrity sha512-QISMfayJOFE1+JzhKBdOKRpzByiLre20MHDss9WwWdQIPGSO1RRoDVb7ufTx2ER6ZeX+9zXzG7VPfh3gMhafQQ==
pl-api@^1.0.0-rc.73:
version "1.0.0-rc.73"
resolved "https://registry.yarnpkg.com/pl-api/-/pl-api-1.0.0-rc.73.tgz#c6455ea479c95bb4c1f04fced8001e43eae26507"
integrity sha512-QZWXmKGIp/s77GrpOoRQVEeD9h09CNO4XFXELtzT+hlQHcxYn5RTM+y5948kthl2VEgSJltRNNWjE/EwIaVoIA==
dependencies:
blurhash "^2.0.5"
http-link-header "^1.1.3"