Support admin accounts endpoint (first pass)
This commit is contained in:
parent
714391b807
commit
5bd03bdcaa
|
@ -35,6 +35,7 @@ import {
|
||||||
updateCredentialsController,
|
updateCredentialsController,
|
||||||
verifyCredentialsController,
|
verifyCredentialsController,
|
||||||
} from './controllers/api/accounts.ts';
|
} from './controllers/api/accounts.ts';
|
||||||
|
import { adminAccountsController } from './controllers/api/admin.ts';
|
||||||
import { appCredentialsController, createAppController } from './controllers/api/apps.ts';
|
import { appCredentialsController, createAppController } from './controllers/api/apps.ts';
|
||||||
import { blocksController } from './controllers/api/blocks.ts';
|
import { blocksController } from './controllers/api/blocks.ts';
|
||||||
import { bookmarksController } from './controllers/api/bookmarks.ts';
|
import { bookmarksController } from './controllers/api/bookmarks.ts';
|
||||||
|
@ -185,6 +186,7 @@ app.get('/api/v1/favourites', requirePubkey, favouritesController);
|
||||||
app.get('/api/v1/bookmarks', requirePubkey, bookmarksController);
|
app.get('/api/v1/bookmarks', requirePubkey, bookmarksController);
|
||||||
app.get('/api/v1/blocks', requirePubkey, blocksController);
|
app.get('/api/v1/blocks', requirePubkey, blocksController);
|
||||||
|
|
||||||
|
app.get('/api/v1/admin/accounts', adminAccountsController);
|
||||||
app.post('/api/v1/pleroma/admin/config', requireRole('admin'), updateConfigController);
|
app.post('/api/v1/pleroma/admin/config', requireRole('admin'), updateConfigController);
|
||||||
|
|
||||||
// Not (yet) implemented.
|
// Not (yet) implemented.
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
import { type AppController } from '@/app.ts';
|
||||||
|
import { Conf } from '@/config.ts';
|
||||||
|
import { eventsDB } from '@/storages.ts';
|
||||||
|
import { renderAdminAccount } from '@/views/mastodon/admin-accounts.ts';
|
||||||
|
|
||||||
|
const adminAccountsController: AppController = async (c) => {
|
||||||
|
const events = await eventsDB.getEvents([{ kinds: [30361], authors: [Conf.pubkey], limit: 20 }]);
|
||||||
|
const pubkeys = events.map((event) => event.tags.find(([name]) => name === 'd')?.[1]!);
|
||||||
|
const authors = await eventsDB.getEvents([{ kinds: [0], ids: pubkeys, limit: pubkeys.length }]);
|
||||||
|
|
||||||
|
for (const event of events) {
|
||||||
|
const d = event.tags.find(([name]) => name === 'd')?.[1];
|
||||||
|
event.d_author = authors.find((author) => author.pubkey === d);
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.json(
|
||||||
|
await Promise.all(
|
||||||
|
events.map((event) => renderAdminAccount(event)),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export { adminAccountsController };
|
|
@ -29,6 +29,8 @@ interface DittoEvent<K extends number = number> extends Event<K> {
|
||||||
author?: DittoEvent<0>;
|
author?: DittoEvent<0>;
|
||||||
author_stats?: AuthorStats;
|
author_stats?: AuthorStats;
|
||||||
event_stats?: EventStats;
|
event_stats?: EventStats;
|
||||||
|
d_author?: DittoEvent<0>;
|
||||||
|
user?: DittoEvent<30361>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Storage interface for Nostr events. */
|
/** Storage interface for Nostr events. */
|
||||||
|
|
|
@ -12,7 +12,7 @@ interface ToAccountOpts {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function renderAccount(
|
async function renderAccount(
|
||||||
event: Omit<NonNullable<DittoEvent['author']>, 'id' | 'sig'>,
|
event: Omit<DittoEvent<0>, 'id' | 'sig'>,
|
||||||
opts: ToAccountOpts = {},
|
opts: ToAccountOpts = {},
|
||||||
) {
|
) {
|
||||||
const { withSource = false } = opts;
|
const { withSource = false } = opts;
|
||||||
|
@ -39,7 +39,7 @@ async function renderAccount(
|
||||||
avatar: picture,
|
avatar: picture,
|
||||||
avatar_static: picture,
|
avatar_static: picture,
|
||||||
bot: false,
|
bot: false,
|
||||||
created_at: nostrDate(event.created_at).toISOString(),
|
created_at: user ? user.inserted_at.toISOString() : nostrDate(event.created_at).toISOString(),
|
||||||
discoverable: true,
|
discoverable: true,
|
||||||
display_name: name,
|
display_name: name,
|
||||||
emojis: renderEmojis(event),
|
emojis: renderEmojis(event),
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
import { DittoEvent } from '@/storages/types.ts';
|
||||||
|
import { nostrDate } from '@/utils.ts';
|
||||||
|
|
||||||
|
import { accountFromPubkey, renderAccount } from './accounts.ts';
|
||||||
|
|
||||||
|
async function renderAdminAccount(event: DittoEvent<30361>) {
|
||||||
|
const d = event.tags.find(([name]) => name === 'd')?.[1]!;
|
||||||
|
const account = event.d_author ? await renderAccount({ ...event.d_author, user: event }) : await accountFromPubkey(d);
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: account.id,
|
||||||
|
username: event.tags.find(([name]) => name === 'name')?.[1]!,
|
||||||
|
domain: account.acct.split('@')[1] || null,
|
||||||
|
created_at: nostrDate(event.created_at).toISOString(),
|
||||||
|
email: '',
|
||||||
|
ip: null,
|
||||||
|
ips: [],
|
||||||
|
locale: '',
|
||||||
|
invite_request: null,
|
||||||
|
role: event.tags.find(([name]) => name === 'role')?.[1] || 'user',
|
||||||
|
confirmed: true,
|
||||||
|
approved: true,
|
||||||
|
disabled: false,
|
||||||
|
silenced: false,
|
||||||
|
suspended: false,
|
||||||
|
account,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export { renderAdminAccount };
|
Loading…
Reference in New Issue