Include source property on own account

This commit is contained in:
Alex Gleason 2023-05-02 13:58:29 -05:00
parent e93fcdc643
commit 6fa897145e
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 18 additions and 2 deletions

View File

@ -11,7 +11,7 @@ const credentialsController: AppController = async (c) => {
const event = await getAuthor(pubkey); const event = await getAuthor(pubkey);
if (event) { if (event) {
return c.json(toAccount(event)); return c.json(toAccount(event, { withSource: true }));
} }
return c.json({ error: 'Could not find user.' }, 404); return c.json({ error: 'Could not find user.' }, 404);

View File

@ -9,7 +9,13 @@ import { type Nip05, parseNip05 } from './utils.ts';
const DEFAULT_AVATAR = 'https://gleasonator.com/images/avi.png'; const DEFAULT_AVATAR = 'https://gleasonator.com/images/avi.png';
const DEFAULT_BANNER = 'https://gleasonator.com/images/banner.png'; const DEFAULT_BANNER = 'https://gleasonator.com/images/banner.png';
function toAccount(event: Event<0>) { interface ToAccountOpts {
withSource?: boolean;
}
function toAccount(event: Event<0>, opts: ToAccountOpts = {}) {
const { withSource = false } = opts;
const { pubkey } = event; const { pubkey } = event;
const { name, nip05, picture, banner, about }: MetaContent = parseContent(event); const { name, nip05, picture, banner, about }: MetaContent = parseContent(event);
const { origin } = new URL(LOCAL_DOMAIN); const { origin } = new URL(LOCAL_DOMAIN);
@ -35,6 +41,16 @@ function toAccount(event: Event<0>) {
follow_requests_count: 0, follow_requests_count: 0,
followers_count: 0, followers_count: 0,
following_count: 0, following_count: 0,
source: withSource
? {
fields: [],
language: '',
note: about || '',
privacy: 'public',
sensitive: false,
follow_requests_count: 0,
}
: undefined,
statuses_count: 0, statuses_count: 0,
header: banner || DEFAULT_BANNER, header: banner || DEFAULT_BANNER,
header_static: banner || DEFAULT_BANNER, header_static: banner || DEFAULT_BANNER,