more accurate stages of sync
This commit is contained in:
parent
659deb9830
commit
bcca2b4446
89
src/main.ts
89
src/main.ts
@ -64,50 +64,63 @@ export default class SaveRemotePlugin extends Plugin {
|
|||||||
|
|
||||||
this.addRibbonIcon("switch", "Save Remote", async () => {
|
this.addRibbonIcon("switch", "Save Remote", async () => {
|
||||||
if (this.syncStatus !== "idle") {
|
if (this.syncStatus !== "idle") {
|
||||||
new Notice("Save Remote already running!");
|
new Notice(`Save Remote already running in stage ${this.syncStatus}!`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
new Notice("Save Remote Sync Preparing");
|
try {
|
||||||
this.syncStatus = "preparing";
|
new Notice("1/6 Save Remote Sync Preparing");
|
||||||
const s3Client = getS3Client(this.settings.s3);
|
this.syncStatus = "preparing";
|
||||||
const remoteRsp = await listFromRemote(s3Client, this.settings.s3);
|
|
||||||
const local = this.app.vault.getAllLoadedFiles();
|
|
||||||
const localHistory = await loadDeleteRenameHistoryTable(this.db);
|
|
||||||
// console.log(remoteRsp);
|
|
||||||
// console.log(local);
|
|
||||||
// console.log(localHistory);
|
|
||||||
|
|
||||||
const mixedStates = await ensembleMixedStates(
|
new Notice("2/6 Starting to fetch remote meta data.");
|
||||||
remoteRsp.Contents,
|
this.syncStatus = "getting_remote_meta";
|
||||||
local,
|
const s3Client = getS3Client(this.settings.s3);
|
||||||
localHistory,
|
const remoteRsp = await listFromRemote(s3Client, this.settings.s3);
|
||||||
this.db,
|
|
||||||
this.settings.password
|
|
||||||
);
|
|
||||||
|
|
||||||
for (const [key, val] of Object.entries(mixedStates)) {
|
new Notice("3/6 Starting to fetch local meta data.");
|
||||||
getOperation(val, true);
|
this.syncStatus = "getting_local_meta";
|
||||||
|
const local = this.app.vault.getAllLoadedFiles();
|
||||||
|
const localHistory = await loadDeleteRenameHistoryTable(this.db);
|
||||||
|
// console.log(remoteRsp);
|
||||||
|
// console.log(local);
|
||||||
|
// console.log(localHistory);
|
||||||
|
|
||||||
|
new Notice("4/6 Starting to generate sync plan.");
|
||||||
|
const mixedStates = await ensembleMixedStates(
|
||||||
|
remoteRsp.Contents,
|
||||||
|
local,
|
||||||
|
localHistory,
|
||||||
|
this.db,
|
||||||
|
this.settings.password
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const [key, val] of Object.entries(mixedStates)) {
|
||||||
|
getOperation(val, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(mixedStates);
|
||||||
|
|
||||||
|
// The operations above are read only and kind of safe.
|
||||||
|
// The operations below begins to write or delete (!!!) something.
|
||||||
|
|
||||||
|
new Notice("5/6 Save Remote Sync data exchanging!");
|
||||||
|
|
||||||
|
this.syncStatus = "syncing";
|
||||||
|
await doActualSync(
|
||||||
|
s3Client,
|
||||||
|
this.settings.s3,
|
||||||
|
this.db,
|
||||||
|
this.app.vault,
|
||||||
|
mixedStates,
|
||||||
|
this.settings.password
|
||||||
|
);
|
||||||
|
|
||||||
|
new Notice("6/6 Save Remote finish!");
|
||||||
|
this.syncStatus = "idle";
|
||||||
|
} catch (error) {
|
||||||
|
new Notice(`Save Remote error while ${this.syncStatus}: ${error}`);
|
||||||
|
this.syncStatus = "idle";
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(mixedStates);
|
|
||||||
|
|
||||||
// The operations above are read only and kind of safe.
|
|
||||||
// The operations below begins to write or delete (!!!) something.
|
|
||||||
|
|
||||||
new Notice("Save Remote Sync data exchanging!");
|
|
||||||
|
|
||||||
await doActualSync(
|
|
||||||
s3Client,
|
|
||||||
this.settings.s3,
|
|
||||||
this.db,
|
|
||||||
this.app.vault,
|
|
||||||
mixedStates,
|
|
||||||
this.settings.password
|
|
||||||
);
|
|
||||||
|
|
||||||
new Notice("Save Remote finish!");
|
|
||||||
this.syncStatus = "idle";
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.addSettingTab(new SaveRemoteSettingTab(this.app, this));
|
this.addSettingTab(new SaveRemoteSettingTab(this.app, this));
|
||||||
|
|||||||
@ -31,7 +31,14 @@ type DecisionType =
|
|||||||
| "mkdirplocal"
|
| "mkdirplocal"
|
||||||
| "skip";
|
| "skip";
|
||||||
|
|
||||||
export type SyncStatusType = "idle" | "preparing" | "syncing";
|
export type SyncStatusType =
|
||||||
|
| "idle"
|
||||||
|
| "preparing"
|
||||||
|
| "getting_remote_meta"
|
||||||
|
| "getting_local_meta"
|
||||||
|
| "generating_plan"
|
||||||
|
| "syncing"
|
||||||
|
| "finish";
|
||||||
|
|
||||||
interface FileOrFolderMixedState {
|
interface FileOrFolderMixedState {
|
||||||
key: string;
|
key: string;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user