forked from FoundKeyGang/FoundKey
make webfinger server stuff more readable
This commit is contained in:
parent
bed6a1e2d8
commit
c67ff44207
1 changed files with 26 additions and 19 deletions
|
@ -80,26 +80,33 @@ 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 fromAcct = (acct: Acct.Acct): FindOptionsWhere<User> | number =>
|
||||
!acct.host || acct.host === config.host.toLowerCase() ? {
|
||||
usernameLower: acct.username,
|
||||
host: IsNull(),
|
||||
isSuspended: false,
|
||||
} : 422;
|
||||
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);
|
||||
};
|
||||
|
||||
let resource = ctx.query.resource;
|
||||
|
||||
|
|
Loading…
Reference in a new issue