This commit is contained in:
tamaina 2024-03-01 06:58:43 +00:00
parent 54fe8ca600
commit bec6159b4a
1 changed files with 30 additions and 18 deletions

View File

@ -131,12 +131,25 @@ export class ApDbResolverService implements OnApplicationShutdown {
v => v != null,
);
if (keys == null || keys.length === 8) return null;
if (keys == null || !Array.isArray(keys)) return null;
if (keys.length === 0) {
return {
user,
key: keys[0],
};
}
const exactKey = keys.find(x => x.keyId === keyId);
if (exactKey) {
return {
user,
key: exactKey,
};
}
// 公開鍵は複数あるが、mainっぽいのを選ぶ
const key = keys.length === 1 ?
keys[0] :
keys.find(x => {
const mainKey = keys.find(x => {
try {
if (x.keyId === keyId) return true;
const url = new URL(x.keyId);
@ -151,11 +164,10 @@ export class ApDbResolverService implements OnApplicationShutdown {
} catch { /* noop */ }
return false;
}) ?? keys[0];
});
return {
user,
key,
key: mainKey ?? keys[0],
};
}