mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-05-09 17:21:54 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ceb671683 | ||
|
|
ea40e5918c | ||
|
|
830f2f25d1 | ||
|
|
05f0abebf0 | ||
|
|
842da980d7 |
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"id": "obsidian-livesync",
|
"id": "obsidian-livesync",
|
||||||
"name": "Self-hosted LiveSync",
|
"name": "Self-hosted LiveSync",
|
||||||
"version": "0.19.3",
|
"version": "0.19.5",
|
||||||
"minAppVersion": "0.9.12",
|
"minAppVersion": "0.9.12",
|
||||||
"description": "Community implementation of self-hosted livesync. Reflect your vault changes to some other devices immediately. Please make sure to disable other synchronize solutions to avoid content corruption or duplication.",
|
"description": "Community implementation of self-hosted livesync. Reflect your vault changes to some other devices immediately. Please make sure to disable other synchronize solutions to avoid content corruption or duplication.",
|
||||||
"author": "vorotamoroz",
|
"author": "vorotamoroz",
|
||||||
|
|||||||
16
package-lock.json
generated
16
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "obsidian-livesync",
|
"name": "obsidian-livesync",
|
||||||
"version": "0.19.3",
|
"version": "0.19.5",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "obsidian-livesync",
|
"name": "obsidian-livesync",
|
||||||
"version": "0.19.3",
|
"version": "0.19.5",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"diff-match-patch": "^1.0.5",
|
"diff-match-patch": "^1.0.5",
|
||||||
@@ -4087,9 +4087,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/yaml": {
|
"node_modules/yaml": {
|
||||||
"version": "2.1.3",
|
"version": "2.2.2",
|
||||||
"resolved": "https://registry.npmjs.org/yaml/-/yaml-2.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/yaml/-/yaml-2.2.2.tgz",
|
||||||
"integrity": "sha512-AacA8nRULjKMX2DvWvOAdBZMOfQlypSFkjcOcu9FalllIDJ1kvlREzcdIZmidQUqqeMv7jorHjq2HlLv/+c2lg==",
|
"integrity": "sha512-CBKFWExMn46Foo4cldiChEzn7S7SRV+wqiluAb6xmueD/fGyRHIhX8m14vVGgeFWjN540nKCNVj6P21eQjgTuA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 14"
|
"node": ">= 14"
|
||||||
@@ -7047,9 +7047,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"yaml": {
|
"yaml": {
|
||||||
"version": "2.1.3",
|
"version": "2.2.2",
|
||||||
"resolved": "https://registry.npmjs.org/yaml/-/yaml-2.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/yaml/-/yaml-2.2.2.tgz",
|
||||||
"integrity": "sha512-AacA8nRULjKMX2DvWvOAdBZMOfQlypSFkjcOcu9FalllIDJ1kvlREzcdIZmidQUqqeMv7jorHjq2HlLv/+c2lg==",
|
"integrity": "sha512-CBKFWExMn46Foo4cldiChEzn7S7SRV+wqiluAb6xmueD/fGyRHIhX8m14vVGgeFWjN540nKCNVj6P21eQjgTuA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"yocto-queue": {
|
"yocto-queue": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "obsidian-livesync",
|
"name": "obsidian-livesync",
|
||||||
"version": "0.19.3",
|
"version": "0.19.5",
|
||||||
"description": "Reflect your vault changes to some other devices immediately. Please make sure to disable other synchronize solutions to avoid content corruption or duplication.",
|
"description": "Reflect your vault changes to some other devices immediately. Please make sure to disable other synchronize solutions to avoid content corruption or duplication.",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import { writable } from 'svelte/store';
|
import { writable } from 'svelte/store';
|
||||||
import { Notice, PluginManifest, stringifyYaml, parseYaml } from "./deps";
|
import { Notice, PluginManifest, parseYaml } from "./deps";
|
||||||
|
|
||||||
import { EntryDoc, LoadedEntry, LOG_LEVEL, InternalFileEntry, FilePathWithPrefix, FilePath, DocumentID } from "./lib/src/types";
|
import { EntryDoc, LoadedEntry, LOG_LEVEL, InternalFileEntry, FilePathWithPrefix, FilePath, DocumentID } from "./lib/src/types";
|
||||||
import { ICXHeader, PERIODIC_PLUGIN_SWEEP, } from "./types";
|
import { ICXHeader, PERIODIC_PLUGIN_SWEEP, } from "./types";
|
||||||
import { delay, getDocData } from "./lib/src/utils";
|
import { Parallels, delay, getDocData } from "./lib/src/utils";
|
||||||
import { Logger } from "./lib/src/logger";
|
import { Logger } from "./lib/src/logger";
|
||||||
import { PouchDB } from "./lib/src/pouchdb-browser.js";
|
import { PouchDB } from "./lib/src/pouchdb-browser.js";
|
||||||
import { WrappedNotice } from "./lib/src/wrapper";
|
import { WrappedNotice } from "./lib/src/wrapper";
|
||||||
import { base64ToArrayBuffer, arrayBufferToBase64, readString, writeString, uint8ArrayToHexString } from "./lib/src/strbin";
|
import { base64ToArrayBuffer, arrayBufferToBase64, readString, uint8ArrayToHexString } from "./lib/src/strbin";
|
||||||
import { runWithLock } from "./lib/src/lock";
|
import { runWithLock } from "./lib/src/lock";
|
||||||
import { LiveSyncCommands } from "./LiveSyncCommands";
|
import { LiveSyncCommands } from "./LiveSyncCommands";
|
||||||
import { stripAllPrefixes } from "./lib/src/path";
|
import { stripAllPrefixes } from "./lib/src/path";
|
||||||
@@ -17,13 +17,29 @@ import { PluginDialogModal } from "./dialogs";
|
|||||||
import { JsonResolveModal } from "./JsonResolveModal";
|
import { JsonResolveModal } from "./JsonResolveModal";
|
||||||
|
|
||||||
|
|
||||||
|
function serialize<T>(obj: T): string {
|
||||||
|
return JSON.stringify(obj, null, 1);
|
||||||
|
}
|
||||||
|
function deserialize<T>(str: string, def: T) {
|
||||||
|
try {
|
||||||
|
return JSON.parse(str) as T;
|
||||||
|
} catch (ex) {
|
||||||
|
try {
|
||||||
|
return parseYaml(str);
|
||||||
|
} catch (ex) {
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export const pluginList = writable([] as PluginDataExDisplay[]);
|
export const pluginList = writable([] as PluginDataExDisplay[]);
|
||||||
export const pluginIsEnumerating = writable(false);
|
export const pluginIsEnumerating = writable(false);
|
||||||
|
|
||||||
|
const encoder = new TextEncoder();
|
||||||
const hashString = (async (key: string) => {
|
const hashString = (async (key: string) => {
|
||||||
const buff = writeString(key);
|
// const buff = writeString(key);
|
||||||
|
const buff = encoder.encode(key);
|
||||||
const digest = await crypto.subtle.digest('SHA-256', buff);
|
const digest = await crypto.subtle.digest('SHA-256', buff);
|
||||||
return uint8ArrayToHexString(new Uint8Array(digest));
|
return uint8ArrayToHexString(new Uint8Array(digest));
|
||||||
})
|
})
|
||||||
@@ -145,7 +161,7 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
if (this.plugin.suspended) {
|
if (this.plugin.suspended) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.settings.autoSweepPlugins) {
|
if (this.settings.autoSweepPlugins && this.settings.usePluginSync) {
|
||||||
await this.scanAllConfigFiles(false);
|
await this.scanAllConfigFiles(false);
|
||||||
}
|
}
|
||||||
this.periodicPluginSweepProcessor.enable(this.settings.autoSweepPluginsPeriodic && !this.settings.watchInternalFileChanges ? (PERIODIC_PLUGIN_SWEEP * 1000) : 0);
|
this.periodicPluginSweepProcessor.enable(this.settings.autoSweepPluginsPeriodic && !this.settings.watchInternalFileChanges ? (PERIODIC_PLUGIN_SWEEP * 1000) : 0);
|
||||||
@@ -171,7 +187,7 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
const entries = [] as PluginDataExDisplay[]
|
const entries = [] as PluginDataExDisplay[]
|
||||||
const plugins = this.localDatabase.findEntries(ICXHeader + "", `${ICXHeader}\u{10ffff}`, { include_docs: true });
|
const plugins = this.localDatabase.findEntries(ICXHeader + "", `${ICXHeader}\u{10ffff}`, { include_docs: true });
|
||||||
const semaphore = Semaphore(4);
|
const semaphore = Semaphore(4);
|
||||||
const processes = [] as Promise<void>[];
|
const para = Parallels();
|
||||||
let count = 0;
|
let count = 0;
|
||||||
pluginIsEnumerating.set(true);
|
pluginIsEnumerating.set(true);
|
||||||
let processed = false;
|
let processed = false;
|
||||||
@@ -184,7 +200,8 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
processed = true;
|
processed = true;
|
||||||
const oldEntry = (this.pluginList.find(e => e.documentPath == path));
|
const oldEntry = (this.pluginList.find(e => e.documentPath == path));
|
||||||
if (oldEntry && oldEntry.mtime == plugin.mtime) continue;
|
if (oldEntry && oldEntry.mtime == plugin.mtime) continue;
|
||||||
processes.push((async (v) => {
|
await para.wait(5);
|
||||||
|
para.add((async (v) => {
|
||||||
|
|
||||||
const release = await semaphore.acquire(1);
|
const release = await semaphore.acquire(1);
|
||||||
try {
|
try {
|
||||||
@@ -193,7 +210,7 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
Logger(`plugin-${path}`, LOG_LEVEL.VERBOSE);
|
Logger(`plugin-${path}`, LOG_LEVEL.VERBOSE);
|
||||||
const wx = await this.localDatabase.getDBEntry(path, null, false, false);
|
const wx = await this.localDatabase.getDBEntry(path, null, false, false);
|
||||||
if (wx) {
|
if (wx) {
|
||||||
const data = parseYaml(getDocData(wx.data)) as PluginDataEx;
|
const data = deserialize(getDocData(wx.data), {}) as PluginDataEx;
|
||||||
const xFiles = [] as PluginDataExFile[];
|
const xFiles = [] as PluginDataExFile[];
|
||||||
for (const file of data.files) {
|
for (const file of data.files) {
|
||||||
const work = { ...file };
|
const work = { ...file };
|
||||||
@@ -217,7 +234,7 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
}
|
}
|
||||||
)(plugin));
|
)(plugin));
|
||||||
}
|
}
|
||||||
await Promise.all(processes);
|
await para.all();
|
||||||
let newList = [...this.pluginList];
|
let newList = [...this.pluginList];
|
||||||
for (const item of entries) {
|
for (const item of entries) {
|
||||||
newList = newList.filter(x => x.documentPath != item.documentPath);
|
newList = newList.filter(x => x.documentPath != item.documentPath);
|
||||||
@@ -241,9 +258,9 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
const docB = await this.localDatabase.getDBEntry(dataB.documentPath);
|
const docB = await this.localDatabase.getDBEntry(dataB.documentPath);
|
||||||
|
|
||||||
if (docA && docB) {
|
if (docA && docB) {
|
||||||
const pluginDataA = parseYaml(getDocData(docA.data)) as PluginDataEx;
|
const pluginDataA = deserialize(getDocData(docA.data), {}) as PluginDataEx;
|
||||||
pluginDataA.documentPath = dataA.documentPath;
|
pluginDataA.documentPath = dataA.documentPath;
|
||||||
const pluginDataB = parseYaml(getDocData(docB.data)) as PluginDataEx;
|
const pluginDataB = deserialize(getDocData(docB.data), {}) as PluginDataEx;
|
||||||
pluginDataB.documentPath = dataB.documentPath;
|
pluginDataB.documentPath = dataB.documentPath;
|
||||||
|
|
||||||
// Use outer structure to wrap each data.
|
// Use outer structure to wrap each data.
|
||||||
@@ -282,7 +299,7 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
if (dx == false) {
|
if (dx == false) {
|
||||||
throw "Not found on database"
|
throw "Not found on database"
|
||||||
}
|
}
|
||||||
const loadedData = parseYaml(getDocData(dx.data)) as PluginDataEx;
|
const loadedData = deserialize(getDocData(dx.data), {}) as PluginDataEx;
|
||||||
for (const f of loadedData.files) {
|
for (const f of loadedData.files) {
|
||||||
Logger(`Applying ${f.filename} of ${data.displayName || data.name}..`);
|
Logger(`Applying ${f.filename} of ${data.displayName || data.name}..`);
|
||||||
try {
|
try {
|
||||||
@@ -520,7 +537,7 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const content = stringifyYaml(dt);
|
const content = serialize(dt);
|
||||||
try {
|
try {
|
||||||
const old = await this.localDatabase.getDBEntryMeta(prefixedFileName, null, false);
|
const old = await this.localDatabase.getDBEntryMeta(prefixedFileName, null, false);
|
||||||
let saveData: LoadedEntry;
|
let saveData: LoadedEntry;
|
||||||
@@ -567,6 +584,7 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
|
|
||||||
}
|
}
|
||||||
async watchVaultRawEventsAsync(path: FilePath) {
|
async watchVaultRawEventsAsync(path: FilePath) {
|
||||||
|
if (!this.settings.usePluginSync) return false;
|
||||||
if (!this.isTargetPath(path)) return false;
|
if (!this.isTargetPath(path)) return false;
|
||||||
const stat = await this.app.vault.adapter.stat(path);
|
const stat = await this.app.vault.adapter.stat(path);
|
||||||
// Make sure that target is a file.
|
// Make sure that target is a file.
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
import { Notice, normalizePath, PluginManifest } from "./deps";
|
import { Notice, normalizePath, PluginManifest } from "./deps";
|
||||||
import { EntryDoc, LoadedEntry, LOG_LEVEL, InternalFileEntry, FilePathWithPrefix, FilePath } from "./lib/src/types";
|
import { EntryDoc, LoadedEntry, LOG_LEVEL, InternalFileEntry, FilePathWithPrefix, FilePath } from "./lib/src/types";
|
||||||
import { InternalFileInfo, ICHeader, ICHeaderEnd } from "./types";
|
import { InternalFileInfo, ICHeader, ICHeaderEnd } from "./types";
|
||||||
import { delay, isDocContentSame } from "./lib/src/utils";
|
import { Parallels, delay, isDocContentSame } from "./lib/src/utils";
|
||||||
import { Logger } from "./lib/src/logger";
|
import { Logger } from "./lib/src/logger";
|
||||||
import { PouchDB } from "./lib/src/pouchdb-browser.js";
|
import { PouchDB } from "./lib/src/pouchdb-browser.js";
|
||||||
import { disposeMemoObject, memoIfNotExist, memoObject, retrieveMemoObject, scheduleTask, isInternalMetadata, PeriodicProcessor } from "./utils";
|
import { disposeMemoObject, memoIfNotExist, memoObject, retrieveMemoObject, scheduleTask, isInternalMetadata, PeriodicProcessor } from "./utils";
|
||||||
import { WrappedNotice } from "./lib/src/wrapper";
|
import { WrappedNotice } from "./lib/src/wrapper";
|
||||||
import { base64ToArrayBuffer, arrayBufferToBase64 } from "./lib/src/strbin";
|
import { base64ToArrayBuffer, arrayBufferToBase64 } from "./lib/src/strbin";
|
||||||
import { runWithLock } from "./lib/src/lock";
|
import { runWithLock } from "./lib/src/lock";
|
||||||
import { Semaphore } from "./lib/src/semaphore";
|
|
||||||
import { JsonResolveModal } from "./JsonResolveModal";
|
import { JsonResolveModal } from "./JsonResolveModal";
|
||||||
import { LiveSyncCommands } from "./LiveSyncCommands";
|
import { LiveSyncCommands } from "./LiveSyncCommands";
|
||||||
import { addPrefix, stripAllPrefixes } from "./lib/src/path";
|
import { addPrefix, stripAllPrefixes } from "./lib/src/path";
|
||||||
@@ -254,37 +253,35 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
c = pieces.shift();
|
c = pieces.shift();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const p = [] as Promise<void>[];
|
|
||||||
const semaphore = Semaphore(10);
|
|
||||||
// Cache update time information for files which have already been processed (mainly for files that were skipped due to the same content)
|
// Cache update time information for files which have already been processed (mainly for files that were skipped due to the same content)
|
||||||
let caches: { [key: string]: { storageMtime: number; docMtime: number; }; } = {};
|
let caches: { [key: string]: { storageMtime: number; docMtime: number; }; } = {};
|
||||||
caches = await this.kvDB.get<{ [key: string]: { storageMtime: number; docMtime: number; }; }>("diff-caches-internal") || {};
|
caches = await this.kvDB.get<{ [key: string]: { storageMtime: number; docMtime: number; }; }>("diff-caches-internal") || {};
|
||||||
|
const filesMap = files.reduce((acc, cur) => {
|
||||||
|
acc[cur.path] = cur;
|
||||||
|
return acc;
|
||||||
|
}, {} as { [key: string]: InternalFileInfo; });
|
||||||
|
const filesOnDBMap = filesOnDB.reduce((acc, cur) => {
|
||||||
|
acc[stripAllPrefixes(this.getPath(cur))] = cur;
|
||||||
|
return acc;
|
||||||
|
}, {} as { [key: string]: InternalFileEntry; });
|
||||||
|
const para = Parallels();
|
||||||
for (const filename of allFileNames) {
|
for (const filename of allFileNames) {
|
||||||
if (!filename) continue;
|
|
||||||
processed++;
|
processed++;
|
||||||
if (processed % 100 == 0)
|
if (processed % 100 == 0) {
|
||||||
Logger(`Hidden file: ${processed}/${fileCount}`, logLevel, "sync_internal");
|
Logger(`Hidden file: ${processed}/${fileCount}`, logLevel, "sync_internal");
|
||||||
|
}
|
||||||
|
if (!filename) continue;
|
||||||
if (ignorePatterns.some(e => filename.match(e)))
|
if (ignorePatterns.some(e => filename.match(e)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const fileOnStorage = files.find(e => e.path == filename);
|
const fileOnStorage = filename in filesMap ? filesMap[filename] : undefined;
|
||||||
const fileOnDatabase = filesOnDB.find(e => stripAllPrefixes(this.getPath(e)) == filename);
|
const fileOnDatabase = filename in filesOnDBMap ? filesOnDBMap[filename] : undefined;
|
||||||
const addProc = async (p: () => Promise<void>): Promise<void> => {
|
|
||||||
const releaser = await semaphore.acquire(1);
|
|
||||||
try {
|
|
||||||
return p();
|
|
||||||
} catch (ex) {
|
|
||||||
Logger("Some process failed", logLevel);
|
|
||||||
Logger(ex);
|
|
||||||
} finally {
|
|
||||||
releaser();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const cache = filename in caches ? caches[filename] : { storageMtime: 0, docMtime: 0 };
|
const cache = filename in caches ? caches[filename] : { storageMtime: 0, docMtime: 0 };
|
||||||
|
|
||||||
p.push(addProc(async () => {
|
await para.wait(5);
|
||||||
const xFileOnStorage = fileOnStorage;
|
const proc = (async (xFileOnStorage: InternalFileInfo, xFileOnDatabase: InternalFileEntry) => {
|
||||||
const xFileOnDatabase = fileOnDatabase;
|
|
||||||
if (xFileOnStorage && xFileOnDatabase) {
|
if (xFileOnStorage && xFileOnDatabase) {
|
||||||
// Both => Synchronize
|
// Both => Synchronize
|
||||||
if ((direction != "pullForce" && direction != "pushForce") && xFileOnDatabase.mtime == cache.docMtime && xFileOnStorage.mtime == cache.storageMtime) {
|
if ((direction != "pullForce" && direction != "pushForce") && xFileOnDatabase.mtime == cache.docMtime && xFileOnStorage.mtime == cache.storageMtime) {
|
||||||
@@ -326,9 +323,11 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
throw new Error("Invalid state on hidden file sync");
|
throw new Error("Invalid state on hidden file sync");
|
||||||
// Something corrupted?
|
// Something corrupted?
|
||||||
}
|
}
|
||||||
}));
|
|
||||||
|
});
|
||||||
|
para.add(proc(fileOnStorage, fileOnDatabase))
|
||||||
}
|
}
|
||||||
await Promise.all(p);
|
await para.all();
|
||||||
await this.kvDB.set("diff-caches-internal", caches);
|
await this.kvDB.set("diff-caches-internal", caches);
|
||||||
|
|
||||||
// When files has been retrieved from the database. they must be reloaded.
|
// When files has been retrieved from the database. they must be reloaded.
|
||||||
@@ -495,7 +494,7 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
const mtime = new Date().getTime();
|
const mtime = new Date().getTime();
|
||||||
await runWithLock("file-" + prefixedFileName, false, async () => {
|
await runWithLock("file-" + prefixedFileName, false, async () => {
|
||||||
try {
|
try {
|
||||||
const old = await this.localDatabase.getDBEntry(prefixedFileName, null, false, false) as InternalFileEntry | false;
|
const old = await this.localDatabase.getDBEntryMeta(prefixedFileName, null, true) as InternalFileEntry | false;
|
||||||
let saveData: InternalFileEntry;
|
let saveData: InternalFileEntry;
|
||||||
if (old === false) {
|
if (old === false) {
|
||||||
saveData = {
|
saveData = {
|
||||||
@@ -541,7 +540,7 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
try {
|
try {
|
||||||
// Check conflicted status
|
// Check conflicted status
|
||||||
//TODO option
|
//TODO option
|
||||||
const fileOnDB = await this.localDatabase.getDBEntry(prefixedFileName, { conflicts: true }, false, false);
|
const fileOnDB = await this.localDatabase.getDBEntry(prefixedFileName, { conflicts: true }, false, true);
|
||||||
if (fileOnDB === false)
|
if (fileOnDB === false)
|
||||||
throw new Error(`File not found on database.:${filename}`);
|
throw new Error(`File not found on database.:${filename}`);
|
||||||
// Prevent overwrite for Prevent overwriting while some conflicted revision exists.
|
// Prevent overwrite for Prevent overwriting while some conflicted revision exists.
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
async testConnection(): Promise<void> {
|
async testConnection(): Promise<void> {
|
||||||
const db = await this.plugin.replicator.connectRemoteCouchDBWithSetting(this.plugin.settings, this.plugin.isMobile);
|
const db = await this.plugin.replicator.connectRemoteCouchDBWithSetting(this.plugin.settings, this.plugin.isMobile, true);
|
||||||
if (typeof db === "string") {
|
if (typeof db === "string") {
|
||||||
this.plugin.addLog(`could not connect to ${this.plugin.settings.couchDB_URI} : ${this.plugin.settings.couchDB_DBNAME} \n(${db})`, LOG_LEVEL.NOTICE);
|
this.plugin.addLog(`could not connect to ${this.plugin.settings.couchDB_URI} : ${this.plugin.settings.couchDB_DBNAME} \n(${db})`, LOG_LEVEL.NOTICE);
|
||||||
return;
|
return;
|
||||||
@@ -376,7 +376,7 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
useDynamicIterationCount: useDynamicIterationCount,
|
useDynamicIterationCount: useDynamicIterationCount,
|
||||||
};
|
};
|
||||||
console.dir(settingForCheck);
|
console.dir(settingForCheck);
|
||||||
const db = await this.plugin.replicator.connectRemoteCouchDBWithSetting(settingForCheck, this.plugin.isMobile);
|
const db = await this.plugin.replicator.connectRemoteCouchDBWithSetting(settingForCheck, this.plugin.isMobile, true);
|
||||||
if (typeof db === "string") {
|
if (typeof db === "string") {
|
||||||
Logger("Could not connect to the database.", LOG_LEVEL.NOTICE);
|
Logger("Could not connect to the database.", LOG_LEVEL.NOTICE);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
2
src/lib
2
src/lib
Submodule src/lib updated: 051b50ca38...ec4ecacb43
69
src/main.ts
69
src/main.ts
@@ -4,7 +4,7 @@ import { Diff, DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, diff_match_patch } from "di
|
|||||||
import { debounce, Notice, Plugin, TFile, addIcon, TFolder, normalizePath, TAbstractFile, Editor, MarkdownView, RequestUrlParam, RequestUrlResponse, requestUrl } from "./deps";
|
import { debounce, Notice, Plugin, TFile, addIcon, TFolder, normalizePath, TAbstractFile, Editor, MarkdownView, RequestUrlParam, RequestUrlResponse, requestUrl } from "./deps";
|
||||||
import { EntryDoc, LoadedEntry, ObsidianLiveSyncSettings, diff_check_result, diff_result_leaf, EntryBody, LOG_LEVEL, VER, DEFAULT_SETTINGS, diff_result, FLAGMD_REDFLAG, SYNCINFO_ID, SALT_OF_PASSPHRASE, ConfigPassphraseStore, CouchDBConnection, FLAGMD_REDFLAG2, FLAGMD_REDFLAG3, PREFIXMD_LOGFILE, DatabaseConnectingStatus, EntryHasPath, DocumentID, FilePathWithPrefix, FilePath, AnyEntry } from "./lib/src/types";
|
import { EntryDoc, LoadedEntry, ObsidianLiveSyncSettings, diff_check_result, diff_result_leaf, EntryBody, LOG_LEVEL, VER, DEFAULT_SETTINGS, diff_result, FLAGMD_REDFLAG, SYNCINFO_ID, SALT_OF_PASSPHRASE, ConfigPassphraseStore, CouchDBConnection, FLAGMD_REDFLAG2, FLAGMD_REDFLAG3, PREFIXMD_LOGFILE, DatabaseConnectingStatus, EntryHasPath, DocumentID, FilePathWithPrefix, FilePath, AnyEntry } from "./lib/src/types";
|
||||||
import { InternalFileInfo, queueItem, CacheData, FileEventItem, FileWatchEventQueueMax } from "./types";
|
import { InternalFileInfo, queueItem, CacheData, FileEventItem, FileWatchEventQueueMax } from "./types";
|
||||||
import { getDocData, isDocContentSame } from "./lib/src/utils";
|
import { getDocData, isDocContentSame, Parallels } from "./lib/src/utils";
|
||||||
import { Logger } from "./lib/src/logger";
|
import { Logger } from "./lib/src/logger";
|
||||||
import { PouchDB } from "./lib/src/pouchdb-browser.js";
|
import { PouchDB } from "./lib/src/pouchdb-browser.js";
|
||||||
import { LogDisplayModal } from "./LogDisplayModal";
|
import { LogDisplayModal } from "./LogDisplayModal";
|
||||||
@@ -87,7 +87,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
processReplication = (e: PouchDB.Core.ExistingDocument<EntryDoc>[]) => this.parseReplicationResult(e);
|
processReplication = (e: PouchDB.Core.ExistingDocument<EntryDoc>[]) => this.parseReplicationResult(e);
|
||||||
async connectRemoteCouchDB(uri: string, auth: { username: string; password: string }, disableRequestURI: boolean, passphrase: string | false, useDynamicIterationCount: boolean): Promise<string | { db: PouchDB.Database<EntryDoc>; info: PouchDB.Core.DatabaseInfo }> {
|
async connectRemoteCouchDB(uri: string, auth: { username: string; password: string }, disableRequestURI: boolean, passphrase: string | false, useDynamicIterationCount: boolean, performSetup: boolean, skipInfo: boolean): Promise<string | { db: PouchDB.Database<EntryDoc>; info: PouchDB.Core.DatabaseInfo }> {
|
||||||
if (!isValidRemoteCouchDBURI(uri)) return "Remote URI is not valid";
|
if (!isValidRemoteCouchDBURI(uri)) return "Remote URI is not valid";
|
||||||
if (uri.toLowerCase() != uri) return "Remote URI and database name could not contain capital letters.";
|
if (uri.toLowerCase() != uri) return "Remote URI and database name could not contain capital letters.";
|
||||||
if (uri.indexOf(" ") !== -1) return "Remote URI and database name could not contain spaces.";
|
if (uri.indexOf(" ") !== -1) return "Remote URI and database name could not contain spaces.";
|
||||||
@@ -104,6 +104,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin
|
|||||||
const conf: PouchDB.HttpAdapter.HttpAdapterConfiguration = {
|
const conf: PouchDB.HttpAdapter.HttpAdapterConfiguration = {
|
||||||
adapter: "http",
|
adapter: "http",
|
||||||
auth,
|
auth,
|
||||||
|
skip_setup: !performSetup,
|
||||||
fetch: async (url: string | Request, opts: RequestInit) => {
|
fetch: async (url: string | Request, opts: RequestInit) => {
|
||||||
let size = "";
|
let size = "";
|
||||||
const localURL = url.toString().substring(uri.length);
|
const localURL = url.toString().substring(uri.length);
|
||||||
@@ -192,6 +193,9 @@ export default class ObsidianLiveSyncPlugin extends Plugin
|
|||||||
if (passphrase !== "false" && typeof passphrase === "string") {
|
if (passphrase !== "false" && typeof passphrase === "string") {
|
||||||
enableEncryption(db, passphrase, useDynamicIterationCount);
|
enableEncryption(db, passphrase, useDynamicIterationCount);
|
||||||
}
|
}
|
||||||
|
if (skipInfo) {
|
||||||
|
return { db: db, info: {} };
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const info = await db.info();
|
const info = await db.info();
|
||||||
return { db: db, info: info };
|
return { db: db, info: info };
|
||||||
@@ -1364,8 +1368,8 @@ export default class ObsidianLiveSyncPlugin extends Plugin
|
|||||||
// If `Read chunks online` is disabled, chunks should be transferred before here.
|
// If `Read chunks online` is disabled, chunks should be transferred before here.
|
||||||
// However, in some cases, chunks are after that. So, if missing chunks exist, we have to wait for them.
|
// However, in some cases, chunks are after that. So, if missing chunks exist, we have to wait for them.
|
||||||
if ((!this.settings.readChunksOnline) && "children" in doc) {
|
if ((!this.settings.readChunksOnline) && "children" in doc) {
|
||||||
const c = await this.localDatabase.collectChunksWithCache(doc.children)
|
const c = await this.localDatabase.collectChunksWithCache(doc.children);
|
||||||
const missing = c.filter((e) => !e.chunk).map((e) => e.id);
|
const missing = c.filter((e) => e.chunk === false).map((e) => e.id);
|
||||||
if (missing.length > 0) Logger(`${path} (${doc._id}, ${doc._rev}) Queued (waiting ${missing.length} items)`, LOG_LEVEL.VERBOSE);
|
if (missing.length > 0) Logger(`${path} (${doc._id}, ${doc._rev}) Queued (waiting ${missing.length} items)`, LOG_LEVEL.VERBOSE);
|
||||||
newQueue.missingChildren = missing;
|
newQueue.missingChildren = missing;
|
||||||
this.queuedFiles.push(newQueue);
|
this.queuedFiles.push(newQueue);
|
||||||
@@ -1381,15 +1385,15 @@ export default class ObsidianLiveSyncPlugin extends Plugin
|
|||||||
const docsSorted = docs.sort((a, b) => b.mtime - a.mtime);
|
const docsSorted = docs.sort((a, b) => b.mtime - a.mtime);
|
||||||
L1:
|
L1:
|
||||||
for (const change of docsSorted) {
|
for (const change of docsSorted) {
|
||||||
|
if (isChunk(change._id)) {
|
||||||
|
await this.parseIncomingChunk(change);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
for (const proc of this.addOns) {
|
for (const proc of this.addOns) {
|
||||||
if (await proc.parseReplicationResultItem(change)) {
|
if (await proc.parseReplicationResultItem(change)) {
|
||||||
continue L1;
|
continue L1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isChunk(change._id)) {
|
|
||||||
await this.parseIncomingChunk(change);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (change._id == SYNCINFO_ID) {
|
if (change._id == SYNCINFO_ID) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -1488,19 +1492,20 @@ export default class ObsidianLiveSyncPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
return proc.substring(0, p);
|
return proc.substring(0, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
const pendingTask = e.pending.length
|
const pendingTask = e.pending.length
|
||||||
? "\nPending: " +
|
? e.pending.length < 10 ? ("\nPending: " +
|
||||||
Object.entries(e.pending.reduce((p, c) => ({ ...p, [getProcKind(c)]: (p[getProcKind(c)] ?? 0) + 1 }), {} as { [key: string]: number }))
|
Object.entries(e.pending.reduce((p, c) => ({ ...p, [getProcKind(c)]: (p[getProcKind(c)] ?? 0) + 1 }), {} as { [key: string]: number }))
|
||||||
.map((e) => `${e[0]}${e[1] == 1 ? "" : `(${e[1]})`}`)
|
.map((e) => `${e[0]}${e[1] == 1 ? "" : `(${e[1]})`}`)
|
||||||
.join(", ")
|
.join(", ")
|
||||||
: "";
|
) : `\n Pending: ${e.pending.length}` : "";
|
||||||
|
|
||||||
const runningTask = e.running.length
|
const runningTask = e.running.length
|
||||||
? "\nRunning: " +
|
? e.running.length < 10 ? ("\nRunning: " +
|
||||||
Object.entries(e.running.reduce((p, c) => ({ ...p, [getProcKind(c)]: (p[getProcKind(c)] ?? 0) + 1 }), {} as { [key: string]: number }))
|
Object.entries(e.running.reduce((p, c) => ({ ...p, [getProcKind(c)]: (p[getProcKind(c)] ?? 0) + 1 }), {} as { [key: string]: number }))
|
||||||
.map((e) => `${e[0]}${e[1] == 1 ? "" : `(${e[1]})`}`)
|
.map((e) => `${e[0]}${e[1] == 1 ? "" : `(${e[1]})`}`)
|
||||||
.join(", ")
|
.join(", ")
|
||||||
: "";
|
) : `\n Running: ${e.running.length}` : "";
|
||||||
this.setStatusBarText(message + pendingTask + runningTask);
|
this.setStatusBarText(message + pendingTask + runningTask);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -1663,25 +1668,23 @@ Or if you are sure know what had been happened, we can unlock the database from
|
|||||||
|
|
||||||
const runAll = async<T>(procedureName: string, objects: T[], callback: (arg: T) => Promise<void>) => {
|
const runAll = async<T>(procedureName: string, objects: T[], callback: (arg: T) => Promise<void>) => {
|
||||||
Logger(procedureName);
|
Logger(procedureName);
|
||||||
const semaphore = Semaphore(25);
|
|
||||||
if (!this.localDatabase.isReady) throw Error("Database is not ready!");
|
if (!this.localDatabase.isReady) throw Error("Database is not ready!");
|
||||||
const processes = objects.map(e => (async (v) => {
|
const para = Parallels();
|
||||||
const releaser = await semaphore.acquire(1, procedureName);
|
for (const v of objects) {
|
||||||
|
await para.wait(10);
|
||||||
|
para.add((async (v) => {
|
||||||
|
try {
|
||||||
|
await callback(v);
|
||||||
|
} catch (ex) {
|
||||||
|
Logger(`Error while ${procedureName}`, LOG_LEVEL.NOTICE);
|
||||||
|
Logger(ex);
|
||||||
|
}
|
||||||
|
})(v));
|
||||||
|
|
||||||
try {
|
|
||||||
await callback(v);
|
|
||||||
} catch (ex) {
|
|
||||||
Logger(`Error while ${procedureName}`, LOG_LEVEL.NOTICE);
|
|
||||||
Logger(ex);
|
|
||||||
} finally {
|
|
||||||
releaser();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)(e));
|
await para.all();
|
||||||
await Promise.all(processes);
|
|
||||||
|
|
||||||
Logger(`${procedureName} done.`);
|
Logger(`${procedureName} done.`);
|
||||||
};
|
}
|
||||||
|
|
||||||
await runAll("UPDATE DATABASE", onlyInStorage, async (e) => {
|
await runAll("UPDATE DATABASE", onlyInStorage, async (e) => {
|
||||||
Logger(`UPDATE DATABASE ${e.path}`);
|
Logger(`UPDATE DATABASE ${e.path}`);
|
||||||
|
|||||||
14
updates.md
14
updates.md
@@ -27,5 +27,19 @@ I hope you will give it a try.
|
|||||||
- 0.19.3
|
- 0.19.3
|
||||||
- Improved:
|
- Improved:
|
||||||
- Now replication will be paced by collecting chunks. If synchronisation has been deadlocked, please enable `Do not pace synchronization` once.
|
- Now replication will be paced by collecting chunks. If synchronisation has been deadlocked, please enable `Do not pace synchronization` once.
|
||||||
|
- 0.19.4
|
||||||
|
- Improved:
|
||||||
|
- Reduced remote database checking to improve speed and reduce bandwidth.
|
||||||
|
- Fixed:
|
||||||
|
- Chunks which previously misinterpreted are now interpreted correctly.
|
||||||
|
- No more missing chunks which not be found forever, except if it has been actually missing.
|
||||||
|
- Deleted file detection on hidden file synchronising now works fine.
|
||||||
|
- Now the Customisation sync is surely quiet while it has been disabled.
|
||||||
|
- 0.19.5
|
||||||
|
- Fixed:
|
||||||
|
- Now hidden file synchronisation would not be hanged, even if so many files exist.
|
||||||
|
- Improved:
|
||||||
|
- Customisation sync works more smoothly.
|
||||||
|
- Note: Concurrent processing has been rollbacked into the original implementation. As a result, the total number of processes is no longer shown next to the hourglass icon. However, only the processes that are running concurrently are shown.
|
||||||
|
|
||||||
... To continue on to `updates_old.md`.
|
... To continue on to `updates_old.md`.
|
||||||
|
|||||||
Reference in New Issue
Block a user