feat: sync wired up

This commit is contained in:
2026-02-11 06:54:10 +01:00
parent 503d895588
commit 3126be4e90
5 changed files with 74 additions and 9 deletions

View File

@@ -64,7 +64,21 @@ export class DatabaseConnection {
return this.localDb;
}
async initializeRemote(): Promise<DrizzleDB | null> {
async initializeRemote(remoteConfig?: { tursoUrl: string; tursoAuthToken: string }): Promise<DrizzleDB | null> {
// Update config if new credentials are provided
if (remoteConfig) {
// Close existing remote connection if credentials changed
if (this.remoteClient &&
(this.config.tursoUrl !== remoteConfig.tursoUrl ||
this.config.tursoAuthToken !== remoteConfig.tursoAuthToken)) {
this.remoteClient.close();
this.remoteClient = null;
this.remoteDb = null;
}
this.config.tursoUrl = remoteConfig.tursoUrl;
this.config.tursoAuthToken = remoteConfig.tursoAuthToken;
}
if (!this.config.tursoUrl || !this.config.tursoAuthToken) {
return null;
}

View File

@@ -64,14 +64,17 @@ export class SyncEngine extends EventEmitter {
// Start auto-sync if enabled
if (config.autoSync && config.syncInterval > 0) {
this.syncIntervalId = setInterval(
() => this.sync('bidirectional'),
() => this.fullSync('bidirectional'),
config.syncInterval * 60 * 1000
);
}
// Initialize remote database connection
// Initialize remote database connection with the provided credentials
const db = getDatabase();
await db.initializeRemote();
await db.initializeRemote({
tursoUrl: config.tursoUrl,
tursoAuthToken: config.tursoAuthToken,
});
this.emit('configured', config);
}

View File

@@ -307,7 +307,7 @@ export function registerIpcHandlers(): void {
ipcMain.handle('sync:start', async (_, direction: SyncDirection = 'bidirectional') => {
const engine = getSyncEngine();
return engine.sync(direction);
return engine.fullSync(direction);
});
ipcMain.handle('sync:getStatus', async () => {
@@ -337,9 +337,28 @@ export function registerIpcHandlers(): void {
// ============ Dropbox Sync Handlers ============
ipcMain.handle('dropbox:configure', async (_, config: DropboxSyncConfig) => {
ipcMain.handle('dropbox:configure', async (_, config: Partial<DropboxSyncConfig>) => {
const engine = getDropboxSyncEngine();
return engine.configure(config);
// Inject local project paths so the engine knows where files live
const projectEngine = getProjectEngine();
const activeProject = await projectEngine.getActiveProject();
const projectId = activeProject?.id || 'default';
const paths = projectEngine.getProjectPaths(projectId);
const fullConfig: DropboxSyncConfig = {
accessToken: config.accessToken,
appKey: config.appKey || '',
appSecret: config.appSecret,
refreshToken: config.refreshToken,
syncEnabled: config.syncEnabled ?? true,
syncInterval: config.syncInterval ?? 60,
localPostsDir: paths.posts,
localMediaDir: paths.media,
remoteBasePath: config.remoteBasePath ?? (config as any).remotePath ?? '',
};
return engine.configure(fullConfig);
});
ipcMain.handle('dropbox:isConfigured', async () => {