forked from GitHubMirrors/silverbullet-icalendar
Make configuration more robust for single sources
Some checks failed
Build SilverBullet Plug / build (push) Failing after 9s
Some checks failed
Build SilverBullet Plug / build (push) Failing after 9s
This commit is contained in:
12
icalendar.ts
12
icalendar.ts
@@ -118,19 +118,21 @@ function convertDatesToStrings<T>(obj: T): DateToString<T> {
|
|||||||
* Retrieves and validates configured calendar sources
|
* Retrieves and validates configured calendar sources
|
||||||
*/
|
*/
|
||||||
async function getSources(): Promise<Source[]> {
|
async function getSources(): Promise<Source[]> {
|
||||||
|
// Using system.getSpaceConfig as config.get is being phased out in syscalls
|
||||||
const plugConfig = await config.get<PlugConfig>("icalendar", { sources: [] });
|
const plugConfig = await config.get<PlugConfig>("icalendar", { sources: [] });
|
||||||
|
|
||||||
if (!plugConfig.sources || !Array.isArray(plugConfig.sources)) {
|
if (!plugConfig.sources) {
|
||||||
console.error("[iCalendar] Invalid configuration:", { plugConfig });
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugConfig.sources.length === 0) {
|
// Handle case where user provides a single object instead of an array
|
||||||
return [];
|
let sources = plugConfig.sources;
|
||||||
|
if (!Array.isArray(sources)) {
|
||||||
|
sources = [sources as unknown as Source];
|
||||||
}
|
}
|
||||||
|
|
||||||
const validated: Source[] = [];
|
const validated: Source[] = [];
|
||||||
for (const src of plugConfig.sources) {
|
for (const src of sources) {
|
||||||
if (typeof src.url !== "string") {
|
if (typeof src.url !== "string") {
|
||||||
console.error("[iCalendar] Invalid source (missing url):", src);
|
console.error("[iCalendar] Invalid source (missing url):", src);
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user