From aeb7a7d2be160e909df3a33c95c180037084f8fc Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 15 Feb 2024 18:17:14 +0100 Subject: [PATCH 1/4] replace ?? with ||, check if FEDERATION_VALIDATE_COMMUNITY_TIMER is valid number --- backend/src/config/index.ts | 4 ++-- backend/src/federation/validateCommunities.ts | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index b94178157..607aace6c 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -128,8 +128,8 @@ if ( const federation = { FEDERATION_BACKEND_SEND_ON_API: process.env.FEDERATION_BACKEND_SEND_ON_API ?? '1_0', - FEDERATION_VALIDATE_COMMUNITY_TIMER: - Number(process.env.FEDERATION_VALIDATE_COMMUNITY_TIMER) ?? 60000, + FEDERATION_VALIDATE_COMMUNITY_TIMER: // ?? operator don't work here as expected + Number(process.env.FEDERATION_VALIDATE_COMMUNITY_TIMER) || 60000, FEDERATION_XCOM_SENDCOINS_ENABLED: process.env.FEDERATION_XCOM_SENDCOINS_ENABLED === 'true' ?? false, // default value for community-uuid is equal uuid of stage-3 diff --git a/backend/src/federation/validateCommunities.ts b/backend/src/federation/validateCommunities.ts index f19d606bd..1013db98e 100644 --- a/backend/src/federation/validateCommunities.ts +++ b/backend/src/federation/validateCommunities.ts @@ -13,8 +13,12 @@ import { backendLogger as logger } from '@/server/logger' import { startCommunityAuthentication } from './authenticateCommunities' import { PublicCommunityInfoLoggingView } from './client/1_0/logging/PublicCommunityInfoLogging.view' import { ApiVersionType } from './enum/apiVersionType' +import { LogError } from '@/server/LogError' export async function startValidateCommunities(timerInterval: number): Promise { + if (Number.isNaN(timerInterval) || timerInterval <= 0) { + throw new LogError('FEDERATION_VALIDATE_COMMUNITY_TIMER is not a positive number') + } logger.info( `Federation: startValidateCommunities loop with an interval of ${timerInterval} ms...`, ) From efa361810b92625c0f5941b22f7b6906a580e2f2 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 15 Feb 2024 18:29:11 +0100 Subject: [PATCH 2/4] lint fix --- backend/src/config/index.ts | 3 ++- backend/src/federation/validateCommunities.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 607aace6c..efda3fc31 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -128,7 +128,8 @@ if ( const federation = { FEDERATION_BACKEND_SEND_ON_API: process.env.FEDERATION_BACKEND_SEND_ON_API ?? '1_0', - FEDERATION_VALIDATE_COMMUNITY_TIMER: // ?? operator don't work here as expected + // ?? operator don't work here as expected + FEDERATION_VALIDATE_COMMUNITY_TIMER: Number(process.env.FEDERATION_VALIDATE_COMMUNITY_TIMER) || 60000, FEDERATION_XCOM_SENDCOINS_ENABLED: process.env.FEDERATION_XCOM_SENDCOINS_ENABLED === 'true' ?? false, diff --git a/backend/src/federation/validateCommunities.ts b/backend/src/federation/validateCommunities.ts index 1013db98e..b76e22087 100644 --- a/backend/src/federation/validateCommunities.ts +++ b/backend/src/federation/validateCommunities.ts @@ -8,12 +8,12 @@ import { FederatedCommunityLoggingView } from '@logging/FederatedCommunityLoggin import { FederationClient as V1_0_FederationClient } from '@/federation/client/1_0/FederationClient' import { PublicCommunityInfo } from '@/federation/client/1_0/model/PublicCommunityInfo' import { FederationClientFactory } from '@/federation/client/FederationClientFactory' +import { LogError } from '@/server/LogError' import { backendLogger as logger } from '@/server/logger' import { startCommunityAuthentication } from './authenticateCommunities' import { PublicCommunityInfoLoggingView } from './client/1_0/logging/PublicCommunityInfoLogging.view' import { ApiVersionType } from './enum/apiVersionType' -import { LogError } from '@/server/LogError' export async function startValidateCommunities(timerInterval: number): Promise { if (Number.isNaN(timerInterval) || timerInterval <= 0) { From 48f69ca89841058f837e056f505f408494b5adfa Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 15 Feb 2024 19:33:27 +0100 Subject: [PATCH 3/4] Update backend/src/config/index.ts Co-authored-by: clauspeterhuebner <86960882+clauspeterhuebner@users.noreply.github.com> --- backend/src/config/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index efda3fc31..2555a1730 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -130,7 +130,7 @@ const federation = { FEDERATION_BACKEND_SEND_ON_API: process.env.FEDERATION_BACKEND_SEND_ON_API ?? '1_0', // ?? operator don't work here as expected FEDERATION_VALIDATE_COMMUNITY_TIMER: - Number(process.env.FEDERATION_VALIDATE_COMMUNITY_TIMER) || 60000, + Number(process.env.FEDERATION_VALIDATE_COMMUNITY_TIMER ?? 60000) , FEDERATION_XCOM_SENDCOINS_ENABLED: process.env.FEDERATION_XCOM_SENDCOINS_ENABLED === 'true' ?? false, // default value for community-uuid is equal uuid of stage-3 From ea24651ca019d25514742dd6057cd91159636e0c Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 15 Feb 2024 19:59:34 +0100 Subject: [PATCH 4/4] fix lint --- backend/src/config/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 2555a1730..0aed77583 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -129,8 +129,9 @@ if ( const federation = { FEDERATION_BACKEND_SEND_ON_API: process.env.FEDERATION_BACKEND_SEND_ON_API ?? '1_0', // ?? operator don't work here as expected - FEDERATION_VALIDATE_COMMUNITY_TIMER: - Number(process.env.FEDERATION_VALIDATE_COMMUNITY_TIMER ?? 60000) , + FEDERATION_VALIDATE_COMMUNITY_TIMER: Number( + process.env.FEDERATION_VALIDATE_COMMUNITY_TIMER ?? 60000, + ), FEDERATION_XCOM_SENDCOINS_ENABLED: process.env.FEDERATION_XCOM_SENDCOINS_ENABLED === 'true' ?? false, // default value for community-uuid is equal uuid of stage-3