Files
oikos/server/services/caldav-sync.js
T
Ulas Kalayci 7b91fa5136 Fix caldav-sync.js imports to match Task 2 spec
Remove buildICS, escapeICS, unescapeICS imports - these will be
needed in Task 5 (Sync Functions), not in Task 2. Keep only the
4 functions specified in the Task 2 spec: parseICS, formatICSDate,
tzLocalToUTC, applyDuration.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-04 07:56:57 +02:00

60 lines
1.7 KiB
JavaScript

/**
* Modul: Generic CalDAV Sync
* Zweck: Multi-Account CalDAV synchronization with calendar selection
* Abhängigkeiten: tsdav, server/db.js, server/services/ics-parser.js
*/
import { createLogger } from '../logger.js';
const log = createLogger('CalDAV');
import * as db from '../db.js';
// Reused functions from apple-calendar.js
import {
parseICS,
formatICSDate,
tzLocalToUTC,
applyDuration
} from './ics-parser.js';
// --------------------------------------------------------
// Helper Functions
// --------------------------------------------------------
function normalizeCalColor(c) {
if (!c) return null;
if (/^#[0-9a-fA-F]{8}$/.test(c)) return c.slice(0, 7); // strip alpha
if (/^#[0-9a-fA-F]{6}$/.test(c)) return c;
return null;
}
function upsertExternalCalendar(source, externalId, name, color) {
const row = db.get().prepare(`
INSERT INTO external_calendars (source, external_id, name, color)
VALUES (?, ?, ?, ?)
ON CONFLICT(source, external_id) DO UPDATE SET
name = excluded.name,
color = excluded.color
RETURNING id
`).get(source, externalId, name, color);
return row.id;
}
// --------------------------------------------------------
// Credentials Helpers
// --------------------------------------------------------
function getAccountById(accountId) {
return db.get().prepare('SELECT * FROM caldav_accounts WHERE id = ?').get(accountId);
}
function getAllAccounts() {
return db.get().prepare('SELECT * FROM caldav_accounts').all();
}
// --------------------------------------------------------
// Export placeholder (will be filled in next tasks)
// --------------------------------------------------------
export { };