mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-04-29 12:28:35 +00:00
Fixed: No longer credentials are broken during object storage configuration (related: #852).
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -32,6 +32,7 @@ import SetupRemote from "../SetupWizard/dialogs/SetupRemote.svelte";
|
||||
import SetupRemoteCouchDB from "../SetupWizard/dialogs/SetupRemoteCouchDB.svelte";
|
||||
import SetupRemoteBucket from "../SetupWizard/dialogs/SetupRemoteBucket.svelte";
|
||||
import SetupRemoteP2P from "../SetupWizard/dialogs/SetupRemoteP2P.svelte";
|
||||
import { syncActivatedRemoteSettings } from "./remoteConfigBuffer.ts";
|
||||
|
||||
function getSettingsFromEditingSettings(editingSettings: AllSettings): ObsidianLiveSyncSettings {
|
||||
const workObj = { ...editingSettings } as ObsidianLiveSyncSettings;
|
||||
@@ -183,6 +184,11 @@ export function paneRemoteConfig(
|
||||
}, true);
|
||||
|
||||
if (synchroniseActiveRemote) {
|
||||
// Keep both buffers aligned with the newly activated remote before saving any remaining dirty keys.
|
||||
syncActivatedRemoteSettings(this.editingSettings, this.core.settings);
|
||||
if (this.initialSettings) {
|
||||
syncActivatedRemoteSettings(this.initialSettings, this.core.settings);
|
||||
}
|
||||
await this.saveAllDirtySettings();
|
||||
}
|
||||
|
||||
|
||||
17
src/modules/features/SettingDialogue/remoteConfigBuffer.ts
Normal file
17
src/modules/features/SettingDialogue/remoteConfigBuffer.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { pickBucketSyncSettings, pickCouchDBSyncSettings, pickP2PSyncSettings } from "@lib/common/utils.ts";
|
||||
import type { ObsidianLiveSyncSettings } from "@lib/common/types.ts";
|
||||
|
||||
// Keep the setting dialogue buffer aligned with the current core settings before persisting other dirty keys.
|
||||
// This also clears stale dirty values left from editing a different remote type before switching active remotes.
|
||||
export function syncActivatedRemoteSettings(
|
||||
target: Partial<ObsidianLiveSyncSettings>,
|
||||
source: ObsidianLiveSyncSettings
|
||||
): void {
|
||||
Object.assign(target, {
|
||||
remoteType: source.remoteType,
|
||||
activeConfigurationId: source.activeConfigurationId,
|
||||
...pickBucketSyncSettings(source),
|
||||
...pickCouchDBSyncSettings(source),
|
||||
...pickP2PSyncSettings(source),
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { DEFAULT_SETTINGS, REMOTE_COUCHDB, REMOTE_MINIO } from "../../../lib/src/common/types";
|
||||
import { syncActivatedRemoteSettings } from "./remoteConfigBuffer";
|
||||
|
||||
describe("syncActivatedRemoteSettings", () => {
|
||||
it("should copy active MinIO credentials into the editing buffer", () => {
|
||||
const target = {
|
||||
...DEFAULT_SETTINGS,
|
||||
remoteType: REMOTE_COUCHDB,
|
||||
activeConfigurationId: "old-remote",
|
||||
accessKey: "",
|
||||
secretKey: "",
|
||||
endpoint: "",
|
||||
bucket: "",
|
||||
region: "",
|
||||
encrypt: true,
|
||||
};
|
||||
const source = {
|
||||
...DEFAULT_SETTINGS,
|
||||
remoteType: REMOTE_MINIO,
|
||||
activeConfigurationId: "remote-s3",
|
||||
accessKey: "access",
|
||||
secretKey: "secret",
|
||||
endpoint: "https://minio.example.test",
|
||||
bucket: "vault",
|
||||
region: "sz-hq",
|
||||
bucketPrefix: "folder/",
|
||||
useCustomRequestHandler: false,
|
||||
forcePathStyle: true,
|
||||
bucketCustomHeaders: "",
|
||||
};
|
||||
|
||||
syncActivatedRemoteSettings(target, source);
|
||||
|
||||
expect(target.remoteType).toBe(REMOTE_MINIO);
|
||||
expect(target.activeConfigurationId).toBe("remote-s3");
|
||||
expect(target.accessKey).toBe("access");
|
||||
expect(target.secretKey).toBe("secret");
|
||||
expect(target.endpoint).toBe("https://minio.example.test");
|
||||
expect(target.bucket).toBe("vault");
|
||||
expect(target.region).toBe("sz-hq");
|
||||
expect(target.bucketPrefix).toBe("folder/");
|
||||
expect(target.encrypt).toBe(true);
|
||||
});
|
||||
|
||||
it("should clear stale dirty values from a different remote type", () => {
|
||||
const target = {
|
||||
...DEFAULT_SETTINGS,
|
||||
remoteType: REMOTE_MINIO,
|
||||
activeConfigurationId: "remote-s3",
|
||||
accessKey: "access",
|
||||
secretKey: "secret",
|
||||
endpoint: "https://minio.example.test",
|
||||
bucket: "vault",
|
||||
region: "sz-hq",
|
||||
couchDB_URI: "https://edited.invalid",
|
||||
couchDB_USER: "edited-user",
|
||||
couchDB_PASSWORD: "edited-pass",
|
||||
couchDB_DBNAME: "edited-db",
|
||||
};
|
||||
const source = {
|
||||
...DEFAULT_SETTINGS,
|
||||
remoteType: REMOTE_MINIO,
|
||||
activeConfigurationId: "remote-s3",
|
||||
accessKey: "access",
|
||||
secretKey: "secret",
|
||||
endpoint: "https://minio.example.test",
|
||||
bucket: "vault",
|
||||
region: "sz-hq",
|
||||
couchDB_URI: "https://current.example.test",
|
||||
couchDB_USER: "current-user",
|
||||
couchDB_PASSWORD: "current-pass",
|
||||
couchDB_DBNAME: "current-db",
|
||||
};
|
||||
|
||||
syncActivatedRemoteSettings(target, source);
|
||||
|
||||
expect(target.couchDB_URI).toBe("https://current.example.test");
|
||||
expect(target.couchDB_USER).toBe("current-user");
|
||||
expect(target.couchDB_PASSWORD).toBe("current-pass");
|
||||
expect(target.couchDB_DBNAME).toBe("current-db");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user