export sync plans in table format
This commit is contained in:
parent
39940deb3f
commit
99f143115b
@ -11,14 +11,73 @@ import {
|
||||
DEFAULT_DEBUG_FOLDER,
|
||||
DEFAULT_LOG_HISTORY_FILE_PREFIX,
|
||||
DEFAULT_SYNC_PLANS_HISTORY_FILE_PREFIX,
|
||||
FileOrFolderMixedState,
|
||||
} from "./baseTypes";
|
||||
|
||||
import { log } from "./moreOnLog";
|
||||
|
||||
const turnSyncPlanToTable = (record: string) => {
|
||||
const syncPlan: SyncPlanType = JSON.parse(record);
|
||||
const { ts, tsFmt, remoteType, mixedStates } = syncPlan;
|
||||
|
||||
type allowedHeadersType = keyof FileOrFolderMixedState;
|
||||
const headers: allowedHeadersType[] = [
|
||||
"key",
|
||||
"remoteEncryptedKey",
|
||||
"existLocal",
|
||||
"sizeLocal",
|
||||
"mtimeLocal",
|
||||
"deltimeLocal",
|
||||
"changeLocalMtimeUsingMapping",
|
||||
"existRemote",
|
||||
"sizeRemote",
|
||||
"mtimeRemote",
|
||||
"deltimeRemote",
|
||||
"changeRemoteMtimeUsingMapping",
|
||||
"decision",
|
||||
"decisionBranch",
|
||||
];
|
||||
|
||||
const lines = [
|
||||
`ts: ${ts}${tsFmt !== undefined ? " / " + tsFmt : ""}`,
|
||||
`remoteType: ${remoteType}`,
|
||||
`| ${headers.join(" | ")} |`,
|
||||
`| ${headers.map((x) => "---").join(" | ")} |`,
|
||||
];
|
||||
for (const [k1, v1] of Object.entries(syncPlan.mixedStates)) {
|
||||
const k = k1 as string;
|
||||
const v = v1 as FileOrFolderMixedState;
|
||||
const singleLine = [];
|
||||
for (const h of headers) {
|
||||
const field = v[h];
|
||||
if (field === undefined) {
|
||||
singleLine.push("");
|
||||
continue;
|
||||
}
|
||||
if (
|
||||
h === "mtimeLocal" ||
|
||||
h === "deltimeLocal" ||
|
||||
h === "mtimeRemote" ||
|
||||
h === "deltimeRemote"
|
||||
) {
|
||||
const fmt = v[(h + "Fmt") as allowedHeadersType] as string;
|
||||
const s = `${field}${fmt !== undefined ? " / " + fmt : ""}`;
|
||||
singleLine.push(s);
|
||||
} else {
|
||||
singleLine.push(field);
|
||||
}
|
||||
}
|
||||
lines.push(`| ${singleLine.join(" | ")} |`);
|
||||
}
|
||||
|
||||
return lines.join("\n");
|
||||
};
|
||||
|
||||
export const exportVaultSyncPlansToFiles = async (
|
||||
db: InternalDBs,
|
||||
vault: Vault,
|
||||
vaultRandomID: string
|
||||
vaultRandomID: string,
|
||||
toFormat: "table" | "json" = "json"
|
||||
) => {
|
||||
log.info("exporting");
|
||||
await mkdirpInVault(DEFAULT_DEBUG_FOLDER, vault);
|
||||
@ -27,9 +86,16 @@ export const exportVaultSyncPlansToFiles = async (
|
||||
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");
|
||||
if (toFormat === "json") {
|
||||
md =
|
||||
"Sync plans found:\n\n" +
|
||||
records.map((x) => "```json\n" + x + "\n```\n").join("\n");
|
||||
} else if (toFormat === "table") {
|
||||
md =
|
||||
"Sync plans found:\n\n" + records.map(turnSyncPlanToTable).join("\n\n");
|
||||
} else {
|
||||
const _: never = toFormat;
|
||||
}
|
||||
}
|
||||
const ts = Date.now();
|
||||
const filePath = `${DEFAULT_DEBUG_FOLDER}${DEFAULT_SYNC_PLANS_HISTORY_FILE_PREFIX}${ts}.md`;
|
||||
|
||||
@ -1 +1 @@
|
||||
Subproject commit 6bfbaa3c1b5c54885b300d6fb93f9c98d50f54e4
|
||||
Subproject commit 470fe141ef48237e81eb84cb466f9bc7f374274c
|
||||
22
src/main.ts
22
src/main.ts
@ -676,14 +676,30 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
});
|
||||
|
||||
this.addCommand({
|
||||
id: "export-sync-plans",
|
||||
name: t("command_exportsyncplans"),
|
||||
id: "export-sync-plans-json",
|
||||
name: t("command_exportsyncplans_json"),
|
||||
icon: iconNameLogs,
|
||||
callback: async () => {
|
||||
await exportVaultSyncPlansToFiles(
|
||||
this.db,
|
||||
this.app.vault,
|
||||
this.vaultRandomID
|
||||
this.vaultRandomID,
|
||||
"json"
|
||||
);
|
||||
new Notice(t("settings_syncplans_notice"));
|
||||
},
|
||||
});
|
||||
|
||||
this.addCommand({
|
||||
id: "export-sync-plans-table",
|
||||
name: t("command_exportsyncplans_table"),
|
||||
icon: iconNameLogs,
|
||||
callback: async () => {
|
||||
await exportVaultSyncPlansToFiles(
|
||||
this.db,
|
||||
this.app.vault,
|
||||
this.vaultRandomID,
|
||||
"table"
|
||||
);
|
||||
new Notice(t("settings_syncplans_notice"));
|
||||
},
|
||||
|
||||
@ -1687,12 +1687,25 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
.setName(t("settings_syncplans"))
|
||||
.setDesc(t("settings_syncplans_desc"))
|
||||
.addButton(async (button) => {
|
||||
button.setButtonText(t("settings_syncplans_button"));
|
||||
button.setButtonText(t("settings_syncplans_button_json"));
|
||||
button.onClick(async () => {
|
||||
await exportVaultSyncPlansToFiles(
|
||||
this.plugin.db,
|
||||
this.app.vault,
|
||||
this.plugin.vaultRandomID
|
||||
this.plugin.vaultRandomID,
|
||||
"json"
|
||||
);
|
||||
new Notice(t("settings_syncplans_notice"));
|
||||
});
|
||||
})
|
||||
.addButton(async (button) => {
|
||||
button.setButtonText(t("settings_syncplans_button_table"));
|
||||
button.onClick(async () => {
|
||||
await exportVaultSyncPlansToFiles(
|
||||
this.plugin.db,
|
||||
this.app.vault,
|
||||
this.plugin.vaultRandomID,
|
||||
"table"
|
||||
);
|
||||
new Notice(t("settings_syncplans_notice"));
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user