Skip to content

Commit 6a06d88

Browse files
committed
feat(RenderLog): Show exporting and uploading progress.
1 parent 523d085 commit 6a06d88

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/exporter.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,11 @@ export const publishFiles = async (
100100
}
101101
}
102102
await HTMLGenerator.beginBatch(allFiles);
103+
RenderLog.progress(0, allFiles.length, "Exporting Docs", "...", "var(--color-accent)");
103104
let externalFiles: Downloadable[] = [];
104105
let toUploads: any[] = [];
105106

107+
let i = 0;
106108
for (const path of pathList) {
107109
const file = vault.getAbstractFileByPath(path);
108110
if (!(file instanceof TFile)) {
@@ -111,7 +113,7 @@ export const publishFiles = async (
111113
}
112114
log.info('html path: ', htmlPath, file);
113115
const htmlFilePath = htmlPath.joinString(file.name).setExtension("html");
114-
116+
RenderLog.progress(i++, path.length, "Exporting Docs", "Exporting: " + file.path, "var(--color-accent)");
115117
const exportedFile = await exportFile(file, new Path(path), true, htmlFilePath, new Path(settings.localWatchDir));
116118
if (exportedFile) {
117119
toUploads.push(...exportedFile.downloads.map(d => {
@@ -129,16 +131,19 @@ export const publishFiles = async (
129131
externalFiles.push(...exportedFile.downloads);
130132
}
131133
}
134+
135+
132136

133137
externalFiles = externalFiles.filter((file, index) => externalFiles.findIndex((f) => f.relativeDownloadPath == file.relativeDownloadPath && f.filename === file.filename) == index);
134138
await Utils.downloadFiles(externalFiles, htmlPath);
135139
log.info('download files to: ', htmlPath, externalFiles);
136-
HTMLGenerator.endBatch();
137140

138141
await sleep(200);
139142

140143
try {
141-
const resPromise = toUploads.map(upload => {
144+
RenderLog.progress(0, toUploads.length, "Uploading Docs", "...", "var(--color-accent)");
145+
146+
const resPromise = toUploads.map((upload, i) => {
142147
const htmlFileRelPath = Path.getRelativePathFromVault(new Path(upload.path), true).asString;
143148
log.info('rel path: ', htmlFileRelPath);
144149
return client.uploadToRemote(
@@ -152,11 +157,17 @@ export const publishFiles = async (
152157
false,
153158
'',
154159
upload.key
155-
);
160+
).then((resp) => {
161+
RenderLog.progress(i++, toUploads.length, "Uploading Docs", "Upload success: " + upload.key, "var(--color-accent)");
162+
return resp;
163+
})
156164
})
157165

158166
await Promise.all(resPromise).then(result => {
159167
log.info('upload to remote result: ', result);
168+
RenderLog.progress(toUploads.length, toUploads.length, "Uploading Docs", "Uploading Done: ", "var(--color-accent)");
169+
HTMLGenerator.endBatch();
170+
160171
const bucket = settings.s3.s3BucketName;
161172
const urls = result.map(record => `https://${bucket}.${settings.s3.s3Endpoint}/${record?.key}`)
162173
log.info('url list: ', urls);
@@ -171,6 +182,7 @@ export const publishFiles = async (
171182
})
172183
} catch (error) {
173184
log.error('exception: ', error);
185+
HTMLGenerator.endBatch();
174186
}
175187

176188

0 commit comments

Comments
 (0)