From 13537d1481c71335616d499a39279d57a6b4c944 Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Mon, 18 Apr 2022 00:22:00 +0800 Subject: [PATCH] insert dry run into plan records --- src/baseTypes.ts | 2 ++ src/main.ts | 12 ++++++------ src/sync.ts | 10 +++++++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/baseTypes.ts b/src/baseTypes.ts index e59262b..dc074c9 100644 --- a/src/baseTypes.ts +++ b/src/baseTypes.ts @@ -165,3 +165,5 @@ export const DEFAULT_DEBUG_FOLDER = "_debug_remotely_save/"; export const DEFAULT_SYNC_PLANS_HISTORY_FILE_PREFIX = "sync_plans_hist_exported_on_"; export const DEFAULT_LOG_HISTORY_FILE_PREFIX = "log_hist_exported_on_"; + +export type SyncTriggerSourceType = "manual" | "auto" | "dry" | "autoOnceInit"; diff --git a/src/main.ts b/src/main.ts index 0adc8f6..952f0c8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,7 +9,10 @@ import { } from "obsidian"; import cloneDeep from "lodash/cloneDeep"; import { createElement, RotateCcw, RefreshCcw, FileText } from "lucide"; -import type { RemotelySavePluginSettings } from "./baseTypes"; +import type { + RemotelySavePluginSettings, + SyncTriggerSourceType, +} from "./baseTypes"; import { COMMAND_CALLBACK, COMMAND_CALLBACK_ONEDRIVE, @@ -89,8 +92,6 @@ interface OAuth2Info { revokeAuthSetting?: Setting; } -type SyncTriggerSourceType = "manual" | "auto" | "dry" | "autoOnceInit"; - const iconNameSyncWait = `remotely-save-sync-wait`; const iconNameSyncRunning = `remotely-save-sync-running`; const iconNameLogs = `remotely-save-logs`; @@ -286,6 +287,7 @@ export default class RemotelySavePlugin extends Plugin { origMetadataOnRemote.deletions, localHistory, client.serviceType, + triggerSource, this.app.vault, this.settings.syncConfigDir, this.app.vault.configDir, @@ -293,9 +295,7 @@ export default class RemotelySavePlugin extends Plugin { this.settings.password ); log.info(plan.mixedStates); // for debugging - if (triggerSource !== "dry") { - await insertSyncPlanRecordByVault(this.db, plan, this.vaultRandomID); - } + await insertSyncPlanRecordByVault(this.db, plan, this.vaultRandomID); // The operations above are almost read only and kind of safe. // The operations below begins to write or delete (!!!) something. diff --git a/src/sync.ts b/src/sync.ts index 1bd68bd..edf100b 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -7,13 +7,14 @@ import { } from "obsidian"; import AggregateError from "aggregate-error"; import PQueue from "p-queue"; -import { +import type { RemoteItem, - SUPPORTED_SERVICES_TYPE, + SyncTriggerSourceType, DecisionType, FileOrFolderMixedState, - API_VER_STAT_FOLDER, + SUPPORTED_SERVICES_TYPE, } from "./baseTypes"; +import { API_VER_STAT_FOLDER } from "./baseTypes"; import { decryptBase32ToString, decryptBase64urlToString, @@ -65,6 +66,7 @@ export type SyncStatusType = export interface SyncPlanType { ts: number; tsFmt?: string; + syncTriggerSource?: SyncTriggerSourceType; remoteType: SUPPORTED_SERVICES_TYPE; mixedStates: Record; } @@ -752,6 +754,7 @@ export const getSyncPlan = async ( remoteDeleteHistory: DeletionOnRemote[], localFileHistory: FileFolderHistoryRecord[], remoteType: SUPPORTED_SERVICES_TYPE, + triggerSource: SyncTriggerSourceType, vault: Vault, syncConfigDir: boolean, configDir: string, @@ -824,6 +827,7 @@ export const getSyncPlan = async ( ts: currTs, tsFmt: currTsFmt, remoteType: remoteType, + syncTriggerSource: triggerSource, mixedStates: mixedStates, } as SyncPlanType; return {