iCloud: recognise Apple's calendar entries; say what was seen when none match
build-container / build (push) Successful in 1m56s
build-container / build (push) Successful in 1m56s
Apple writes <calendar xmlns="urn:ietf:params:xml:ns:caldav"/> (attributes, no prefix), which the previous pattern missed, so a valid sign-in reported "No calendars found". Match it with a lookahead, check the HTTP status of the listing, and name what iCloud returned if nothing matches. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
044589686c
commit
a4e0e24ab7
1 file changed
+8
-3
@@ -65,10 +65,15 @@ async function connect(appleId, password) {
|
||||
if (!homeHref) throw new Error('Could not find the calendar home for this account');
|
||||
const home = abs(homeHref, b.url);
|
||||
const c = await dav('PROPFIND', home, { ...o, depth: 1, body: PROPFIND_CALS });
|
||||
const calendars = [];
|
||||
if (c.status >= 400) throw new Error(`iCloud answered ${c.status} when listing the calendars`);
|
||||
const calendars = [], seen = [];
|
||||
for (const r of responses(c.text)) {
|
||||
const rt = tag(r, 'resourcetype') || '';
|
||||
if (!/<(?:\w+:)?calendar\s*\/?>/i.test(rt)) continue;
|
||||
// Apple writes <calendar xmlns="urn:ietf:params:xml:ns:caldav"/> (with attributes, and often no prefix); the lookahead keeps
|
||||
// calendar-proxy-read, calendar-home-set etc. from matching.
|
||||
const isCal = /<(?:[\w-]+:)?calendar(?=[\s/>])/i.test(rt);
|
||||
seen.push(isCal ? 'calendar' : (rt.replace(/<(?:[\w-]+:)?([\w-]+)[^>]*>/g, '$1 ').trim() || 'other').slice(0, 30));
|
||||
if (!isCal) continue;
|
||||
const comps = tag(r, 'supported-calendar-component-set');
|
||||
const events = !comps || /name="VEVENT"/i.test(comps), todos = !!comps && /name="VTODO"/i.test(comps);
|
||||
if (!events && !todos) continue;
|
||||
@@ -76,7 +81,7 @@ async function connect(appleId, password) {
|
||||
const color = (tag(r, 'calendar-color') || '').trim().slice(0, 7);
|
||||
calendars.push({ id: calId(href), href, name: decode(tag(r, 'displayname') || 'Calendar').trim() || 'Calendar', color: /^#[0-9a-f]{6}$/i.test(color) ? color : '#d9453a', enabled: true, events, todos });
|
||||
}
|
||||
if (!calendars.length) throw new Error('No calendars found on this account');
|
||||
if (!calendars.length) throw new Error(`Signed in, but no calendars were found (iCloud listed ${seen.length} item${seen.length === 1 ? '' : 's'}: ${seen.slice(0, 6).join(', ') || 'none'}). Make sure Calendar is turned on for this Apple ID in iCloud settings.`);
|
||||
save({ user: o.user, pass: o.pass, calendars });
|
||||
return status();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user