Compare commits

...

2 commits

Author SHA1 Message Date
c67ff44207
make webfinger server stuff more readable
Some checks failed
ci/woodpecker/push/lint-backend Pipeline failed
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/lint-sw Pipeline failed
ci/woodpecker/push/lint-foundkey-js Pipeline was successful
ci/woodpecker/push/lint-client Pipeline failed
ci/woodpecker/push/test Pipeline failed
2023-12-16 09:59:51 +01:00
bed6a1e2d8
redirect webfinger of domain to instance actor
(Johann150 yells at cloud)
2023-12-16 09:59:17 +01:00

View file

@ -80,33 +80,50 @@ router.get('/.well-known/oauth-authorization-server', oauth);
router.get('/.well-known/openid-configuration', oauth);
router.get(webFingerPath, async ctx => {
const fromId = (id: User['id']): FindOptionsWhere<User> => ({
id,
host: IsNull(),
isSuspended: false,
});
const fromAcct = (acct_str: string): FindOptionsWhere<User> | number => {
const acct = Acct.parse(acct_str);
if (!acct.host || acct.host === config.host.toLowerCase()) {
return {
usernameLower: acct.username,
host: IsNull(),
isSuspended: false,
};
} else {
return 422;
}
};
const generateQuery = (resource: string): FindOptionsWhere<User> | number =>
resource.startsWith(`${config.url.toLowerCase()}/users/`) ?
fromId(resource.split('/').pop()!) :
fromAcct(Acct.parse(
resource.startsWith(`${config.url.toLowerCase()}/@`) ? resource.split('/').pop()! :
resource.startsWith('acct:') ? resource.slice('acct:'.length) :
resource));
const generateQuery = (resource: string): FindOptionsWhere<User> | number => {
if (resource.startsWith(`${config.url.toLowerCase()}/users/`)) {
return {
id: resource.split('/').pop()!,
host: IsNull(),
isSuspended: false,
};
} else if (resource.startsWith(`${config.url.toLowerCase()}/@`)) {
return fromAcct(resource.split('/').pop()!);
} else if (resource.startsWith("acct:")) {
return fromAcct(resource.slice('acct:'.length));
}
return fromAcct(resource);
};
const fromAcct = (acct: Acct.Acct): FindOptionsWhere<User> | number =>
!acct.host || acct.host === config.host.toLowerCase() ? {
usernameLower: acct.username,
host: IsNull(),
isSuspended: false,
} : 422;
let resource = ctx.query.resource;
if (typeof ctx.query.resource !== 'string') {
if (typeof resource !== 'string') {
ctx.status = 400;
return;
}
const query = generateQuery(ctx.query.resource.toLowerCase());
resource = resource.toLowerCase();
// Mastodon sometimes only checks for the domain name,
// which should be rewritten to the instance actor.
if (`https://${config.host}`.toLowerCase() === resource) {
resource = `acct:instance.actor@${config.host}`;
}
const query = generateQuery(resource);
if (typeof query === 'number') {
ctx.status = query;