From 51f756ec6090fa3a3a9c786dcb18488a68e3babf Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Mon, 5 Aug 2024 16:34:48 +0200 Subject: [PATCH] Fallback for readSetting for old SB versions --- plug-api/lib/settings_page.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/plug-api/lib/settings_page.ts b/plug-api/lib/settings_page.ts index d19dffe8..446ac10c 100644 --- a/plug-api/lib/settings_page.ts +++ b/plug-api/lib/settings_page.ts @@ -1,4 +1,5 @@ import { system } from "$sb/syscalls.ts"; +import { readYamlPage } from "$sb/lib/yaml_page.ts"; /** * Retrieves a setting from the space configuration. @@ -11,5 +12,20 @@ export async function readSetting( key: string, defaultValue?: any, ): Promise { - return await system.getSpaceConfig(key) ?? defaultValue; + try { + return await system.getSpaceConfig(key) ?? defaultValue; + } catch { + // We're running an old version of SilverBullet, fallback to reading from SETTINGS page + try { + const allSettings = (await readYamlPage("SETTINGS")) || {}; + const val = allSettings[key]; + return val === undefined ? defaultValue : val; + } catch (e: any) { + if (e.message === "Not found") { + // No settings yet, return default values for all + return defaultValue; + } + throw e; + } + } }