MCPcopy Create free account
hub / github.com/bewcloud/bewcloud / syncCalendars

Function syncCalendars

lib/models/dav.js:10040–10087  ·  view source on GitHub ↗
(params)

Source from the content-addressed store, hash-verified

10038 * Sync remote calendars to local
10039 */
10040const syncCalendars = async (params) => {
10041 var _a;
10042 const { oldCalendars, account, detailedResult, headers, headersToExclude } = params;
10043 if (!account) {
10044 throw new Error('Must have account before syncCalendars');
10045 }
10046 const localCalendars = (_a = oldCalendars !== null && oldCalendars !== void 0 ? oldCalendars : account.calendars) !== null && _a !== void 0 ? _a : [];
10047 const remoteCalendars = await fetchCalendars({
10048 account,
10049 headers: excludeHeaders(headers, headersToExclude),
10050 });
10051 // no existing url
10052 const created = remoteCalendars.filter((rc) => localCalendars.every((lc) => !urlContains(lc.url, rc.url)));
10053 debug$2(`new calendars: ${created.map((cc) => cc.displayName)}`);
10054 // have same url, but syncToken/ctag different
10055 const updated = localCalendars.reduce((prev, curr) => {
10056 const found = remoteCalendars.find((rc) => urlContains(rc.url, curr.url));
10057 if (found &&
10058 ((found.syncToken && found.syncToken !== curr.syncToken) ||
10059 (found.ctag && found.ctag !== curr.ctag))) {
10060 return [...prev, found];
10061 }
10062 return prev;
10063 }, []);
10064 debug$2(`updated calendars: ${updated.map((cc) => cc.displayName)}`);
10065 const updatedWithObjects = await Promise.all(updated.map(async (u) => {
10066 const result = await smartCollectionSync({
10067 collection: { ...u, objectMultiGet: calendarMultiGet },
10068 method: 'webdav',
10069 headers: excludeHeaders(headers, headersToExclude),
10070 account,
10071 });
10072 return result;
10073 }));
10074 // does not present in remote
10075 const deleted = localCalendars.filter((cal) => remoteCalendars.every((rc) => !urlContains(rc.url, cal.url)));
10076 debug$2(`deleted calendars: ${deleted.map((cc) => cc.displayName)}`);
10077 const unchanged = localCalendars.filter((cal) => remoteCalendars.some((rc) => urlContains(rc.url, cal.url) &&
10078 ((rc.syncToken && rc.syncToken !== cal.syncToken) || (rc.ctag && rc.ctag !== cal.ctag))));
10079 // debug(`unchanged calendars: ${unchanged.map((cc) => cc.displayName)}`);
10080 return detailedResult
10081 ? {
10082 created,
10083 updated,
10084 deleted,
10085 }
10086 : [...unchanged, ...created, ...updatedWithObjects];
10087};
10088const freeBusyQuery = async (params) => {
10089 const { url, timeRange, depth, headers, headersToExclude } = params;
10090 if (timeRange) {

Callers

nothing calls this directly

Calls 4

fetchCalendarsFunction · 0.85
excludeHeadersFunction · 0.85
urlContainsFunction · 0.85
smartCollectionSyncFunction · 0.85

Tested by

no test coverage detected