add human readable time
This commit is contained in:
parent
b8c4a2bd9a
commit
b39544b43b
@ -145,6 +145,11 @@ export interface FileOrFolderMixedState {
|
|||||||
decisionBranch?: number;
|
decisionBranch?: number;
|
||||||
syncDone?: "done";
|
syncDone?: "done";
|
||||||
remoteEncryptedKey?: string;
|
remoteEncryptedKey?: string;
|
||||||
|
|
||||||
|
mtimeLocalFmt?: string;
|
||||||
|
mtimeRemoteFmt?: string;
|
||||||
|
deltimeLocalFmt?: string;
|
||||||
|
deltimeRemoteFmt?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const API_VER_STAT_FOLDER = "0.13.27";
|
export const API_VER_STAT_FOLDER = "0.13.27";
|
||||||
|
|||||||
@ -516,6 +516,7 @@ export const insertSyncPlanRecordByVault = async (
|
|||||||
) => {
|
) => {
|
||||||
const record = {
|
const record = {
|
||||||
ts: syncPlan.ts,
|
ts: syncPlan.ts,
|
||||||
|
tsFmt: syncPlan.tsFmt,
|
||||||
vaultRandomID: vaultRandomID,
|
vaultRandomID: vaultRandomID,
|
||||||
remoteType: syncPlan.remoteType,
|
remoteType: syncPlan.remoteType,
|
||||||
syncPlan: JSON.stringify(syncPlan /* directly stringify */, null, 2),
|
syncPlan: JSON.stringify(syncPlan /* directly stringify */, null, 2),
|
||||||
|
|||||||
16
src/misc.ts
16
src/misc.ts
@ -7,6 +7,12 @@ import XRegExp from "xregexp";
|
|||||||
import * as origLog from "loglevel";
|
import * as origLog from "loglevel";
|
||||||
const log = origLog.getLogger("rs-default");
|
const log = origLog.getLogger("rs-default");
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface Window {
|
||||||
|
moment: (...data: any) => any;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If any part of the file starts with '.' or '_' then it's a hidden file.
|
* If any part of the file starts with '.' or '_' then it's a hidden file.
|
||||||
* @param item
|
* @param item
|
||||||
@ -303,3 +309,13 @@ export const atWhichLevel = (x: string) => {
|
|||||||
export const checkHasSpecialCharForDir = (x: string) => {
|
export const checkHasSpecialCharForDir = (x: string) => {
|
||||||
return /[?/\\]/.test(x);
|
return /[?/\\]/.test(x);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const unixTimeToStr = (x: number | undefined | null) => {
|
||||||
|
if (x === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
if (x === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return window.moment(x).format() as string;
|
||||||
|
};
|
||||||
|
|||||||
32
src/sync.ts
32
src/sync.ts
@ -33,6 +33,7 @@ import {
|
|||||||
getFolderLevels,
|
getFolderLevels,
|
||||||
getParentFolder,
|
getParentFolder,
|
||||||
atWhichLevel,
|
atWhichLevel,
|
||||||
|
unixTimeToStr,
|
||||||
} from "./misc";
|
} from "./misc";
|
||||||
import { RemoteClient } from "./remote";
|
import { RemoteClient } from "./remote";
|
||||||
import {
|
import {
|
||||||
@ -63,6 +64,7 @@ export type SyncStatusType =
|
|||||||
|
|
||||||
export interface SyncPlanType {
|
export interface SyncPlanType {
|
||||||
ts: number;
|
ts: number;
|
||||||
|
tsFmt?: string;
|
||||||
remoteType: SUPPORTED_SERVICES_TYPE;
|
remoteType: SUPPORTED_SERVICES_TYPE;
|
||||||
mixedStates: Record<string, FileOrFolderMixedState>;
|
mixedStates: Record<string, FileOrFolderMixedState>;
|
||||||
}
|
}
|
||||||
@ -212,10 +214,12 @@ export const parseRemoteItems = async (
|
|||||||
let r = {} as FileOrFolderMixedState;
|
let r = {} as FileOrFolderMixedState;
|
||||||
if (backwardMapping !== undefined) {
|
if (backwardMapping !== undefined) {
|
||||||
key = backwardMapping.localKey;
|
key = backwardMapping.localKey;
|
||||||
|
const mtimeRemote = backwardMapping.localMtime || entry.lastModified;
|
||||||
r = {
|
r = {
|
||||||
key: key,
|
key: key,
|
||||||
existRemote: true,
|
existRemote: true,
|
||||||
mtimeRemote: backwardMapping.localMtime || entry.lastModified,
|
mtimeRemote: mtimeRemote,
|
||||||
|
mtimeRemoteFmt: unixTimeToStr(mtimeRemote),
|
||||||
sizeRemote: backwardMapping.localSize || entry.size,
|
sizeRemote: backwardMapping.localSize || entry.size,
|
||||||
remoteEncryptedKey: remoteEncryptedKey,
|
remoteEncryptedKey: remoteEncryptedKey,
|
||||||
changeRemoteMtimeUsingMapping: true,
|
changeRemoteMtimeUsingMapping: true,
|
||||||
@ -225,6 +229,7 @@ export const parseRemoteItems = async (
|
|||||||
key: key,
|
key: key,
|
||||||
existRemote: true,
|
existRemote: true,
|
||||||
mtimeRemote: entry.lastModified,
|
mtimeRemote: entry.lastModified,
|
||||||
|
mtimeRemoteFmt: unixTimeToStr(entry.lastModified),
|
||||||
sizeRemote: entry.size,
|
sizeRemote: entry.size,
|
||||||
remoteEncryptedKey: remoteEncryptedKey,
|
remoteEncryptedKey: remoteEncryptedKey,
|
||||||
changeRemoteMtimeUsingMapping: false,
|
changeRemoteMtimeUsingMapping: false,
|
||||||
@ -320,10 +325,12 @@ const ensembleMixedStates = async (
|
|||||||
// ignore
|
// ignore
|
||||||
continue;
|
continue;
|
||||||
} else if (entry instanceof TFile) {
|
} else if (entry instanceof TFile) {
|
||||||
|
const mtimeLocal = Math.max(entry.stat.mtime || 0, entry.stat.ctime || 0);
|
||||||
r = {
|
r = {
|
||||||
key: entry.path,
|
key: entry.path,
|
||||||
existLocal: true,
|
existLocal: true,
|
||||||
mtimeLocal: Math.max(entry.stat.mtime || 0, entry.stat.ctime || 0),
|
mtimeLocal: mtimeLocal,
|
||||||
|
mtimeLocalFmt: unixTimeToStr(mtimeLocal),
|
||||||
sizeLocal: entry.stat.size,
|
sizeLocal: entry.stat.size,
|
||||||
};
|
};
|
||||||
} else if (entry instanceof TFolder) {
|
} else if (entry instanceof TFolder) {
|
||||||
@ -332,6 +339,7 @@ const ensembleMixedStates = async (
|
|||||||
key: key,
|
key: key,
|
||||||
existLocal: true,
|
existLocal: true,
|
||||||
mtimeLocal: undefined,
|
mtimeLocal: undefined,
|
||||||
|
mtimeLocalFmt: undefined,
|
||||||
sizeLocal: 0,
|
sizeLocal: 0,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
@ -346,6 +354,7 @@ const ensembleMixedStates = async (
|
|||||||
results[key].key = r.key;
|
results[key].key = r.key;
|
||||||
results[key].existLocal = r.existLocal;
|
results[key].existLocal = r.existLocal;
|
||||||
results[key].mtimeLocal = r.mtimeLocal;
|
results[key].mtimeLocal = r.mtimeLocal;
|
||||||
|
results[key].mtimeLocalFmt = r.mtimeLocalFmt;
|
||||||
results[key].sizeLocal = r.sizeLocal;
|
results[key].sizeLocal = r.sizeLocal;
|
||||||
} else {
|
} else {
|
||||||
results[key] = r;
|
results[key] = r;
|
||||||
@ -356,10 +365,12 @@ const ensembleMixedStates = async (
|
|||||||
if (syncConfigDir && localConfigDirContents !== undefined) {
|
if (syncConfigDir && localConfigDirContents !== undefined) {
|
||||||
for (const entry of localConfigDirContents) {
|
for (const entry of localConfigDirContents) {
|
||||||
const key = entry.key;
|
const key = entry.key;
|
||||||
|
const mtimeLocal = Math.max(entry.mtime, entry.ctime);
|
||||||
const r: FileOrFolderMixedState = {
|
const r: FileOrFolderMixedState = {
|
||||||
key: key,
|
key: key,
|
||||||
existLocal: true,
|
existLocal: true,
|
||||||
mtimeLocal: Math.max(entry.mtime, entry.ctime),
|
mtimeLocal: mtimeLocal,
|
||||||
|
mtimeLocalFmt: unixTimeToStr(mtimeLocal),
|
||||||
sizeLocal: entry.size,
|
sizeLocal: entry.size,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -367,6 +378,7 @@ const ensembleMixedStates = async (
|
|||||||
results[key].key = r.key;
|
results[key].key = r.key;
|
||||||
results[key].existLocal = r.existLocal;
|
results[key].existLocal = r.existLocal;
|
||||||
results[key].mtimeLocal = r.mtimeLocal;
|
results[key].mtimeLocal = r.mtimeLocal;
|
||||||
|
results[key].mtimeLocalFmt = r.mtimeLocalFmt;
|
||||||
results[key].sizeLocal = r.sizeLocal;
|
results[key].sizeLocal = r.sizeLocal;
|
||||||
} else {
|
} else {
|
||||||
results[key] = r;
|
results[key] = r;
|
||||||
@ -380,6 +392,7 @@ const ensembleMixedStates = async (
|
|||||||
const r = {
|
const r = {
|
||||||
key: key,
|
key: key,
|
||||||
deltimeRemote: entry.actionWhen,
|
deltimeRemote: entry.actionWhen,
|
||||||
|
deltimeRemoteFmt: unixTimeToStr(entry.actionWhen),
|
||||||
} as FileOrFolderMixedState;
|
} as FileOrFolderMixedState;
|
||||||
|
|
||||||
if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir)) {
|
if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir)) {
|
||||||
@ -389,6 +402,7 @@ const ensembleMixedStates = async (
|
|||||||
if (results.hasOwnProperty(key)) {
|
if (results.hasOwnProperty(key)) {
|
||||||
results[key].key = r.key;
|
results[key].key = r.key;
|
||||||
results[key].deltimeRemote = r.deltimeRemote;
|
results[key].deltimeRemote = r.deltimeRemote;
|
||||||
|
results[key].deltimeRemoteFmt = r.deltimeRemoteFmt;
|
||||||
} else {
|
} else {
|
||||||
results[key] = r;
|
results[key] = r;
|
||||||
|
|
||||||
@ -417,10 +431,12 @@ const ensembleMixedStates = async (
|
|||||||
const r = {
|
const r = {
|
||||||
key: key,
|
key: key,
|
||||||
deltimeLocal: entry.actionWhen,
|
deltimeLocal: entry.actionWhen,
|
||||||
|
deltimeLocalFmt: unixTimeToStr(entry.actionWhen),
|
||||||
} as FileOrFolderMixedState;
|
} as FileOrFolderMixedState;
|
||||||
|
|
||||||
if (results.hasOwnProperty(key)) {
|
if (results.hasOwnProperty(key)) {
|
||||||
results[key].deltimeLocal = r.deltimeLocal;
|
results[key].deltimeLocal = r.deltimeLocal;
|
||||||
|
results[key].deltimeLocalFmt = r.deltimeLocalFmt;
|
||||||
} else {
|
} else {
|
||||||
results[key] = r;
|
results[key] = r;
|
||||||
results[key].existLocal = false; // we have already checked local
|
results[key].existLocal = false; // we have already checked local
|
||||||
@ -430,13 +446,16 @@ const ensembleMixedStates = async (
|
|||||||
const r = {
|
const r = {
|
||||||
key: key,
|
key: key,
|
||||||
mtimeLocal: entry.actionWhen,
|
mtimeLocal: entry.actionWhen,
|
||||||
|
mtimeLocalFmt: unixTimeToStr(entry.actionWhen),
|
||||||
changeLocalMtimeUsingMapping: true,
|
changeLocalMtimeUsingMapping: true,
|
||||||
};
|
};
|
||||||
if (results.hasOwnProperty(key)) {
|
if (results.hasOwnProperty(key)) {
|
||||||
results[key].mtimeLocal = Math.max(
|
const mtimeLocal = Math.max(
|
||||||
r.mtimeLocal || 0,
|
r.mtimeLocal || 0,
|
||||||
results[key].mtimeLocal || 0
|
results[key].mtimeLocal || 0
|
||||||
);
|
);
|
||||||
|
results[key].mtimeLocal = mtimeLocal;
|
||||||
|
results[key].mtimeLocalFmt = unixTimeToStr(mtimeLocal);
|
||||||
results[key].changeLocalMtimeUsingMapping =
|
results[key].changeLocalMtimeUsingMapping =
|
||||||
r.changeLocalMtimeUsingMapping;
|
r.changeLocalMtimeUsingMapping;
|
||||||
} else {
|
} else {
|
||||||
@ -793,8 +812,11 @@ export const getSyncPlan = async (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const currTs = Date.now();
|
||||||
|
const currTsFmt = unixTimeToStr(currTs);
|
||||||
const plan = {
|
const plan = {
|
||||||
ts: Date.now(),
|
ts: currTs,
|
||||||
|
tsFmt: currTsFmt,
|
||||||
remoteType: remoteType,
|
remoteType: remoteType,
|
||||||
mixedStates: mixedStates,
|
mixedStates: mixedStates,
|
||||||
} as SyncPlanType;
|
} as SyncPlanType;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user