add a little helper to see file stat
This commit is contained in:
parent
ed52a8542f
commit
3d1269a9f2
@ -4,14 +4,14 @@ import { FakeFs } from "./fsAll";
|
|||||||
import { TFile, TFolder, type Vault } from "obsidian";
|
import { TFile, TFolder, type Vault } from "obsidian";
|
||||||
import { listFilesInObsFolder } from "./obsFolderLister";
|
import { listFilesInObsFolder } from "./obsFolderLister";
|
||||||
import { Profiler } from "./profiler";
|
import { Profiler } from "./profiler";
|
||||||
import { getFolderLevels, mkdirpInVault, statFix } from "./misc";
|
import { getFolderLevels, mkdirpInVault, statFix, unixTimeToStr } from "./misc";
|
||||||
|
|
||||||
export class FakeFsLocal extends FakeFs {
|
export class FakeFsLocal extends FakeFs {
|
||||||
vault: Vault;
|
vault: Vault;
|
||||||
syncConfigDir: boolean;
|
syncConfigDir: boolean;
|
||||||
configDir: string;
|
configDir: string;
|
||||||
pluginID: string;
|
pluginID: string;
|
||||||
profiler: Profiler;
|
profiler: Profiler | undefined;
|
||||||
deleteToWhere: "obsidian" | "system";
|
deleteToWhere: "obsidian" | "system";
|
||||||
kind: "local";
|
kind: "local";
|
||||||
constructor(
|
constructor(
|
||||||
@ -19,7 +19,7 @@ export class FakeFsLocal extends FakeFs {
|
|||||||
syncConfigDir: boolean,
|
syncConfigDir: boolean,
|
||||||
configDir: string,
|
configDir: string,
|
||||||
pluginID: string,
|
pluginID: string,
|
||||||
profiler: Profiler,
|
profiler: Profiler | undefined,
|
||||||
deleteToWhere: "obsidian" | "system"
|
deleteToWhere: "obsidian" | "system"
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
@ -34,12 +34,12 @@ export class FakeFsLocal extends FakeFs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async walk(): Promise<Entity[]> {
|
async walk(): Promise<Entity[]> {
|
||||||
this.profiler.addIndent();
|
this.profiler?.addIndent();
|
||||||
this.profiler.insert("enter walk for local");
|
this.profiler?.insert("enter walk for local");
|
||||||
const local: Entity[] = [];
|
const local: Entity[] = [];
|
||||||
|
|
||||||
const localTAbstractFiles = this.vault.getAllLoadedFiles();
|
const localTAbstractFiles = this.vault.getAllLoadedFiles();
|
||||||
this.profiler.insert("finish getting walk for local");
|
this.profiler?.insert("finish getting walk for local");
|
||||||
for (const entry of localTAbstractFiles) {
|
for (const entry of localTAbstractFiles) {
|
||||||
let r: Entity | undefined = undefined;
|
let r: Entity | undefined = undefined;
|
||||||
let key = entry.path;
|
let key = entry.path;
|
||||||
@ -89,10 +89,10 @@ export class FakeFsLocal extends FakeFs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.profiler.insert("finish transforming walk for local");
|
this.profiler?.insert("finish transforming walk for local");
|
||||||
|
|
||||||
if (this.syncConfigDir) {
|
if (this.syncConfigDir) {
|
||||||
this.profiler.insert("into syncConfigDir");
|
this.profiler?.insert("into syncConfigDir");
|
||||||
const syncFiles = await listFilesInObsFolder(
|
const syncFiles = await listFilesInObsFolder(
|
||||||
this.configDir,
|
this.configDir,
|
||||||
this.vault,
|
this.vault,
|
||||||
@ -101,11 +101,11 @@ export class FakeFsLocal extends FakeFs {
|
|||||||
for (const f of syncFiles) {
|
for (const f of syncFiles) {
|
||||||
local.push(f);
|
local.push(f);
|
||||||
}
|
}
|
||||||
this.profiler.insert("finish syncConfigDir");
|
this.profiler?.insert("finish syncConfigDir");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.profiler.insert("finish walk for local");
|
this.profiler?.insert("finish walk for local");
|
||||||
this.profiler.removeIndent();
|
this.profiler?.removeIndent();
|
||||||
return local;
|
return local;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,6 +120,8 @@ export class FakeFsLocal extends FakeFs {
|
|||||||
keyRaw: isFolder ? `${key}/` : key,
|
keyRaw: isFolder ? `${key}/` : key,
|
||||||
mtimeCli: statRes.mtime,
|
mtimeCli: statRes.mtime,
|
||||||
mtimeSvr: statRes.mtime,
|
mtimeSvr: statRes.mtime,
|
||||||
|
mtimeCliFmt: unixTimeToStr(statRes.mtime),
|
||||||
|
mtimeSvrFmt: unixTimeToStr(statRes.mtime),
|
||||||
size: statRes.size, // local always unencrypted
|
size: statRes.size, // local always unencrypted
|
||||||
sizeRaw: statRes.size,
|
sizeRaw: statRes.size,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -342,5 +342,7 @@
|
|||||||
"syncalgov3_checkbox_manual_backup": "I will backup my vault manually firstly.",
|
"syncalgov3_checkbox_manual_backup": "I will backup my vault manually firstly.",
|
||||||
"syncalgov3_checkbox_requiremultidevupdate": "I understand I need to update the plugin ACROSS ALL DEVICES to make them work properly.",
|
"syncalgov3_checkbox_requiremultidevupdate": "I understand I need to update the plugin ACROSS ALL DEVICES to make them work properly.",
|
||||||
"syncalgov3_button_agree": "Agree",
|
"syncalgov3_button_agree": "Agree",
|
||||||
"syncalgov3_button_disagree": "Do Not Agree"
|
"syncalgov3_button_disagree": "Do Not Agree",
|
||||||
|
|
||||||
|
"menu_check_file_stat": "Check file stats"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -341,5 +341,7 @@
|
|||||||
"syncalgov3_checkbox_manual_backup": "我将会首先手动备份我的库(Vault)。",
|
"syncalgov3_checkbox_manual_backup": "我将会首先手动备份我的库(Vault)。",
|
||||||
"syncalgov3_checkbox_requiremultidevupdate": "我理解,我需要在所有设备上都更新此插件使之正常运行。",
|
"syncalgov3_checkbox_requiremultidevupdate": "我理解,我需要在所有设备上都更新此插件使之正常运行。",
|
||||||
"syncalgov3_button_agree": "同意",
|
"syncalgov3_button_agree": "同意",
|
||||||
"syncalgov3_button_disagree": "不同意"
|
"syncalgov3_button_disagree": "不同意",
|
||||||
|
|
||||||
|
"menu_check_file_stat": "查看文件属性"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -340,5 +340,7 @@
|
|||||||
"syncalgov3_checkbox_manual_backup": "我將會首先手動備份我的庫(Vault)。",
|
"syncalgov3_checkbox_manual_backup": "我將會首先手動備份我的庫(Vault)。",
|
||||||
"syncalgov3_checkbox_requiremultidevupdate": "我理解,我需要在所有裝置上都更新此外掛使之正常執行。",
|
"syncalgov3_checkbox_requiremultidevupdate": "我理解,我需要在所有裝置上都更新此外掛使之正常執行。",
|
||||||
"syncalgov3_button_agree": "同意",
|
"syncalgov3_button_agree": "同意",
|
||||||
"syncalgov3_button_disagree": "不同意"
|
"syncalgov3_button_disagree": "不同意",
|
||||||
|
|
||||||
|
"menu_check_file_stat": "檢視檔案屬性"
|
||||||
}
|
}
|
||||||
|
|||||||
38
src/main.ts
38
src/main.ts
@ -9,6 +9,7 @@ import {
|
|||||||
Platform,
|
Platform,
|
||||||
requireApiVersion,
|
requireApiVersion,
|
||||||
Events,
|
Events,
|
||||||
|
TFolder,
|
||||||
} from "obsidian";
|
} from "obsidian";
|
||||||
import cloneDeep from "lodash/cloneDeep";
|
import cloneDeep from "lodash/cloneDeep";
|
||||||
import { createElement, RotateCcw, RefreshCcw, FileText } from "lucide";
|
import { createElement, RotateCcw, RefreshCcw, FileText } from "lucide";
|
||||||
@ -783,6 +784,8 @@ export default class RemotelySavePlugin extends Plugin {
|
|||||||
// console.info("click", evt);
|
// console.info("click", evt);
|
||||||
// });
|
// });
|
||||||
|
|
||||||
|
this.enableCheckingFileStat();
|
||||||
|
|
||||||
if (!this.settings.agreeToUseSyncV3) {
|
if (!this.settings.agreeToUseSyncV3) {
|
||||||
const syncAlgoV3Modal = new SyncAlgoV3Modal(this.app, this);
|
const syncAlgoV3Modal = new SyncAlgoV3Modal(this.app, this);
|
||||||
syncAlgoV3Modal.open();
|
syncAlgoV3Modal.open();
|
||||||
@ -1198,6 +1201,41 @@ export default class RemotelySavePlugin extends Plugin {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enableCheckingFileStat() {
|
||||||
|
this.app.workspace.onLayoutReady(() => {
|
||||||
|
const t = (x: TransItemType, vars?: any) => {
|
||||||
|
return this.i18n.t(x, vars);
|
||||||
|
};
|
||||||
|
this.registerEvent(
|
||||||
|
this.app.workspace.on("file-menu", (menu, file) => {
|
||||||
|
if (file instanceof TFolder) {
|
||||||
|
// folder not supported yet
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
menu.addItem((item) => {
|
||||||
|
item
|
||||||
|
.setTitle(t("menu_check_file_stat"))
|
||||||
|
.setIcon("file-cog")
|
||||||
|
.onClick(async () => {
|
||||||
|
const filePath = file.path;
|
||||||
|
const fsLocal = new FakeFsLocal(
|
||||||
|
this.app.vault,
|
||||||
|
this.settings.syncConfigDir ?? false,
|
||||||
|
this.app.vault.configDir,
|
||||||
|
this.manifest.id,
|
||||||
|
undefined,
|
||||||
|
this.settings.deleteToWhere ?? "system"
|
||||||
|
);
|
||||||
|
const s = await fsLocal.stat(filePath);
|
||||||
|
new Notice(JSON.stringify(s, null, 2), 10000);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async saveAgreeToUseNewSyncAlgorithm() {
|
async saveAgreeToUseNewSyncAlgorithm() {
|
||||||
this.settings.agreeToUseSyncV3 = true;
|
this.settings.agreeToUseSyncV3 = true;
|
||||||
await this.saveSettings();
|
await this.saveSettings();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user