From b692c00b8de0aef5380858570e8366c6773b9697 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Thu, 13 Feb 2025 09:46:49 +0100 Subject: [PATCH] feat(config): improve typesafety by definitely returning a number previously it was either a number like string (in case env or config.ini was used) or a number (the fallback value) we now parseInt the value -> if any value is NaN (e.g. because it was incorrectly set) it will try with the next, before it uses the fallback value the strange looking `parseInt(String(process.env.TRILIUM_SESSION_COOKIEMAXAGE))` is required to make TypeScript happy, other variants of trying to get the value into a string were not good enough for typescript :-) The `String(process.env.TRILIUM_SESSION_COOKIEMAXAGE)` will now either return a number like value or 'undefined' (as string), which parseInt parses into NaN, which is falsy. --- src/services/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/config.ts b/src/services/config.ts index b17ed954b..b10015aa7 100644 --- a/src/services/config.ts +++ b/src/services/config.ts @@ -85,7 +85,7 @@ const config: TriliumConfig = { process.env.TRILIUM_SESSION_COOKIEPATH || iniConfig?.Session?.cookiePath || "/", cookieMaxAge: - process.env.TRILIUM_SESSION_COOKIEMAXAGE || iniConfig?.Session?.cookieMaxAge || 21 * 24 * 60 * 60 // 21 Days in Seconds + parseInt(String(process.env.TRILIUM_SESSION_COOKIEMAXAGE)) || parseInt(iniConfig?.Session?.cookieMaxAge) || 21 * 24 * 60 * 60 // 21 Days in Seconds }, Sync: {