diff --git a/mock-obsidian.ts b/mock-obsidian.ts index 6b31c96..5b4d666 100644 --- a/mock-obsidian.ts +++ b/mock-obsidian.ts @@ -156,7 +156,7 @@ export function arrayBufferToBase64(buffer: ArrayBuffer): string { } export function base64ToArrayBuffer(base64: string): ArrayBuffer { - return Buffer.from(base64, "base64"); + return Buffer.from(base64, "base64").buffer; } // Mock Event reference diff --git a/src/sync-manager.ts b/src/sync-manager.ts index da11a5a..eae673e 100644 --- a/src/sync-manager.ts +++ b/src/sync-manager.ts @@ -261,7 +261,7 @@ export default class SyncManager { } const normalizedPath = normalizePath(targetPath); - await this.vault.adapter.writeBinary(normalizedPath, data); + await this.vault.adapter.writeBinary(normalizedPath, data.buffer); await this.logger.info("Written file", { normalizedPath, }); @@ -724,12 +724,12 @@ export default class SyncManager { } } - // For non-deletion cases, if SHAs differ, we just need to check if local changed. + // For non-deletion cases, if SHAs differ, we need to check if local changed and what file was modified last // Conflicts are already filtered out so we can make this decision easily - if (localSHA !== localFile.sha) { + if (localSHA !== localFile.sha && remoteFile.lastModified < localFile.lastModified) { actions.push({ type: "upload", filePath: filePath }); return; - } else { + } else if(remoteFile.lastModified > localFile.lastModified) { actions.push({ type: "download", filePath: filePath }); return; }