mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2024-12-12 09:04:06 +02: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:
parent
81caad8602
commit
b0f612b61c
@ -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 (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.";
|
||||
@ -155,7 +155,7 @@ export class LocalPouchDB extends LocalPouchDBBase {
|
||||
|
||||
const db: PouchDB.Database<EntryDoc> = new PouchDB<EntryDoc>(uri, conf);
|
||||
if (passphrase && typeof passphrase === "string") {
|
||||
enableEncryption(db, passphrase);
|
||||
enableEncryption(db, passphrase, useDynamicIterationCount);
|
||||
}
|
||||
try {
|
||||
const info = await db.info();
|
||||
|
@ -297,10 +297,12 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
||||
if (inWizard) {
|
||||
this.plugin.settings.encrypt = value;
|
||||
passphrase.setDisabled(!value);
|
||||
dynamicIteration.setDisabled(!value);
|
||||
await this.plugin.saveSettings();
|
||||
} else {
|
||||
this.plugin.settings.workingEncrypt = value;
|
||||
passphrase.setDisabled(!value);
|
||||
dynamicIteration.setDisabled(!value);
|
||||
await this.plugin.saveSettings();
|
||||
}
|
||||
})
|
||||
@ -325,11 +327,30 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
||||
});
|
||||
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 settingForCheck: RemoteDBSettings = {
|
||||
...this.plugin.settings,
|
||||
encrypt: this.plugin.settings.workingEncrypt,
|
||||
passphrase: this.plugin.settings.workingPassphrase,
|
||||
useDynamicIterationCount: this.plugin.settings.workingUseDynamicIterationCount,
|
||||
};
|
||||
console.dir(settingForCheck);
|
||||
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);
|
||||
return;
|
||||
}
|
||||
if (!(await checkWorkingPassphrase())) {
|
||||
if (!(await checkWorkingPassphrase()) && !sendToServer) {
|
||||
return;
|
||||
}
|
||||
if (!this.plugin.settings.workingEncrypt) {
|
||||
@ -368,6 +389,7 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
||||
this.plugin.settings.syncOnFileOpen = false;
|
||||
this.plugin.settings.encrypt = this.plugin.settings.workingEncrypt;
|
||||
this.plugin.settings.passphrase = this.plugin.settings.workingPassphrase;
|
||||
this.plugin.settings.useDynamicIterationCount = this.plugin.settings.workingUseDynamicIterationCount;
|
||||
|
||||
await this.plugin.saveSettings();
|
||||
if (sendToServer) {
|
||||
|
2
src/lib
2
src/lib
@ -1 +1 @@
|
||||
Subproject commit af6bbef6fa8cc5832f755260e1d16f019a09d496
|
||||
Subproject commit 9fe5ce421f48064368230e724bc8d8bfb270b44f
|
@ -418,7 +418,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
||||
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}`;
|
||||
await navigator.clipboard.writeText(uri);
|
||||
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", "");
|
||||
if (encryptingPassphrase === false) return;
|
||||
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}`;
|
||||
await navigator.clipboard.writeText(uri);
|
||||
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 encryptingPassphrase = await askString(this.app, "Passphrase", "Passphrase for your settings", "");
|
||||
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) {
|
||||
const result = await askYesNo(this.app, "Importing LiveSync's conf, OK?");
|
||||
if (result == "yes") {
|
||||
|
Loading…
Reference in New Issue
Block a user