From 973a36cfd1d1dff42d5bb9becca8bc93e6f14d3c Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 1 Jul 2024 09:40:05 +1000 Subject: [PATCH] fix: return value --- services/api/src/routes/keys.ts | 46 +++++++++++++++++---------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/services/api/src/routes/keys.ts b/services/api/src/routes/keys.ts index 69f7a460ef..9d6d249745 100644 --- a/services/api/src/routes/keys.ts +++ b/services/api/src/routes/keys.ts @@ -53,35 +53,37 @@ const keysRoute = async ( const keys = R.map(R.prop('sshKey'), rows); const fingerprintKeyMap = await mapFingerprints(keys) - const found = fingerprintKeyMap.filter(el => {if (el.fingerprint === fingerprint) { return el.key }}); + const found = await fingerprintKeyMap.filter(el => {if (el.fingerprint === fingerprint) { return el.key }})[0]; - if (found) { + if (!found) { logger.debug(`Unknown fingerprint: ${fingerprint}`); - } - - // update key used timestamp - const foundkey = await query( - sqlClientPool, - knex('ssh_key') - .select('id') - .where('key_fingerprint', fingerprint) - .toString(), - ); - // check if a key is found - if (foundkey.length > 0) { - var date = new Date(); - const convertDateFormat = R.init; - var lastUsed = convertDateFormat(date.toISOString()); - await query( + // drop out + res.send(); + } else { + // update key used timestamp + const foundkey = await query( sqlClientPool, knex('ssh_key') - .where('id', foundkey[0].id) - .update({lastUsed: lastUsed}) + .select('id') + .where('key_fingerprint', fingerprint) .toString(), ); + // check if a key is found + if (foundkey.length > 0) { + var date = new Date(); + const convertDateFormat = R.init; + var lastUsed = convertDateFormat(date.toISOString()); + await query( + sqlClientPool, + knex('ssh_key') + .where('id', foundkey[0].id) + .update({lastUsed: lastUsed}) + .toString(), + ); + } + // return key + res.send(found.key); } - - res.send(found[0].key); }; export default [bodyParser.json(), keysRoute];