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,31 +131,43 @@ export class ApDbResolverService implements OnApplicationShutdown {
v => v != null, 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っぽいのを選ぶ // 公開鍵は複数あるが、mainっぽいのを選ぶ
const key = keys.length === 1 ? const mainKey = keys.find(x => {
keys[0] : try {
keys.find(x => { if (x.keyId === keyId) return true;
try { const url = new URL(x.keyId);
if (x.keyId === keyId) return true; const path = url.pathname.split('/').pop()?.toLowerCase();
const url = new URL(x.keyId); if (url.hash) {
const path = url.pathname.split('/').pop()?.toLowerCase(); if (url.hash.toLowerCase().includes('main')) {
if (url.hash) {
if (url.hash.toLowerCase().includes('main')) {
return true;
}
} else if (path?.includes('main') || path === 'publickey') {
return true; return true;
} }
} catch { /* noop */ } } else if (path?.includes('main') || path === 'publickey') {
return true;
return false; }
}) ?? keys[0]; } catch { /* noop */ }
return false;
});
return { return {
user, user,
key, key: mainKey ?? keys[0],
}; };
} }