Define the event object

This commit is contained in:
Marek S. Lukasiewicz
2025-01-05 17:14:34 +01:00
parent 9d234428d4
commit 1de79df25d
3 changed files with 57 additions and 12 deletions

View File

@@ -44,9 +44,6 @@ select summary, description
## Roadmap
- Decide which properties should be exposed:
- Location
- Color?
- Add instructions for popular services:
- Nextcloud
- Google Calendar

37
example-google.json Normal file
View File

@@ -0,0 +1,37 @@
{
"summary": "Flight to Minas Tirith (VG 1234)",
"uid": "loremipsum123@google.com",
"created": {
"date": "2024-09-17T20:07:20.000Z",
"type": "DATE-TIME"
},
"lastModified": {
"date": "2024-09-17T20:07:20.000Z",
"type": "DATE-TIME"
},
"stamp": {
"date": "2025-01-05T15:51:40.000Z",
"type": "DATE-TIME"
},
"start": {
"date": "2024-10-28T18:05:00.000Z",
"type": "DATE-TIME"
},
"location": "Shire (SHR)",
"description": "Example data from Google Calendar, as parsed by ts-ics\nit has newlines like this",
"timeTransparent": "TRANSPARENT",
"class": "PRIVATE",
"status": "CONFIRMED",
"attendees": [
{
"email": "hobbit@example.com",
"name": "hobbit@example.com",
"role": "REQ-PARTICIPANT",
"partstat": "ACCEPTED"
}
],
"end": {
"date": "2024-10-28T20:00:00.000Z",
"type": "DATE-TIME"
}
}

View File

@@ -1,20 +1,29 @@
import { editor, system } from "@silverbulletmd/silverbullet/syscalls";
import { system } from "@silverbulletmd/silverbullet/syscalls";
import { QueryProviderEvent } from "@silverbulletmd/silverbullet/types";
import { applyQuery } from "@silverbulletmd/silverbullet/lib/query";
import { parseIcsCalendar, type VCalendar } from "ts-ics";
// Try to match SilverBullet properties where possible.
// Timestamps should be strings formatted with `localDateString`
interface Event {
// Typically available in calendar apps
summary: string | undefined;
description: string | undefined;
location: string | undefined;
// Same as SilverBullet pages
created: string | undefined;
lastModified: string | undefined;
// Keep consistent with dates above
start: string | undefined;
end: string | undefined;
sourceName: string | undefined;
}
interface Source {
url: string;
name: string | undefined;
url: string; // Should be an .ics file
name: string | undefined; // Optional name that will be assigned to events
}
export async function queryEvents(
@@ -37,22 +46,23 @@ export async function queryEvents(
throw new Error("Didn't parse events from ics data");
}
console.log(JSON.stringify(calendarParsed.events[0], null, 2));
// The order here is the default order of columns without the select clause
for (const icsEvent of calendarParsed.events) {
events.push({
summary: icsEvent.summary,
sourceName: source.name,
location: icsEvent.location,
description: icsEvent.description,
// Mimic properties of pages
start: localDateString(icsEvent.start.date),
end: icsEvent.end ? localDateString(icsEvent.end.date) : undefined,
created: icsEvent.created
? localDateString(icsEvent.created.date)
: undefined,
lastModified: icsEvent.lastModified
? localDateString(icsEvent.lastModified.date)
: undefined,
// Consistent with formats above
start: localDateString(icsEvent.start.date),
end: icsEvent.end ? localDateString(icsEvent.end.date) : undefined,
});
}
} catch (err) {
@@ -69,6 +79,7 @@ async function getSources(): Promise<Source[]> {
const config = await system.getSpaceConfig("icalendar", {});
if (!config.sources || !Array.isArray(config.sources)) {
// The queries are running on server, probably because of that, can't use editor.flashNotification
console.error("Configure icalendar.sources");
return [];
}