import { TAbstractFile, TFolder, TFile, Vault } from "obsidian"; import type { SyncPlanType } from "./sync"; import { readAllSyncPlanRecordTextsByVault } from "./localdb"; import type { InternalDBs } from "./localdb"; import { mkdirpInVault } from "./misc"; import * as origLog from "loglevel"; const log = origLog.getLogger("rs-default"); const DEFAULT_DEBUG_FOLDER = "_debug_remotely_save/"; const DEFAULT_SYNC_PLANS_HISTORY_FILE_PREFIX = "sync_plans_hist_exported_on_"; export const exportVaultSyncPlansToFiles = async ( db: InternalDBs, vault: Vault, vaultRandomID: string ) => { log.info("exporting"); await mkdirpInVault(DEFAULT_DEBUG_FOLDER, vault); const records = await readAllSyncPlanRecordTextsByVault(db, vaultRandomID); let md = ""; if (records.length === 0) { md = "No sync plans history found"; } else { md = "Sync plans found:\n\n" + records.map((x) => "```json\n" + x + "\n```\n").join("\n"); } const ts = Date.now(); const filePath = `${DEFAULT_DEBUG_FOLDER}${DEFAULT_SYNC_PLANS_HISTORY_FILE_PREFIX}${ts}.md`; await vault.create(filePath, md, { mtime: ts, }); log.info("finish exporting"); };