export sync plans in table format
This commit is contained in:
parent
39940deb3f
commit
99f143115b
@ -11,14 +11,73 @@ import {
|
|||||||
DEFAULT_DEBUG_FOLDER,
|
DEFAULT_DEBUG_FOLDER,
|
||||||
DEFAULT_LOG_HISTORY_FILE_PREFIX,
|
DEFAULT_LOG_HISTORY_FILE_PREFIX,
|
||||||
DEFAULT_SYNC_PLANS_HISTORY_FILE_PREFIX,
|
DEFAULT_SYNC_PLANS_HISTORY_FILE_PREFIX,
|
||||||
|
FileOrFolderMixedState,
|
||||||
} from "./baseTypes";
|
} from "./baseTypes";
|
||||||
|
|
||||||
import { log } from "./moreOnLog";
|
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 (
|
export const exportVaultSyncPlansToFiles = async (
|
||||||
db: InternalDBs,
|
db: InternalDBs,
|
||||||
vault: Vault,
|
vault: Vault,
|
||||||
vaultRandomID: string
|
vaultRandomID: string,
|
||||||
|
toFormat: "table" | "json" = "json"
|
||||||
) => {
|
) => {
|
||||||
log.info("exporting");
|
log.info("exporting");
|
||||||
await mkdirpInVault(DEFAULT_DEBUG_FOLDER, vault);
|
await mkdirpInVault(DEFAULT_DEBUG_FOLDER, vault);
|
||||||
@ -27,9 +86,16 @@ export const exportVaultSyncPlansToFiles = async (
|
|||||||
if (records.length === 0) {
|
if (records.length === 0) {
|
||||||
md = "No sync plans history found";
|
md = "No sync plans history found";
|
||||||
} else {
|
} else {
|
||||||
|
if (toFormat === "json") {
|
||||||
md =
|
md =
|
||||||
"Sync plans found:\n\n" +
|
"Sync plans found:\n\n" +
|
||||||
records.map((x) => "```json\n" + x + "\n```\n").join("\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 ts = Date.now();
|
||||||
const filePath = `${DEFAULT_DEBUG_FOLDER}${DEFAULT_SYNC_PLANS_HISTORY_FILE_PREFIX}${ts}.md`;
|
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({
|
this.addCommand({
|
||||||
id: "export-sync-plans",
|
id: "export-sync-plans-json",
|
||||||
name: t("command_exportsyncplans"),
|
name: t("command_exportsyncplans_json"),
|
||||||
icon: iconNameLogs,
|
icon: iconNameLogs,
|
||||||
callback: async () => {
|
callback: async () => {
|
||||||
await exportVaultSyncPlansToFiles(
|
await exportVaultSyncPlansToFiles(
|
||||||
this.db,
|
this.db,
|
||||||
this.app.vault,
|
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"));
|
new Notice(t("settings_syncplans_notice"));
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1687,12 +1687,25 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
|||||||
.setName(t("settings_syncplans"))
|
.setName(t("settings_syncplans"))
|
||||||
.setDesc(t("settings_syncplans_desc"))
|
.setDesc(t("settings_syncplans_desc"))
|
||||||
.addButton(async (button) => {
|
.addButton(async (button) => {
|
||||||
button.setButtonText(t("settings_syncplans_button"));
|
button.setButtonText(t("settings_syncplans_button_json"));
|
||||||
button.onClick(async () => {
|
button.onClick(async () => {
|
||||||
await exportVaultSyncPlansToFiles(
|
await exportVaultSyncPlansToFiles(
|
||||||
this.plugin.db,
|
this.plugin.db,
|
||||||
this.app.vault,
|
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"));
|
new Notice(t("settings_syncplans_notice"));
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user