feat(caldav): add caldav-sync service base structure with helpers
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* 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,
|
||||
buildICS,
|
||||
escapeICS,
|
||||
unescapeICS,
|
||||
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 { };
|
||||
Reference in New Issue
Block a user