updateCredentials: allow setting nip05 through the API, remove restrictions on update_credentials

This commit is contained in:
Alex Gleason 2024-03-24 16:42:19 -05:00
parent cfc2f02104
commit 75c277e7e8
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
4 changed files with 10 additions and 7 deletions

View File

@ -143,11 +143,7 @@ app.get('/oauth/authorize', oauthController);
app.post('/api/v1/accounts', requireProof({ pow: 20 }), createAccountController); app.post('/api/v1/accounts', requireProof({ pow: 20 }), createAccountController);
app.get('/api/v1/accounts/verify_credentials', requirePubkey, verifyCredentialsController); app.get('/api/v1/accounts/verify_credentials', requirePubkey, verifyCredentialsController);
app.patch( app.patch('/api/v1/accounts/update_credentials', requirePubkey, updateCredentialsController);
'/api/v1/accounts/update_credentials',
requireRole('user', { validatePayload: false }),
updateCredentialsController,
);
app.get('/api/v1/accounts/search', accountSearchController); app.get('/api/v1/accounts/search', accountSearchController);
app.get('/api/v1/accounts/lookup', accountLookupController); app.get('/api/v1/accounts/lookup', accountLookupController);
app.get('/api/v1/accounts/relationships', relationshipsController); app.get('/api/v1/accounts/relationships', relationshipsController);

View File

@ -181,11 +181,11 @@ const updateCredentialsSchema = z.object({
locked: z.boolean().optional(), locked: z.boolean().optional(),
bot: z.boolean().optional(), bot: z.boolean().optional(),
discoverable: z.boolean().optional(), discoverable: z.boolean().optional(),
nip05: z.string().optional(),
}); });
const updateCredentialsController: AppController = async (c) => { const updateCredentialsController: AppController = async (c) => {
const pubkey = c.get('pubkey')!; const pubkey = c.get('pubkey')!;
const user = c.get('user')!;
const body = await parseBody(c.req.raw); const body = await parseBody(c.req.raw);
const result = updateCredentialsSchema.safeParse(body); const result = updateCredentialsSchema.safeParse(body);
@ -201,6 +201,7 @@ const updateCredentialsController: AppController = async (c) => {
header: headerFile, header: headerFile,
display_name, display_name,
note, note,
nip05,
} = result.data; } = result.data;
const [avatar, header] = await Promise.all([ const [avatar, header] = await Promise.all([
@ -212,7 +213,7 @@ const updateCredentialsController: AppController = async (c) => {
meta.about = note ?? meta.about; meta.about = note ?? meta.about;
meta.picture = avatar?.url ?? meta.picture; meta.picture = avatar?.url ?? meta.picture;
meta.banner = header?.url ?? meta.banner; meta.banner = header?.url ?? meta.banner;
meta.nip05 = `${user.username}@${Conf.url.host}` ?? meta.nip05; meta.nip05 = nip05 ?? meta.nip05;
const event = await createEvent({ const event = await createEvent({
kind: 0, kind: 0,

View File

@ -34,6 +34,8 @@ interface Nip05 {
handle: string; handle: string;
/** The localpart, if available and not `_`. Otherwise the domain. */ /** The localpart, if available and not `_`. Otherwise the domain. */
nickname: string; nickname: string;
/** The full NIP-05 identifier. */
value: string;
} }
/** /**
@ -50,6 +52,7 @@ function parseNip05(value: string): Nip05 {
domain, domain,
handle: local === '_' ? domain : value, handle: local === '_' ? domain : value,
nickname: (local && local !== '_') ? local : domain, nickname: (local && local !== '_') ? local : domain,
value,
}; };
} }

View File

@ -65,6 +65,9 @@ async function renderAccount(
privacy: 'public', privacy: 'public',
sensitive: false, sensitive: false,
follow_requests_count: 0, follow_requests_count: 0,
nostr: {
nip05: parsed05?.value,
},
} }
: undefined, : undefined,
statuses_count: event.author_stats?.notes_count ?? 0, statuses_count: event.author_stats?.notes_count ?? 0,