fix stat on Android, add operations to nan ctime mtime and undefined size

This commit is contained in:
fyears
2022-05-10 21:15:30 +08:00
parent 4e8bec9511
commit 28bd861c9e
5 changed files with 56 additions and 21 deletions
+23 -4
View File
@@ -339,12 +339,9 @@ export const checkHasSpecialCharForDir = (x: string) => {
};
export const unixTimeToStr = (x: number | undefined | null) => {
if (x === undefined) {
if (x === undefined || x === null || Number.isNaN(x)) {
return undefined;
}
if (x === null) {
return null;
}
return window.moment(x).format() as string;
};
@@ -408,3 +405,25 @@ export const toText = (x: any) => {
return `${x}`;
}
};
/**
* On Android the stat has bugs for folders. So we need a fixed version.
* @param vault
* @param path
*/
export const statFix = async (vault: Vault, path: string) => {
const s = await vault.adapter.stat(path);
if (s.ctime === undefined || s.ctime === null || Number.isNaN(s.ctime)) {
s.ctime = undefined;
}
if (s.mtime === undefined || s.mtime === null || Number.isNaN(s.mtime)) {
s.mtime = undefined;
}
if (
(s.size === undefined || s.size === null || Number.isNaN(s.size)) &&
s.type === "folder"
) {
s.size = 0;
}
return s;
};