updateCredentials: allow setting nip05 through the API, remove restrictions on update_credentials
This commit is contained in:
parent
cfc2f02104
commit
75c277e7e8
|
@ -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);
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in New Issue