Support admin accounts endpoint (first pass)

This commit is contained in:
Alex Gleason
2024-01-05 15:35:55 -06:00
parent 714391b807
commit 5bd03bdcaa
5 changed files with 59 additions and 2 deletions

View File

@@ -12,7 +12,7 @@ interface ToAccountOpts {
}
async function renderAccount(
event: Omit<NonNullable<DittoEvent['author']>, 'id' | 'sig'>,
event: Omit<DittoEvent<0>, 'id' | 'sig'>,
opts: ToAccountOpts = {},
) {
const { withSource = false } = opts;
@@ -39,7 +39,7 @@ async function renderAccount(
avatar: picture,
avatar_static: picture,
bot: false,
created_at: nostrDate(event.created_at).toISOString(),
created_at: user ? user.inserted_at.toISOString() : nostrDate(event.created_at).toISOString(),
discoverable: true,
display_name: name,
emojis: renderEmojis(event),

View File

@@ -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 };