From e7edf887136128f73aa03375d1d3f3b4ac581e26 Mon Sep 17 00:00:00 2001 From: vorotamoroz Date: Fri, 1 Mar 2024 03:28:06 +0000 Subject: [PATCH] Fixed - No longer unchanged hidden files and customisations are saved and transferred now. - File integrity of vault history indicates the integrity correctly. Improved - In the report, the schema of the remote database URI is now printed. --- src/CmdConfigSync.ts | 16 ++++++++++++++-- src/CmdHiddenFileSync.ts | 2 +- src/GlobalHistory.svelte | 3 ++- src/ObsidianLiveSyncSettingTab.ts | 3 ++- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/CmdConfigSync.ts b/src/CmdConfigSync.ts index 2250465..e7e05f8 100644 --- a/src/CmdConfigSync.ts +++ b/src/CmdConfigSync.ts @@ -4,7 +4,7 @@ import { Notice, type PluginManifest, parseYaml, normalizePath, type ListedFiles import type { EntryDoc, LoadedEntry, InternalFileEntry, FilePathWithPrefix, FilePath, DocumentID, AnyEntry, SavingEntry } from "./lib/src/types"; import { LOG_LEVEL_INFO, LOG_LEVEL_NOTICE, LOG_LEVEL_VERBOSE, MODE_SELECTIVE } from "./lib/src/types"; import { ICXHeader, PERIODIC_PLUGIN_SWEEP, } from "./types"; -import { createTextBlob, delay, getDocData, sendSignal, waitForSignal } from "./lib/src/utils"; +import { createTextBlob, delay, getDocData, isDocContentSame, sendSignal, waitForSignal } from "./lib/src/utils"; import { Logger } from "./lib/src/logger"; import { WrappedNotice } from "./lib/src/wrapper"; import { readString, decodeBinary, arrayBufferToBase64, sha1 } from "./lib/src/strbin"; @@ -687,9 +687,21 @@ export class ConfigSync extends LiveSyncCommands { }; } else { if (old.mtime == mtime) { - // Logger(`STORAGE --> DB:${file.path}: (hidden) Not changed`, LOG_LEVEL_VERBOSE); + // Logger(`STORAGE --> DB:${prefixedFileName}: (config) Skipped (Same time)`, LOG_LEVEL_VERBOSE); return true; } + const oldC = await this.localDatabase.getDBEntryFromMeta(old, {}, false, false); + if (oldC) { + const d = await deserialize(getDocData(oldC.data), {}) as PluginDataEx; + const diffs = (d.files.map(previous => ({ prev: previous, curr: dt.files.find(e => e.filename == previous.filename) })).map(async e => { + try { return await isDocContentSame(e.curr.data, e.prev.data) } catch (_) { return false } + })) + const isSame = (await Promise.all(diffs)).every(e => e == true); + if (isSame) { + Logger(`STORAGE --> DB:${prefixedFileName}: (config) Skipped (Same content)`, LOG_LEVEL_VERBOSE); + return true; + } + } saveData = { ...old, diff --git a/src/CmdHiddenFileSync.ts b/src/CmdHiddenFileSync.ts index 8521a71..a347e64 100644 --- a/src/CmdHiddenFileSync.ts +++ b/src/CmdHiddenFileSync.ts @@ -479,7 +479,7 @@ export class HiddenFileSync extends LiveSyncCommands { type: "newnote", }; } else { - if (await isDocContentSame(old.data, content) && !forceWrite) { + if (await isDocContentSame(createBinaryBlob(decodeBinary(old.data)), content) && !forceWrite) { // Logger(`STORAGE --> DB:${file.path}: (hidden) Not changed`, LOG_LEVEL_VERBOSE); return; } diff --git a/src/GlobalHistory.svelte b/src/GlobalHistory.svelte index e3c7c75..83519b4 100644 --- a/src/GlobalHistory.svelte +++ b/src/GlobalHistory.svelte @@ -7,6 +7,7 @@ import { DocumentHistoryModal } from "./DocumentHistoryModal"; import { isPlainText, stripAllPrefixes } from "./lib/src/path"; import { TFile } from "./deps"; + import { decodeBinary } from "./lib/src/strbin"; export let plugin: ObsidianLiveSyncPlugin; let showDiffInfo = false; @@ -113,7 +114,7 @@ } else { const data = await plugin.vaultAccess.adapterReadBinary(abs); const dataEEncoded = createBinaryBlob(data); - result = await isDocContentSame(dataEEncoded, doc.data); + result = await isDocContentSame(dataEEncoded, createBinaryBlob(decodeBinary(doc.data))); } if (result) { diffDetail += " ⚖️"; diff --git a/src/ObsidianLiveSyncSettingTab.ts b/src/ObsidianLiveSyncSettingTab.ts index d84707c..184f417 100644 --- a/src/ObsidianLiveSyncSettingTab.ts +++ b/src/ObsidianLiveSyncSettingTab.ts @@ -1635,7 +1635,8 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab { const pluginConfig = JSON.parse(JSON.stringify(this.plugin.settings)) as ObsidianLiveSyncSettings; pluginConfig.couchDB_DBNAME = REDACTED; pluginConfig.couchDB_PASSWORD = REDACTED; - pluginConfig.couchDB_URI = isCloudantURI(pluginConfig.couchDB_URI) ? "cloudant" : "self-hosted"; + const scheme = pluginConfig.couchDB_URI.startsWith("http:") ? "(HTTP)" : (pluginConfig.couchDB_URI.startsWith("https:")) ? "(HTTPS)" : "" + pluginConfig.couchDB_URI = isCloudantURI(pluginConfig.couchDB_URI) ? "cloudant" : `self-hosted${scheme}`; pluginConfig.couchDB_USER = REDACTED; pluginConfig.passphrase = REDACTED; pluginConfig.encryptedPassphrase = REDACTED;