mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-09-21 18:17:05 +00:00
Migrate LiveSync flows to provider-owned resources
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import type { SynchronisationInformationResourceFactory } from "@vrtmrz/livesync-commonlib/replication";
|
||||
import {
|
||||
LiveSyncCouchDBReplicator,
|
||||
type LiveSyncCouchDBReplicatorEnv,
|
||||
} from "@vrtmrz/livesync-commonlib/compat/replication/couchdb/LiveSyncReplicator";
|
||||
import { checkSyncInfo } from "@vrtmrz/livesync-commonlib/compat/pouchdb/negotiation";
|
||||
import { createReplicatorDisposer, snapshotRemoteSettings } from "./shared";
|
||||
|
||||
/** Build an owned CouchDB synchronisation-information verifier for one host. */
|
||||
export function createCouchDBSynchronisationInformationResourceFactory(
|
||||
host: LiveSyncCouchDBReplicatorEnv
|
||||
): SynchronisationInformationResourceFactory {
|
||||
return (setting) => {
|
||||
const snapshot = snapshotRemoteSettings(setting);
|
||||
const replicator = new LiveSyncCouchDBReplicator(host);
|
||||
return Promise.resolve({
|
||||
check: async () => {
|
||||
const connection = await replicator.connectRemoteCouchDBWithSetting(
|
||||
snapshot,
|
||||
replicator.isMobile(),
|
||||
true
|
||||
);
|
||||
if (typeof connection === "string") {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
return await checkSyncInfo(connection.db);
|
||||
} finally {
|
||||
await connection.close();
|
||||
}
|
||||
},
|
||||
dispose: createReplicatorDisposer(replicator),
|
||||
});
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user