2024-08-07 02:11:38 +08:00
|
|
|
import { system } from "@silverbulletmd/silverbullet/syscalls";
|
|
|
|
import { readYamlPage } from "@silverbulletmd/silverbullet/lib/yaml_page";
|
2022-07-15 17:17:02 +08:00
|
|
|
|
2022-07-18 16:51:28 +08:00
|
|
|
/**
|
2024-08-02 22:47:36 +08:00
|
|
|
* Retrieves a setting from the space configuration.
|
|
|
|
* @deprecated Use use `editor.getSpaceConfig` syscall instead
|
|
|
|
* @param key string
|
|
|
|
* @param defaultValue
|
|
|
|
* @returns
|
2022-07-18 16:51:28 +08:00
|
|
|
*/
|
2022-12-16 23:35:23 +08:00
|
|
|
export async function readSetting(
|
|
|
|
key: string,
|
|
|
|
defaultValue?: any,
|
|
|
|
): Promise<any> {
|
2024-08-05 22:34:48 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2022-09-13 14:41:01 +08:00
|
|
|
}
|