1
0
forked from mirror/misskey

getAuthUserFromApIdはmainを選ぶ

This commit is contained in:
tamaina 2024-02-26 21:27:50 +00:00
parent 1835397385
commit 5b7b8503cd

View File

@ -152,17 +152,36 @@ export class ApDbResolverService implements OnApplicationShutdown {
@bindThis @bindThis
public async getAuthUserFromApId(uri: string): Promise<{ public async getAuthUserFromApId(uri: string): Promise<{
user: MiRemoteUser; user: MiRemoteUser;
key: MiUserPublickey[] | null; key: MiUserPublickey | null;
} | null> { } | null> {
const user = await this.apPersonService.resolvePerson(uri) as MiRemoteUser; const user = await this.apPersonService.resolvePerson(uri) as MiRemoteUser;
if (user.isDeleted) return null; if (user.isDeleted) return null;
const key = await this.publicKeyByUserIdCache.fetch( const keys = await this.publicKeyByUserIdCache.fetch(
user.id, user.id,
() => this.userPublickeysRepository.find({ where: { userId: user.id } }), () => this.userPublickeysRepository.find({ where: { userId: user.id } }),
v => v != null, v => v != null,
); );
if (keys == null || keys.length === 8) return null;
// 公開鍵は複数あるが、mainっぽいのを選ぶ
const key = keys.length === 1 ?
keys[0] :
keys.find(x => {
try {
const url = new URL(x.keyId);
if (
url.hash.toLowerCase().includes('main') ||
url.pathname.split('/').pop()?.toLowerCase().includes('main')
) {
return true;
}
} catch { /* noop */ }
return false;
}) ?? keys[0];
return { return {
user, user,
key, key,