Borked the gpg signing :(
This commit is contained in:
190
.obsidian/plugins/obsidian-livesync/main.js
vendored
190
.obsidian/plugins/obsidian-livesync/main.js
vendored
@@ -1483,7 +1483,8 @@ var DEFAULT_SETTINGS = {
|
||||
syncOnlyRegEx: "",
|
||||
customChunkSize: 0,
|
||||
readChunksOnline: true,
|
||||
watchInternalFileChanges: true
|
||||
watchInternalFileChanges: true,
|
||||
automaticallyDeleteMetadataOfDeletedFiles: 0
|
||||
};
|
||||
var FLAGMD_REDFLAG = "redflag.md";
|
||||
var SYNCINFO_ID = "syncinfo";
|
||||
@@ -3059,13 +3060,11 @@ var LocalPouchDBBase = class {
|
||||
let plainSplit = false;
|
||||
let cacheUsed = 0;
|
||||
const userPasswordHash = this.h32Raw(new TextEncoder().encode(this.settings.passphrase));
|
||||
const minimumChunkSize = this.settings.minimumChunkSize;
|
||||
if (!saveAsBigChunk && shouldSplitAsPlainText(note._id)) {
|
||||
pieceSize = MAX_DOC_SIZE;
|
||||
plainSplit = true;
|
||||
}
|
||||
const minimumChunkSize = Math.min(Math.max(40, ~~(note.data.length / 100)), maxChunkSize);
|
||||
if (pieceSize < minimumChunkSize)
|
||||
pieceSize = minimumChunkSize;
|
||||
const newLeafs = [];
|
||||
const pieces = splitPieces2(note.data, pieceSize, plainSplit, minimumChunkSize, 0);
|
||||
for (const piece of pieces()) {
|
||||
@@ -3421,6 +3420,13 @@ var LocalPouchDBBase = class {
|
||||
this.replicationErrored(e3);
|
||||
Logger("Replication stopped.", showResult ? LOG_LEVEL.NOTICE : LOG_LEVEL.INFO, "sync");
|
||||
if (this.getLastPostFailedBySize()) {
|
||||
if ("status" in e3 && e3.status == 413) {
|
||||
Logger(`Self-hosted LiveSync has detected some remote-database-incompatible chunks that exist in the local database. It means synchronization with the server had been no longer possible.
|
||||
|
||||
The problem may be caused by chunks that were created with the faulty version or by switching platforms of the database.
|
||||
To solve the circumstance, configure the remote database correctly or we have to rebuild both local and remote databases.`, LOG_LEVEL.NOTICE);
|
||||
return;
|
||||
}
|
||||
const tempSetting = JSON.parse(JSON.stringify(setting));
|
||||
tempSetting.batch_size = Math.ceil(tempSetting.batch_size / 2) + 2;
|
||||
tempSetting.batches_limit = Math.ceil(tempSetting.batches_limit / 2) + 2;
|
||||
@@ -10121,7 +10127,7 @@ var LocalPouchDB = class extends LocalPouchDBBase {
|
||||
await this.kvDB.destroy();
|
||||
}
|
||||
getLastPostFailedBySize() {
|
||||
return this.last_successful_post;
|
||||
return !this.last_successful_post;
|
||||
}
|
||||
async fetchByAPI(request) {
|
||||
var _a, _b;
|
||||
@@ -10162,7 +10168,7 @@ var LocalPouchDB = class extends LocalPouchDBBase {
|
||||
const method = (_a = opts.method) != null ? _a : "GET";
|
||||
if (opts.body) {
|
||||
const opts_length = opts.body.toString().length;
|
||||
if (opts_length > 1024 * 1024 * 10) {
|
||||
if (opts_length > 1e3 * 1e3 * 10) {
|
||||
if (isCloudantURI(uri)) {
|
||||
this.last_successful_post = false;
|
||||
Logger("This request should fail on IBM Cloudant.", LOG_LEVEL.VERBOSE);
|
||||
@@ -10309,8 +10315,8 @@ var ConflictResolveModal = class extends import_obsidian4.Modal {
|
||||
diff = diff.replace(/\n/g, "<br>");
|
||||
div.innerHTML = diff;
|
||||
const div2 = contentEl.createDiv("");
|
||||
const date1 = new Date(this.result.left.mtime).toLocaleString();
|
||||
const date2 = new Date(this.result.right.mtime).toLocaleString();
|
||||
const date1 = new Date(this.result.left.mtime).toLocaleString() + (this.result.left.deleted ? " (Deleted)" : "");
|
||||
const date2 = new Date(this.result.right.mtime).toLocaleString() + (this.result.right.deleted ? " (Deleted)" : "");
|
||||
div2.innerHTML = `
|
||||
<span class='deleted'>A:${date1}</span><br /><span class='added'>B:${date2}</span><br>
|
||||
`;
|
||||
@@ -10440,8 +10446,8 @@ var ObsidianLiveSyncSettingTab = class extends import_obsidian5.PluginSettingTab
|
||||
const containerInformationEl = containerEl.createDiv();
|
||||
const h3El = containerInformationEl.createEl("h3", { text: "Updates" });
|
||||
const informationDivEl = containerInformationEl.createEl("div", { text: "" });
|
||||
const manifestVersion = "0.16.4";
|
||||
const updateInformation = "### 0.16.0\n- Now hidden files need not be scanned. Changes will be detected automatically.\n - If you want it to back to its previous behaviour, please disable `Monitor changes to internal files`.\n - Due to using an internal API, this feature may become unusable with a major update. If this happens, please disable this once.\n\n#### Minors\n\n- 0.16.1 Added missing log updates.\n- 0.16.2 Fixed many problems caused by combinations of `Sync On Save` and the tracking logic that changed at 0.15.6.\n- 0.16.3\n - Fixed detection of IBM Cloudant (And if there are some issues, be fixed automatically).\n - A configuration information reporting tool has been implemented.\n- 0.16.4 Fixed detection failure. Please set the `Chunk size` again when using a self-hosted database.\n\n### 0.15.0\n- Outdated configuration items have been removed.\n- Setup wizard has been implemented!\n\nI appreciate for reviewing and giving me advice @Pouhon158!\n\n#### Minors\n- 0.15.1 Missed the stylesheet.\n- 0.15.2 The wizard has been improved and documented!\n- 0.15.3 Fixed the issue about locking/unlocking remote database while rebuilding in the wizard.\n- 0.15.4 Fixed issues about asynchronous processing (e.g., Conflict check or hidden file detection)\n- 0.15.5 Add new features for setting Self-hosted LiveSync up more easier.\n- 0.15.6 File tracking logic has been refined.\n- 0.15.7 Fixed bug about renaming file.\n- 0.15.8 Fixed bug about deleting empty directory, weird behaviour on boot-sequence on mobile devices.\n- 0.15.9 Improved chunk retrieving, now chunks are retrieved in batch on continuous requests.\n- 0.15.10 Fixed:\n - The boot sequence has been corrected and now boots smoothly.\n - Auto applying of batch save will be processed earlier than before.\n\n... To continue on to `updates_old.md`.";
|
||||
const manifestVersion = "0.16.6";
|
||||
const updateInformation = "### 0.16.0\n- Now hidden files need not be scanned. Changes will be detected automatically.\n - If you want it to back to its previous behaviour, please disable `Monitor changes to internal files`.\n - Due to using an internal API, this feature may become unusable with a major update. If this happens, please disable this once.\n\n#### Minors\n\n- 0.16.1 Added missing log updates.\n- 0.16.2 Fixed many problems caused by combinations of `Sync On Save` and the tracking logic that changed at 0.15.6.\n- 0.16.3\n - Fixed detection of IBM Cloudant (And if there are some issues, be fixed automatically).\n - A configuration information reporting tool has been implemented.\n- 0.16.4 Fixed detection failure. Please set the `Chunk size` again when using a self-hosted database.\n- 0.16.5\n - Fixed\n - Conflict detection and merging now be able to treat deleted files.\n - Logs while the boot-up sequence has been tidied up.\n - Fixed incorrect log entries.\n - New Feature\n - The feature of automatically deleting old expired metadata has been implemented.\n We can configure it in `Delete old metadata of deleted files on start-up` in the `General Settings` pane.\n- 0.16.6\n - Fixed\n - Automatic (temporary) batch size adjustment has been restored to work correctly.\n - Chunk splitting has been backed to the previous behaviour for saving them correctly.\n - Improved\n - Corrupted chunks will be detected automatically.\n - Now on the case-insensitive system, `aaa.md` and `AAA.md` will be treated as the same file or path at applying changesets.\n\nNote:\nBefore 0.16.5, LiveSync had some issues making chunks. In this case, synchronisation had became been always failing after a corrupted one should be made. After 0.16.6, the corrupted chunk is automatically detected. Sorry for troubling you but please do `rebuild everything` when this plug-in notified so.\n\n### 0.15.0\n- Outdated configuration items have been removed.\n- Setup wizard has been implemented!\n\nI appreciate for reviewing and giving me advice @Pouhon158!\n\n#### Minors\n- 0.15.1 Missed the stylesheet.\n- 0.15.2 The wizard has been improved and documented!\n- 0.15.3 Fixed the issue about locking/unlocking remote database while rebuilding in the wizard.\n- 0.15.4 Fixed issues about asynchronous processing (e.g., Conflict check or hidden file detection)\n- 0.15.5 Add new features for setting Self-hosted LiveSync up more easier.\n- 0.15.6 File tracking logic has been refined.\n- 0.15.7 Fixed bug about renaming file.\n- 0.15.8 Fixed bug about deleting empty directory, weird behaviour on boot-sequence on mobile devices.\n- 0.15.9 Improved chunk retrieving, now chunks are retrieved in batch on continuous requests.\n- 0.15.10 Fixed:\n - The boot sequence has been corrected and now boots smoothly.\n - Auto applying of batch save will be processed earlier than before.\n\n... To continue on to `updates_old.md`.";
|
||||
const lastVersion = ~~(versionNumberString2Number(manifestVersion) / 1e3);
|
||||
const tmpDiv = createSpan();
|
||||
tmpDiv.addClass("sls-header-button");
|
||||
@@ -10915,6 +10921,17 @@ var ObsidianLiveSyncSettingTab = class extends import_obsidian5.PluginSettingTab
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
new import_obsidian5.Setting(containerGeneralSettingsEl).setName("Delete old metadata of deleted files on start-up").setClass("wizardHidden").setDesc("(Days passed, 0 to disable automatic-deletion)").addText((text2) => {
|
||||
text2.setPlaceholder("").setValue(this.plugin.settings.automaticallyDeleteMetadataOfDeletedFiles + "").onChange(async (value) => {
|
||||
let v = Number(value);
|
||||
if (isNaN(v)) {
|
||||
v = 0;
|
||||
}
|
||||
this.plugin.settings.automaticallyDeleteMetadataOfDeletedFiles = v;
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
text2.inputEl.setAttribute("type", "number");
|
||||
});
|
||||
addScreenElement("20", containerGeneralSettingsEl);
|
||||
const containerSyncSettingEl = containerEl.createDiv();
|
||||
containerSyncSettingEl.createEl("h3", { text: "Sync Settings" });
|
||||
@@ -12825,6 +12842,14 @@ var ICHeader = "i:";
|
||||
var ICHeaderEnd = "i;";
|
||||
var ICHeaderLength = ICHeader.length;
|
||||
var FileWatchEventQueueMax = 10;
|
||||
function getAbstractFileByPath(path) {
|
||||
var _a, _b;
|
||||
if ("getAbstractFileByPathInsensitive" in app.vault && ((_b = (_a = app.vault.adapter) == null ? void 0 : _a.insensitive) != null ? _b : false)) {
|
||||
return app.vault.getAbstractFileByPathInsensitive(path);
|
||||
} else {
|
||||
return app.vault.getAbstractFileByPath(path);
|
||||
}
|
||||
}
|
||||
function isInternalChunk(str) {
|
||||
return str.startsWith(ICHeader);
|
||||
}
|
||||
@@ -12865,7 +12890,7 @@ var askString = (app2, title, key, placeholder) => {
|
||||
};
|
||||
var touchedFiles = [];
|
||||
function touch(file) {
|
||||
const f = file instanceof import_obsidian8.TFile ? file : app.vault.getAbstractFileByPath(file);
|
||||
const f = file instanceof import_obsidian8.TFile ? file : getAbstractFileByPath(file);
|
||||
const key = `${f.path}-${f.stat.mtime}-${f.stat.size}`;
|
||||
touchedFiles.unshift(key);
|
||||
touchedFiles = touchedFiles.slice(0, 100);
|
||||
@@ -12914,7 +12939,7 @@ var ObsidianLiveSyncPlugin = class extends import_obsidian8.Plugin {
|
||||
return timer;
|
||||
}
|
||||
isRedFlagRaised() {
|
||||
const redflag = this.app.vault.getAbstractFileByPath((0, import_obsidian8.normalizePath)(FLAGMD_REDFLAG));
|
||||
const redflag = getAbstractFileByPath((0, import_obsidian8.normalizePath)(FLAGMD_REDFLAG));
|
||||
if (redflag != null) {
|
||||
return true;
|
||||
}
|
||||
@@ -12968,10 +12993,6 @@ var ObsidianLiveSyncPlugin = class extends import_obsidian8.Plugin {
|
||||
continue;
|
||||
if (isInternalChunk(row.id))
|
||||
continue;
|
||||
if (doc._deleted)
|
||||
continue;
|
||||
if ("deleted" in doc && doc.deleted)
|
||||
continue;
|
||||
if (doc.type == "newnote" || doc.type == "plain") {
|
||||
notes.push({ path: id2path(doc._id), mtime: doc.mtime });
|
||||
}
|
||||
@@ -12990,15 +13011,53 @@ var ObsidianLiveSyncPlugin = class extends import_obsidian8.Plugin {
|
||||
if (target) {
|
||||
if (isInternalChunk(target)) {
|
||||
} else {
|
||||
await this.showIfConflicted(this.app.vault.getAbstractFileByPath(target));
|
||||
await this.showIfConflicted(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
async collectDeletedFiles() {
|
||||
const pageLimit = 1e3;
|
||||
let nextKey = "";
|
||||
const limitDays = this.settings.automaticallyDeleteMetadataOfDeletedFiles;
|
||||
if (limitDays <= 0)
|
||||
return;
|
||||
Logger(`Checking expired file history`);
|
||||
const limit = Date.now() - 86400 * 1e3 * limitDays;
|
||||
const notes = [];
|
||||
do {
|
||||
const docs = await this.localDatabase.localDatabase.allDocs({ limit: pageLimit, startkey: nextKey, conflicts: true, include_docs: true });
|
||||
nextKey = "";
|
||||
for (const row of docs.rows) {
|
||||
const doc = row.doc;
|
||||
nextKey = `${row.id}\u{10FFFF}`;
|
||||
if (doc.type == "newnote" || doc.type == "plain") {
|
||||
if (doc.deleted && doc.mtime - limit < 0) {
|
||||
notes.push({ path: id2path(doc._id), mtime: doc.mtime, ttl: (doc.mtime - limit) / 1e3 / 86400, doc });
|
||||
}
|
||||
}
|
||||
if (isChunk(nextKey)) {
|
||||
nextKey = CHeaderEnd;
|
||||
}
|
||||
}
|
||||
} while (nextKey != "");
|
||||
if (notes.length == 0) {
|
||||
Logger("There are no old documents");
|
||||
Logger(`Checking expired file history done`);
|
||||
return;
|
||||
}
|
||||
for (const v of notes) {
|
||||
Logger(`Deletion history expired: ${v.path}`);
|
||||
const delDoc = v.doc;
|
||||
delDoc._deleted = true;
|
||||
await this.localDatabase.localDatabase.put(delDoc);
|
||||
}
|
||||
Logger(`Checking expired file history done`);
|
||||
}
|
||||
async onload() {
|
||||
setLogger(this.addLog.bind(this));
|
||||
Logger("loading plugin");
|
||||
const manifestVersion = "0.16.4";
|
||||
const packageVersion = "0.16.4";
|
||||
const manifestVersion = "0.16.6";
|
||||
const packageVersion = "0.16.6";
|
||||
Logger(`Self-hosted LiveSync v${manifestVersion} ${packageVersion} `);
|
||||
const lsKey = "obsidian-live-sync-ver" + this.getVaultName();
|
||||
const last_version = localStorage.getItem(lsKey);
|
||||
@@ -13270,7 +13329,7 @@ var ObsidianLiveSyncPlugin = class extends import_obsidian8.Plugin {
|
||||
id: "livesync-checkdoc-conflicted",
|
||||
name: "Resolve if conflicted.",
|
||||
editorCallback: async (editor, view) => {
|
||||
await this.showIfConflicted(view.file);
|
||||
await this.showIfConflicted(view.file.path);
|
||||
}
|
||||
});
|
||||
this.addCommand({
|
||||
@@ -13620,7 +13679,7 @@ var ObsidianLiveSyncPlugin = class extends import_obsidian8.Plugin {
|
||||
if (this.settings.syncOnFileOpen && !this.suspended) {
|
||||
await this.replicate();
|
||||
}
|
||||
await this.showIfConflicted(file);
|
||||
await this.showIfConflicted(file.path);
|
||||
}
|
||||
async applyBatchChange() {
|
||||
if (this.settings.batchSave) {
|
||||
@@ -13693,7 +13752,7 @@ var ObsidianLiveSyncPlugin = class extends import_obsidian8.Plugin {
|
||||
for (const i2 of newFiles) {
|
||||
try {
|
||||
const newFilePath = (0, import_obsidian8.normalizePath)(this.getFilePath(i2));
|
||||
const newFile = this.app.vault.getAbstractFileByPath(newFilePath);
|
||||
const newFile = getAbstractFileByPath(newFilePath);
|
||||
if (newFile instanceof import_obsidian8.TFile) {
|
||||
Logger(`save ${newFile.path} into db`);
|
||||
await this.updateIntoDB(newFile);
|
||||
@@ -13837,7 +13896,7 @@ var ObsidianLiveSyncPlugin = class extends import_obsidian8.Plugin {
|
||||
touch(newFile);
|
||||
this.app.vault.trigger("create", newFile);
|
||||
} catch (ex) {
|
||||
Logger(msg + "ERROR, Could not parse: " + path + "(" + doc.datatype + ")", LOG_LEVEL.NOTICE);
|
||||
Logger(msg + "ERROR, Could not create: " + path + "(" + doc.datatype + ")", LOG_LEVEL.NOTICE);
|
||||
Logger(ex, LOG_LEVEL.VERBOSE);
|
||||
}
|
||||
} else {
|
||||
@@ -13900,7 +13959,7 @@ var ObsidianLiveSyncPlugin = class extends import_obsidian8.Plugin {
|
||||
try {
|
||||
await this.app.vault.modifyBinary(file, bin, { ctime: doc.ctime, mtime: doc.mtime });
|
||||
Logger(msg + path);
|
||||
const xf = this.app.vault.getAbstractFileByPath(file.path);
|
||||
const xf = getAbstractFileByPath(file.path);
|
||||
touch(xf);
|
||||
this.app.vault.trigger("modify", xf);
|
||||
} catch (ex) {
|
||||
@@ -13916,7 +13975,7 @@ var ObsidianLiveSyncPlugin = class extends import_obsidian8.Plugin {
|
||||
try {
|
||||
await this.app.vault.modify(file, doc.data, { ctime: doc.ctime, mtime: doc.mtime });
|
||||
Logger(msg + path);
|
||||
const xf = this.app.vault.getAbstractFileByPath(file.path);
|
||||
const xf = getAbstractFileByPath(file.path);
|
||||
touch(xf);
|
||||
this.app.vault.trigger("modify", xf);
|
||||
} catch (ex) {
|
||||
@@ -13956,7 +14015,7 @@ var ObsidianLiveSyncPlugin = class extends import_obsidian8.Plugin {
|
||||
this.refreshStatusText();
|
||||
}
|
||||
async handleDBChangedAsync(change) {
|
||||
const targetFile = this.app.vault.getAbstractFileByPath(id2path(change._id));
|
||||
const targetFile = getAbstractFileByPath(id2path(change._id));
|
||||
if (targetFile == null) {
|
||||
if (change._deleted || change.deleted) {
|
||||
return;
|
||||
@@ -14062,7 +14121,7 @@ var ObsidianLiveSyncPlugin = class extends import_obsidian8.Plugin {
|
||||
return;
|
||||
const skipOldFile = this.settings.skipOlderFilesOnSync && false;
|
||||
if (!isInternalChunk(doc._id) && skipOldFile) {
|
||||
const info = this.app.vault.getAbstractFileByPath(id2path(doc._id));
|
||||
const info = getAbstractFileByPath(id2path(doc._id));
|
||||
if (info && info instanceof import_obsidian8.TFile) {
|
||||
const localMtime = ~~(info.stat.mtime / 1e3);
|
||||
const docMtime = ~~(doc.mtime / 1e3);
|
||||
@@ -14336,10 +14395,11 @@ var ObsidianLiveSyncPlugin = class extends import_obsidian8.Plugin {
|
||||
if (showingNotice) {
|
||||
Logger("Initializing", LOG_LEVEL.NOTICE, "syncAll");
|
||||
}
|
||||
await this.collectDeletedFiles();
|
||||
const filesStorage = this.app.vault.getFiles().filter((e3) => this.isTargetFile(e3));
|
||||
const filesStorageName = filesStorage.map((e3) => e3.path);
|
||||
const wf = await this.localDatabase.localDatabase.allDocs();
|
||||
const filesDatabase = wf.rows.filter((e3) => !isChunk(e3.id) && !isPluginChunk(e3.id) && e3.id != "obsydian_livesync_version").filter((e3) => isValidPath(e3.id)).map((e3) => id2path(e3.id)).filter((e3) => this.isTargetFile(e3));
|
||||
const filesDatabase = wf.rows.filter((e3) => !isChunk(e3.id) && !isPluginChunk(e3.id) && e3.id != "obsydian_livesync_version" && e3.id != "_design/replicate").filter((e3) => isValidPath(e3.id)).map((e3) => id2path(e3.id)).filter((e3) => this.isTargetFile(e3));
|
||||
const isInitialized = await this.localDatabase.kvDB.get("initialized") || false;
|
||||
if (filesDatabase.length == 0 && !isInitialized) {
|
||||
initialScan = true;
|
||||
@@ -14353,27 +14413,14 @@ var ObsidianLiveSyncPlugin = class extends import_obsidian8.Plugin {
|
||||
Logger("Updating database by new files");
|
||||
this.setStatusBarText(`UPDATE DATABASE`);
|
||||
const runAll = async (procedureName, objects, callback) => {
|
||||
const count = objects.length;
|
||||
Logger(procedureName);
|
||||
let i2 = 0;
|
||||
const semaphore = Semaphore(10);
|
||||
Logger(`${procedureName} exec.`);
|
||||
if (!this.localDatabase.isReady)
|
||||
throw Error("Database is not ready!");
|
||||
const processes = objects.map((e3) => (async (v) => {
|
||||
const releaser = await semaphore.acquire(1, procedureName);
|
||||
try {
|
||||
await callback(v);
|
||||
i2++;
|
||||
if (i2 % 50 == 0) {
|
||||
const notify = `${procedureName} : ${i2}/${count}`;
|
||||
if (showingNotice) {
|
||||
Logger(notify, LOG_LEVEL.NOTICE, "syncAll");
|
||||
} else {
|
||||
Logger(notify);
|
||||
}
|
||||
this.setStatusBarText(notify);
|
||||
}
|
||||
} catch (ex) {
|
||||
Logger(`Error while ${procedureName}`, LOG_LEVEL.NOTICE);
|
||||
Logger(ex);
|
||||
@@ -14390,13 +14437,15 @@ var ObsidianLiveSyncPlugin = class extends import_obsidian8.Plugin {
|
||||
});
|
||||
if (!initialScan) {
|
||||
await runAll("UPDATE STORAGE", onlyInDatabase, async (e3) => {
|
||||
const w = await this.localDatabase.getDBEntryMeta(e3);
|
||||
if (w) {
|
||||
const w = await this.localDatabase.getDBEntryMeta(e3, {}, true);
|
||||
if (w && !(w.deleted || w._deleted)) {
|
||||
Logger(`Check or pull from db:${e3}`);
|
||||
await this.pullFile(e3, filesStorage, false, null, false);
|
||||
Logger(`Check or pull from db:${e3} OK`);
|
||||
} else if (w) {
|
||||
Logger(`Deletion history skipped: ${e3}`, LOG_LEVEL.VERBOSE);
|
||||
} else {
|
||||
Logger(`entry not found, maybe deleted (it is normal behavior):${e3}`);
|
||||
Logger(`entry not found: ${e3}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -14466,7 +14515,7 @@ var ObsidianLiveSyncPlugin = class extends import_obsidian8.Plugin {
|
||||
}
|
||||
async getConflictedDoc(path, rev) {
|
||||
try {
|
||||
const doc = await this.localDatabase.getDBEntry(path, { rev }, false, false);
|
||||
const doc = await this.localDatabase.getDBEntry(path, { rev }, false, false, true);
|
||||
if (doc === false)
|
||||
return false;
|
||||
let data = doc.data;
|
||||
@@ -14476,6 +14525,7 @@ var ObsidianLiveSyncPlugin = class extends import_obsidian8.Plugin {
|
||||
data = doc.data;
|
||||
}
|
||||
return {
|
||||
deleted: doc.deleted || doc._deleted,
|
||||
ctime: doc.ctime,
|
||||
mtime: doc.mtime,
|
||||
rev,
|
||||
@@ -14489,7 +14539,7 @@ var ObsidianLiveSyncPlugin = class extends import_obsidian8.Plugin {
|
||||
return false;
|
||||
}
|
||||
async getConflictedStatus(path) {
|
||||
const test = await this.localDatabase.getDBEntry(path, { conflicts: true }, false, false);
|
||||
const test = await this.localDatabase.getDBEntry(path, { conflicts: true }, false, false, true);
|
||||
if (test === false)
|
||||
return false;
|
||||
if (test == null)
|
||||
@@ -14510,7 +14560,7 @@ var ObsidianLiveSyncPlugin = class extends import_obsidian8.Plugin {
|
||||
Logger(`could not get old revisions, automatically used newer one:${path}`, LOG_LEVEL.NOTICE);
|
||||
return true;
|
||||
}
|
||||
if (leftLeaf.data == rightLeaf.data) {
|
||||
if (leftLeaf.data == rightLeaf.data && leftLeaf.deleted == rightLeaf.deleted) {
|
||||
let leaf = leftLeaf;
|
||||
if (leftLeaf.mtime > rightLeaf.mtime) {
|
||||
leaf = rightLeaf;
|
||||
@@ -14542,11 +14592,11 @@ var ObsidianLiveSyncPlugin = class extends import_obsidian8.Plugin {
|
||||
diff
|
||||
};
|
||||
}
|
||||
showMergeDialog(file, conflictCheckResult) {
|
||||
showMergeDialog(filename, conflictCheckResult) {
|
||||
return new Promise((res, rej) => {
|
||||
Logger("open conflict dialog", LOG_LEVEL.VERBOSE);
|
||||
new ConflictResolveModal(this.app, conflictCheckResult, async (selected) => {
|
||||
const testDoc = await this.localDatabase.getDBEntry(file.path, { conflicts: true });
|
||||
const testDoc = await this.localDatabase.getDBEntry(filename, { conflicts: true }, false, false, true);
|
||||
if (testDoc === false) {
|
||||
Logger("Missing file..", LOG_LEVEL.VERBOSE);
|
||||
return res(true);
|
||||
@@ -14559,23 +14609,29 @@ var ObsidianLiveSyncPlugin = class extends import_obsidian8.Plugin {
|
||||
const toKeep = conflictCheckResult.left.rev != toDelete ? conflictCheckResult.left.rev : conflictCheckResult.right.rev;
|
||||
if (toDelete == "") {
|
||||
const p = conflictCheckResult.diff.map((e3) => e3[1]).join("");
|
||||
await this.localDatabase.deleteDBEntry(file.path, { rev: conflictCheckResult.left.rev });
|
||||
await this.localDatabase.deleteDBEntry(file.path, { rev: conflictCheckResult.right.rev });
|
||||
await this.app.vault.modify(file, p);
|
||||
await this.updateIntoDB(file);
|
||||
await this.pullFile(file.path);
|
||||
await this.localDatabase.deleteDBEntry(filename, { rev: conflictCheckResult.left.rev });
|
||||
await this.localDatabase.deleteDBEntry(filename, { rev: conflictCheckResult.right.rev });
|
||||
const file = getAbstractFileByPath(filename);
|
||||
if (file) {
|
||||
await this.app.vault.modify(file, p);
|
||||
await this.updateIntoDB(file);
|
||||
} else {
|
||||
const newFile = await this.app.vault.create(filename, p);
|
||||
await this.updateIntoDB(newFile);
|
||||
}
|
||||
await this.pullFile(filename);
|
||||
Logger("concat both file");
|
||||
setTimeout(() => {
|
||||
this.showIfConflicted(file);
|
||||
this.showIfConflicted(filename);
|
||||
}, 500);
|
||||
} else if (toDelete == null) {
|
||||
Logger("Leave it still conflicted");
|
||||
} else {
|
||||
Logger(`Conflict resolved:${file.path}`);
|
||||
await this.localDatabase.deleteDBEntry(file.path, { rev: toDelete });
|
||||
await this.pullFile(file.path, null, true, toKeep);
|
||||
Logger(`Conflict resolved:${filename}`);
|
||||
await this.localDatabase.deleteDBEntry(filename, { rev: toDelete });
|
||||
await this.pullFile(filename, null, true, toKeep);
|
||||
setTimeout(() => {
|
||||
this.showIfConflicted(file);
|
||||
this.showIfConflicted(filename);
|
||||
}, 500);
|
||||
}
|
||||
return res(true);
|
||||
@@ -14593,9 +14649,9 @@ var ObsidianLiveSyncPlugin = class extends import_obsidian8.Plugin {
|
||||
const checkFiles = JSON.parse(JSON.stringify(this.conflictedCheckFiles));
|
||||
for (const filename of checkFiles) {
|
||||
try {
|
||||
const file2 = this.app.vault.getAbstractFileByPath(filename);
|
||||
const file2 = getAbstractFileByPath(filename);
|
||||
if (file2 != null && file2 instanceof import_obsidian8.TFile) {
|
||||
await this.showIfConflicted(file2);
|
||||
await this.showIfConflicted(file2.path);
|
||||
}
|
||||
} catch (ex) {
|
||||
Logger(ex);
|
||||
@@ -14603,24 +14659,24 @@ var ObsidianLiveSyncPlugin = class extends import_obsidian8.Plugin {
|
||||
}
|
||||
}, 1e3);
|
||||
}
|
||||
async showIfConflicted(file) {
|
||||
async showIfConflicted(filename) {
|
||||
await runWithLock("conflicted", false, async () => {
|
||||
const conflictCheckResult = await this.getConflictedStatus(file.path);
|
||||
const conflictCheckResult = await this.getConflictedStatus(filename);
|
||||
if (conflictCheckResult === false) {
|
||||
return;
|
||||
}
|
||||
if (conflictCheckResult === true) {
|
||||
Logger("conflict:Automatically merged, but we have to check it again");
|
||||
setTimeout(() => {
|
||||
this.showIfConflicted(file);
|
||||
this.showIfConflicted(filename);
|
||||
}, 500);
|
||||
return;
|
||||
}
|
||||
await this.showMergeDialog(file, conflictCheckResult);
|
||||
await this.showMergeDialog(filename, conflictCheckResult);
|
||||
});
|
||||
}
|
||||
async pullFile(filename, fileList, force, rev, waitForReady = true) {
|
||||
const targetFile = this.app.vault.getAbstractFileByPath(id2path(filename));
|
||||
const targetFile = getAbstractFileByPath(id2path(filename));
|
||||
if (!this.isTargetFile(id2path(filename)))
|
||||
return;
|
||||
if (targetFile == null) {
|
||||
@@ -14647,7 +14703,7 @@ var ObsidianLiveSyncPlugin = class extends import_obsidian8.Plugin {
|
||||
throw new Error(`Missing doc:${file.path}`);
|
||||
}
|
||||
if (!(file instanceof import_obsidian8.TFile) && "path" in file) {
|
||||
const w = this.app.vault.getAbstractFileByPath(file.path);
|
||||
const w = getAbstractFileByPath(file.path);
|
||||
if (w instanceof import_obsidian8.TFile) {
|
||||
file = w;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user