Skip to content

Commit f57f411

Browse files
committed
feat(StatsView): Add local files report.
1 parent 0decb09 commit f57f411

File tree

7 files changed

+52
-7
lines changed

7 files changed

+52
-7
lines changed

src/baseTypes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export type DecisionType =
143143
export type TSyncStatus =
144144
| "pending"
145145
| "syncing"
146+
| "sync-done"
146147
| "publishing"
147148
| "done"
148149
| "fail"
@@ -167,6 +168,7 @@ export interface FileOrFolderMixedState {
167168
decisionBranch?: number;
168169
remoteEncryptedKey?: string;
169170

171+
syncType?: `TOREMOTE` | `TOLOCAL`; // upload to remote OR download to local
170172
syncStatus?: TSyncStatus;
171173
remoteLink?: string;
172174
syncError?: string;

src/components/StatsView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const StatsViewComponent = (props: { plugin: InvioPlugin }) => {
6262
if (url) {
6363
open(url);
6464
} else {
65-
new Notice('This page has been deleted online', 3000);
65+
new Notice('Link not found', 3000);
6666
}
6767
}
6868
const openFile = async (key: string) => {

src/components/store.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ const useStore = create<State>()((set, get) => ({
6767
if (!(obj && obj[key])) {
6868
return;
6969
}
70+
// For ToLocal files, sync done means ready
71+
if ((update.syncStatus === 'sync-done') && (obj[key].syncType === 'TOLOCAL')) {
72+
update.syncStatus = 'done';
73+
}
7074
// Once failed, then all process failed.
7175
if (obj[key].syncStatus === 'fail') {
7276
update.syncStatus = 'fail';

src/exporter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const publishFiles = async (
6969
) => {
7070
const htmlPath = AssetHandler.initHtmlPath();
7171

72-
if (allFiles.length > 100000 || allFiles.length <= 0)
72+
if (allFiles.length > 100000 || allFiles.length < 0)
7373
{
7474
new Notice(`❗Invalid number of files to export: ${allFiles.length}.`, 0);
7575
return {success: false, exportedPath: htmlPath, fileNumber: allFiles.length};

src/main.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ export default class InvioPlugin extends Plugin {
337337
return;
338338
}
339339

340-
const { toRemoteFiles } = TouchedPlanModel.getTouchedFilesGroup(touchedFileMap)
340+
const { toRemoteFiles, toLocalFiles } = TouchedPlanModel.getTouchedFilesGroup(touchedFileMap)
341341

342342

343343
// The operations above are almost read only and kind of safe.
@@ -359,14 +359,14 @@ export default class InvioPlugin extends Plugin {
359359
log.info('init stats view: ', view);
360360
if (view) {
361361
const initData: Record<string, FileOrFolderMixedState> = {};
362-
let changingFiles = toRemoteFiles;
362+
let remoteChangingFiles = toRemoteFiles;
363363
if (triggerSource === 'force') {
364-
changingFiles = allFiles.map(f => {
364+
remoteChangingFiles = allFiles.map(f => {
365365
const fState: FileOrFolderMixedState = { key: f.path, syncStatus: 'syncing' }
366366
return fState;
367367
})
368368
}
369-
changingFiles.forEach(f => {
369+
[ ...remoteChangingFiles, ...toLocalFiles ].forEach(f => {
370370
initData[f.key] = f;
371371
})
372372
view.info('Stats data init...');
@@ -422,6 +422,18 @@ export default class InvioPlugin extends Plugin {
422422
log.info('ignore decision ', decision, pathName);
423423
}
424424
},
425+
async (i: number, totalCount: number, pathName: string, decision: string, err?: any) => {
426+
if (err) {
427+
log.info('sync failed ', pathName, decision);
428+
view?.update(pathName, { syncStatus: 'fail' });
429+
view?.error(`${i}/${totalCount} - file ${pathName} sync failed`);
430+
return;
431+
}
432+
log.info('sync done ', pathName, decision);
433+
// TODO: Get remote link, but need remote domain first
434+
view?.update(pathName, { syncStatus: 'sync-done', remoteLink: '' });
435+
view?.info(`${i}/${totalCount} - file ${pathName} sync done`);
436+
},
425437
(key: string) => {
426438
log.warn('Remote files conflicts when syncing ... ', key);
427439
view?.warn(`Remote file ${key} conflicts when syncing ...`);

src/sync.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,7 @@ export const doActualSync = async (
14541454
concurrency: number = 1,
14551455
callbackSizesGoWrong?: any,
14561456
callbackSyncProcess?: any,
1457+
callbackSyncDone?: any,
14571458
callbackConflictSync?: any
14581459
) => {
14591460
const mixedStates = syncPlan.mixedStates;
@@ -1572,8 +1573,30 @@ export const doActualSync = async (
15721573
vault,
15731574
localDeleteFunc,
15741575
password
1575-
);
1576+
).catch((err) => {
1577+
if (callbackSyncDone !== undefined) {
1578+
callbackSyncDone(
1579+
realCounter,
1580+
realTotalCount,
1581+
key,
1582+
val.decision,
1583+
err
1584+
);
1585+
1586+
realCounter += 1;
1587+
}
1588+
throw err;
1589+
})
1590+
if (callbackSyncDone !== undefined) {
1591+
await callbackSyncDone(
1592+
realCounter,
1593+
realTotalCount,
1594+
key,
1595+
val.decision
1596+
);
15761597

1598+
realCounter += 1;
1599+
}
15771600
log.debug(`finished ${key}`);
15781601
};
15791602

src/touchedPlanModel.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,19 @@ export class TouchedPlanModel extends Modal {
2828
[ ...Object.keys(files) ].forEach(key => {
2929
const f = files[key];
3030
if ((f.decision === 'uploadLocalDelHistToRemote') && f.existRemote) {
31+
f.syncType = 'TOREMOTE';
3132
toRemoteFiles.push(f);
3233
}
3334
if (f.decision === 'uploadLocalToRemote') {
35+
f.syncType = 'TOREMOTE';
3436
toRemoteFiles.push(f);
3537
}
3638
if (f.decision === 'downloadRemoteToLocal') {
39+
f.syncType = 'TOLOCAL';
3740
toLocalFiles.push(f);
3841
}
3942
if ((f.decision === 'keepRemoteDelHist') && f.existLocal) {
43+
f.syncType = 'TOLOCAL';
4044
toLocalFiles.push(f);
4145
}
4246
if (f.remoteUnsync) {

0 commit comments

Comments
 (0)