mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2025-12-15 18:55:57 +00:00
New feature:
- Use dynamic iteration count Fixed: - Read chunks online will fetch the remote chunks correctly. - Read chunks online will save fetched chunks to the local database.
This commit is contained in:
@@ -52,7 +52,7 @@ export class LocalPouchDB extends LocalPouchDBBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async connectRemoteCouchDB(uri: string, auth: { username: string; password: string }, disableRequestURI: boolean, passphrase: string | boolean): Promise<string | { db: PouchDB.Database<EntryDoc>; info: PouchDB.Core.DatabaseInfo }> {
|
async connectRemoteCouchDB(uri: string, auth: { username: string; password: string }, disableRequestURI: boolean, passphrase: string | boolean, useDynamicIterationCount: 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.";
|
||||||
@@ -155,7 +155,7 @@ export class LocalPouchDB extends LocalPouchDBBase {
|
|||||||
|
|
||||||
const db: PouchDB.Database<EntryDoc> = new PouchDB<EntryDoc>(uri, conf);
|
const db: PouchDB.Database<EntryDoc> = new PouchDB<EntryDoc>(uri, conf);
|
||||||
if (passphrase && typeof passphrase === "string") {
|
if (passphrase && typeof passphrase === "string") {
|
||||||
enableEncryption(db, passphrase);
|
enableEncryption(db, passphrase, useDynamicIterationCount);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const info = await db.info();
|
const info = await db.info();
|
||||||
|
|||||||
@@ -297,10 +297,12 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
if (inWizard) {
|
if (inWizard) {
|
||||||
this.plugin.settings.encrypt = value;
|
this.plugin.settings.encrypt = value;
|
||||||
passphrase.setDisabled(!value);
|
passphrase.setDisabled(!value);
|
||||||
|
dynamicIteration.setDisabled(!value);
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
} else {
|
} else {
|
||||||
this.plugin.settings.workingEncrypt = value;
|
this.plugin.settings.workingEncrypt = value;
|
||||||
passphrase.setDisabled(!value);
|
passphrase.setDisabled(!value);
|
||||||
|
dynamicIteration.setDisabled(!value);
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -325,11 +327,30 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
});
|
});
|
||||||
passphrase.setDisabled(!this.plugin.settings.workingEncrypt);
|
passphrase.setDisabled(!this.plugin.settings.workingEncrypt);
|
||||||
|
|
||||||
|
const dynamicIteration = new Setting(containerRemoteDatabaseEl)
|
||||||
|
.setName("Use dynamic iteration count (experimental)")
|
||||||
|
.setDesc("Balancing the encryption/decryption load against the length of the passphrase if toggled. (v0.17.5 or higher required)")
|
||||||
|
.addToggle((toggle) => {
|
||||||
|
toggle.setValue(this.plugin.settings.workingUseDynamicIterationCount)
|
||||||
|
.onChange(async (value) => {
|
||||||
|
if (inWizard) {
|
||||||
|
this.plugin.settings.useDynamicIterationCount = value;
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
} else {
|
||||||
|
this.plugin.settings.workingUseDynamicIterationCount = value;
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.setClass("wizardHidden");
|
||||||
|
dynamicIteration.setDisabled(!this.plugin.settings.workingEncrypt);
|
||||||
|
|
||||||
const checkWorkingPassphrase = async (): Promise<boolean> => {
|
const checkWorkingPassphrase = async (): Promise<boolean> => {
|
||||||
const settingForCheck: RemoteDBSettings = {
|
const settingForCheck: RemoteDBSettings = {
|
||||||
...this.plugin.settings,
|
...this.plugin.settings,
|
||||||
encrypt: this.plugin.settings.workingEncrypt,
|
encrypt: this.plugin.settings.workingEncrypt,
|
||||||
passphrase: this.plugin.settings.workingPassphrase,
|
passphrase: this.plugin.settings.workingPassphrase,
|
||||||
|
useDynamicIterationCount: this.plugin.settings.workingUseDynamicIterationCount,
|
||||||
};
|
};
|
||||||
console.dir(settingForCheck);
|
console.dir(settingForCheck);
|
||||||
const db = await this.plugin.localDatabase.connectRemoteCouchDBWithSetting(settingForCheck, this.plugin.localDatabase.isMobile);
|
const db = await this.plugin.localDatabase.connectRemoteCouchDBWithSetting(settingForCheck, this.plugin.localDatabase.isMobile);
|
||||||
@@ -355,7 +376,7 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
Logger("WARNING! Your device would not support encryption.", LOG_LEVEL.NOTICE);
|
Logger("WARNING! Your device would not support encryption.", LOG_LEVEL.NOTICE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!(await checkWorkingPassphrase())) {
|
if (!(await checkWorkingPassphrase()) && !sendToServer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!this.plugin.settings.workingEncrypt) {
|
if (!this.plugin.settings.workingEncrypt) {
|
||||||
@@ -368,6 +389,7 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
this.plugin.settings.syncOnFileOpen = false;
|
this.plugin.settings.syncOnFileOpen = false;
|
||||||
this.plugin.settings.encrypt = this.plugin.settings.workingEncrypt;
|
this.plugin.settings.encrypt = this.plugin.settings.workingEncrypt;
|
||||||
this.plugin.settings.passphrase = this.plugin.settings.workingPassphrase;
|
this.plugin.settings.passphrase = this.plugin.settings.workingPassphrase;
|
||||||
|
this.plugin.settings.useDynamicIterationCount = this.plugin.settings.workingUseDynamicIterationCount;
|
||||||
|
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
if (sendToServer) {
|
if (sendToServer) {
|
||||||
|
|||||||
2
src/lib
2
src/lib
Submodule src/lib updated: af6bbef6fa...9fe5ce421f
@@ -418,7 +418,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
delete setting[k];
|
delete setting[k];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const encryptedSetting = encodeURIComponent(await encrypt(JSON.stringify(setting), encryptingPassphrase));
|
const encryptedSetting = encodeURIComponent(await encrypt(JSON.stringify(setting), encryptingPassphrase, false));
|
||||||
const uri = `${configURIBase}${encryptedSetting}`;
|
const uri = `${configURIBase}${encryptedSetting}`;
|
||||||
await navigator.clipboard.writeText(uri);
|
await navigator.clipboard.writeText(uri);
|
||||||
Logger("Setup URI copied to clipboard", LOG_LEVEL.NOTICE);
|
Logger("Setup URI copied to clipboard", LOG_LEVEL.NOTICE);
|
||||||
@@ -431,7 +431,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
const encryptingPassphrase = await askString(this.app, "Encrypt your settings", "Passphrase", "");
|
const encryptingPassphrase = await askString(this.app, "Encrypt your settings", "Passphrase", "");
|
||||||
if (encryptingPassphrase === false) return;
|
if (encryptingPassphrase === false) return;
|
||||||
const setting = { ...this.settings };
|
const setting = { ...this.settings };
|
||||||
const encryptedSetting = encodeURIComponent(await encrypt(JSON.stringify(setting), encryptingPassphrase));
|
const encryptedSetting = encodeURIComponent(await encrypt(JSON.stringify(setting), encryptingPassphrase, false));
|
||||||
const uri = `${configURIBase}${encryptedSetting}`;
|
const uri = `${configURIBase}${encryptedSetting}`;
|
||||||
await navigator.clipboard.writeText(uri);
|
await navigator.clipboard.writeText(uri);
|
||||||
Logger("Setup URI copied to clipboard", LOG_LEVEL.NOTICE);
|
Logger("Setup URI copied to clipboard", LOG_LEVEL.NOTICE);
|
||||||
@@ -457,7 +457,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
const oldConf = JSON.parse(JSON.stringify(this.settings));
|
const oldConf = JSON.parse(JSON.stringify(this.settings));
|
||||||
const encryptingPassphrase = await askString(this.app, "Passphrase", "Passphrase for your settings", "");
|
const encryptingPassphrase = await askString(this.app, "Passphrase", "Passphrase for your settings", "");
|
||||||
if (encryptingPassphrase === false) return;
|
if (encryptingPassphrase === false) return;
|
||||||
const newConf = await JSON.parse(await decrypt(confString, encryptingPassphrase));
|
const newConf = await JSON.parse(await decrypt(confString, encryptingPassphrase, false));
|
||||||
if (newConf) {
|
if (newConf) {
|
||||||
const result = await askYesNo(this.app, "Importing LiveSync's conf, OK?");
|
const result = await askYesNo(this.app, "Importing LiveSync's conf, OK?");
|
||||||
if (result == "yes") {
|
if (result == "yes") {
|
||||||
|
|||||||
Reference in New Issue
Block a user