Sync: Local wipe and sync command and better info
This commit is contained in:
@@ -10,6 +10,11 @@ functions:
|
||||
command:
|
||||
name: "Sync: Sync"
|
||||
|
||||
wipeAndSyncCommand:
|
||||
path: sync.ts:localWipeAndSyncCommand
|
||||
command:
|
||||
name: "Sync: Wipe Local Space and Sync"
|
||||
|
||||
check:
|
||||
env: server
|
||||
path: sync.ts:check
|
||||
|
||||
+53
-1
@@ -1,5 +1,11 @@
|
||||
import { store } from "$sb/plugos-syscall/mod.ts";
|
||||
import { editor, sync, system } from "$sb/silverbullet-syscall/mod.ts";
|
||||
import {
|
||||
editor,
|
||||
index,
|
||||
space,
|
||||
sync,
|
||||
system,
|
||||
} from "$sb/silverbullet-syscall/mod.ts";
|
||||
import type { SyncEndpoint } from "$sb/silverbullet-syscall/sync.ts";
|
||||
|
||||
export async function configureCommand() {
|
||||
@@ -68,6 +74,52 @@ export async function syncCommand() {
|
||||
}
|
||||
}
|
||||
|
||||
export async function localWipeAndSyncCommand() {
|
||||
let config: SyncEndpoint | undefined = await store.get("sync.config");
|
||||
if (!config) {
|
||||
config = await configureCommand();
|
||||
if (!config) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
!(await editor.confirm(
|
||||
"Are you sure you want to wipe your local space and sync with the remote?",
|
||||
))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
!(await editor.confirm(
|
||||
"To be clear: this means all local content will be deleted with no way to recover it. Are you sure?",
|
||||
))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Wiping local pages");
|
||||
await editor.flashNotification("Now wiping all pages");
|
||||
for (const page of await space.listPages()) {
|
||||
console.log("Deleting page", page.name);
|
||||
await space.deletePage(page.name);
|
||||
}
|
||||
|
||||
console.log("Wiping local attachments");
|
||||
await editor.flashNotification("Now wiping all attachments");
|
||||
for (const attachment of await space.listAttachments()) {
|
||||
console.log("Deleting attachment", attachment.name);
|
||||
await space.deleteAttachment(attachment.name);
|
||||
}
|
||||
|
||||
console.log("Wiping local sync state");
|
||||
await store.set("sync.snapshot", {});
|
||||
|
||||
// Starting actual sync
|
||||
await syncCommand();
|
||||
}
|
||||
|
||||
// Run on server
|
||||
export function check(config: SyncEndpoint) {
|
||||
return sync.check(config);
|
||||
|
||||
Reference in New Issue
Block a user