Webfinger: fix resource parameter
This commit is contained in:
parent
bf23afdce0
commit
da9bea7560
|
@ -8,7 +8,6 @@ import type { Webfinger } from '@/schemas/webfinger.ts';
|
||||||
|
|
||||||
/** Transforms the resource URI into a `[username, domain]` tuple. */
|
/** Transforms the resource URI into a `[username, domain]` tuple. */
|
||||||
const acctSchema = urlTransformSchema
|
const acctSchema = urlTransformSchema
|
||||||
.refine((uri) => uri.protocol === 'acct:', { message: 'Protocol must be `acct:`', path: ['resource'] })
|
|
||||||
.transform((uri) => uri.pathname)
|
.transform((uri) => uri.pathname)
|
||||||
.pipe(z.string().email('Invalid acct'))
|
.pipe(z.string().email('Invalid acct'))
|
||||||
.transform((acct) => acct.split('@') as [username: string, host: string])
|
.transform((acct) => acct.split('@') as [username: string, host: string])
|
||||||
|
@ -34,7 +33,7 @@ const webfingerController: AppController = (c) => {
|
||||||
const [username] = acctSchema.parse(query.data.resource);
|
const [username] = acctSchema.parse(query.data.resource);
|
||||||
const user = await db.users.findFirst({ where: { username } });
|
const user = await db.users.findFirst({ where: { username } });
|
||||||
c.header('content-type', 'application/jrd+json');
|
c.header('content-type', 'application/jrd+json');
|
||||||
return c.body(JSON.stringify(renderWebfinger(user)));
|
return c.body(JSON.stringify(renderWebfinger({ ...user, resource: query.data.resource })));
|
||||||
} catch (_e) {
|
} catch (_e) {
|
||||||
return c.json({ error: 'Not found' }, 404);
|
return c.json({ error: 'Not found' }, 404);
|
||||||
}
|
}
|
||||||
|
@ -49,7 +48,7 @@ const webfingerController: AppController = (c) => {
|
||||||
return c.json({ error: 'Not found' }, 404);
|
return c.json({ error: 'Not found' }, 404);
|
||||||
}
|
}
|
||||||
c.header('content-type', 'application/jrd+json');
|
c.header('content-type', 'application/jrd+json');
|
||||||
return c.body(JSON.stringify(renderWebfinger(user)));
|
return c.body(JSON.stringify(renderWebfinger({ ...user, resource: query.data.resource })));
|
||||||
} else {
|
} else {
|
||||||
return c.json({ error: 'Unsupported Nostr URI' }, 400);
|
return c.json({ error: 'Unsupported Nostr URI' }, 400);
|
||||||
}
|
}
|
||||||
|
@ -66,7 +65,7 @@ const webfingerController: AppController = (c) => {
|
||||||
return handleNostr();
|
return handleNostr();
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return c.json({ error: 'Not found' }, 404);
|
return c.json({ error: 'Unsupported URI scheme' }, 400);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -82,15 +81,15 @@ const hostMetaController: AppController = (c) => {
|
||||||
interface RenderWebfingerOpts {
|
interface RenderWebfingerOpts {
|
||||||
pubkey: string;
|
pubkey: string;
|
||||||
username: string;
|
username: string;
|
||||||
|
resource: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Present Nostr user on Webfinger. */
|
/** Present Nostr user on Webfinger. */
|
||||||
function renderWebfinger({ pubkey, username }: RenderWebfingerOpts): Webfinger {
|
function renderWebfinger({ pubkey, username, resource }: RenderWebfingerOpts): Webfinger {
|
||||||
const { host } = new URL(Conf.localDomain);
|
|
||||||
const apId = Conf.url(`/users/${username}`);
|
const apId = Conf.url(`/users/${username}`);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
subject: `acct:${username}@${host}`,
|
subject: resource,
|
||||||
aliases: [apId],
|
aliases: [apId],
|
||||||
links: [
|
links: [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue