forked from GitHubMirrors/silverbullet-icalendar
Basic examples for CalDAV and .ics URL
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
name: caldav
|
name: caldav
|
||||||
|
requiredPermissions:
|
||||||
|
- fetch
|
||||||
functions:
|
functions:
|
||||||
helloWorld:
|
queryIcs:
|
||||||
path: caldav.ts:helloWorld
|
path: ./caldav.ts:queryIcs
|
||||||
command:
|
events:
|
||||||
name: "Say hello"
|
- query:cal-ics
|
||||||
|
|||||||
32
caldav.ts
32
caldav.ts
@@ -1,5 +1,33 @@
|
|||||||
import { editor } from "@silverbulletmd/silverbullet/syscalls";
|
import { editor } from "@silverbulletmd/silverbullet/syscalls";
|
||||||
|
import { QueryProviderEvent } from "@silverbulletmd/silverbullet/types";
|
||||||
|
import { readYamlPage } from "@silverbulletmd/silverbullet/lib/yaml_page";
|
||||||
|
import { applyQuery } from "@silverbulletmd/silverbullet/lib/query";
|
||||||
|
import { parseIcsCalendar, type VCalendar } from "ts-ics";
|
||||||
|
|
||||||
export async function helloWorld() {
|
interface Event {
|
||||||
await editor.flashNotification("Hello world!");
|
summary: string | undefined;
|
||||||
|
description: string | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function queryIcs({ query }: QueryProviderEvent): Promise<any[]> {
|
||||||
|
const secrets = await readYamlPage("SECRETS");
|
||||||
|
const icsUrl = secrets.icsUrl;
|
||||||
|
const result = await fetch(icsUrl);
|
||||||
|
const icsData = await result.text();
|
||||||
|
const calendarParsed: VCalendar = parseIcsCalendar(icsData);
|
||||||
|
// TODO: Loop over multiple .ics URLs and assign calendar name based on X-WR-CALNAME
|
||||||
|
|
||||||
|
if (calendarParsed.events === undefined) {
|
||||||
|
editor.flashNotification("Did not parse events from iCalendar");
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const events: Event[] = calendarParsed.events.map((ics) => {
|
||||||
|
return {
|
||||||
|
summary: ics.summary,
|
||||||
|
description: ics.description,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return applyQuery(query, events);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
},
|
},
|
||||||
"imports": {
|
"imports": {
|
||||||
"@silverbulletmd/silverbullet": "jsr:@silverbulletmd/silverbullet@^0.9.0",
|
"@silverbulletmd/silverbullet": "jsr:@silverbulletmd/silverbullet@^0.9.0",
|
||||||
"tsdav": "npm:tsdav@2.1.3"
|
"tsdav": "npm:tsdav@2.1.3",
|
||||||
|
"ts-ics": "npm:ts-ics@1.6.5",
|
||||||
|
"@js-temporal/polyfill": "https://esm.sh/@js-temporal/polyfill@0.4.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
15
example.ts
Normal file
15
example.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import { createDAVClient } from "tsdav";
|
||||||
|
|
||||||
|
const client = await createDAVClient({
|
||||||
|
serverUrl:
|
||||||
|
"https://calendar.google.com/calendar/ical/marqus34%40gmail.com/private-df2ea81c13f2fa2b9d837aef069effe6/basic.ics",
|
||||||
|
credentials: {
|
||||||
|
username: "exemplar",
|
||||||
|
password: Deno.env.get("DAV_PASSWORD"),
|
||||||
|
},
|
||||||
|
authMethod: "Basic",
|
||||||
|
defaultAccountType: "caldav",
|
||||||
|
});
|
||||||
|
|
||||||
|
const calendars = await client.fetchCalendars();
|
||||||
|
console.log(calendars);
|
||||||
Reference in New Issue
Block a user