From 87f5ddc8b1fd4a9b61a6ba0edf57ebd3b100ba78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20=C5=A0korpil?= Date: Tue, 27 Dec 2022 22:40:15 +0100 Subject: [PATCH] If nodeinfo refresh is failed, software name and version is unset --- application/src/Fediverse/NodeInfo/retrieveNodeInfo.ts | 6 +++--- application/src/Jobs/NodeInfo/refreshNodeInfo.ts | 9 +++++++-- application/src/Storage/Nodes/updateNodeInfo.ts | 6 +++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/application/src/Fediverse/NodeInfo/retrieveNodeInfo.ts b/application/src/Fediverse/NodeInfo/retrieveNodeInfo.ts index 9b693ca..35f38d2 100644 --- a/application/src/Fediverse/NodeInfo/retrieveNodeInfo.ts +++ b/application/src/Fediverse/NodeInfo/retrieveNodeInfo.ts @@ -6,10 +6,10 @@ import RobotsTxt from '../RobotsTxt/RobotsTxt.js' const schema = z.object({ name: z.string().optional(), software: z.object({ - name: z.string(), - version: z.string() + name: z.string().nullable(), + version: z.string().nullable() }), - protocols: z.array(z.string()), + protocols: z.array(z.string()).optional(), usage: z.optional( z.object({ users: z.optional( diff --git a/application/src/Jobs/NodeInfo/refreshNodeInfo.ts b/application/src/Jobs/NodeInfo/refreshNodeInfo.ts index 28d7493..182eda3 100644 --- a/application/src/Jobs/NodeInfo/refreshNodeInfo.ts +++ b/application/src/Jobs/NodeInfo/refreshNodeInfo.ts @@ -14,7 +14,12 @@ export const refreshNodeInfo = async ( const nodeInfo = await retrieveDomainNodeInfo(node.domain, robotsTxt) return await updateNodeInfo(elastic, node, nodeInfo) } catch (error) { - console.warn('Failed to update node info', error) - return node + console.warn('Failed to update node info, unsetting node', error) + return await updateNodeInfo(elastic, node, { + software: { + name: null, + version: null + } + }) } } diff --git a/application/src/Storage/Nodes/updateNodeInfo.ts b/application/src/Storage/Nodes/updateNodeInfo.ts index 4b602a8..a773e8e 100644 --- a/application/src/Storage/Nodes/updateNodeInfo.ts +++ b/application/src/Storage/Nodes/updateNodeInfo.ts @@ -23,8 +23,8 @@ export const updateNodeInfo = async ( doc: { name: nodeInfo?.name, openRegistrations: nodeInfo?.openRegistrations, - softwareName: nodeInfo?.software?.name?.toLocaleLowerCase(), - softwareVersion: nodeInfo?.software?.version, + softwareName: nodeInfo?.software?.name?.toLocaleLowerCase() ?? null, + softwareVersion: nodeInfo?.software?.version ?? null, halfYearActiveUserCount: assertPositiveInt( nodeInfo?.usage?.users?.activeHalfyear ), @@ -40,6 +40,6 @@ export const updateNodeInfo = async ( await getNode(elastic, node.domain), 'Missing node after updating it' ) - console.info('Updated node info', { node }) + console.info('Updated node info', { resultNode }) return resultNode }