Add additional debug logging to export

This commit is contained in:
Tom Moor
2023-04-29 22:05:52 -04:00
parent ba2bfc7c89
commit 12bfa6c58d
2 changed files with 55 additions and 12 deletions

View File

@@ -4,6 +4,7 @@ import JSZip from "jszip";
import { find } from "lodash";
import tmp from "tmp";
import { ValidationError } from "@server/errors";
import Logger from "@server/logging/Logger";
import { trace } from "@server/logging/tracing";
import { deserializeFilename } from "./fs";
@@ -83,6 +84,7 @@ export default class ZipHelper {
* @returns pathname of the temporary file where the zip was written to disk
*/
public static async toTmpFile(zip: JSZip): Promise<string> {
Logger.debug("utils", "Creating tmp file…");
return new Promise((resolve, reject) => {
tmp.file(
{
@@ -93,13 +95,38 @@ export default class ZipHelper {
if (err) {
return reject(err);
}
let previousMetadata: JSZip.JSZipMetadata = {
percent: 0,
currentFile: null,
};
zip
.generateNodeStream({
type: "nodebuffer",
streamFiles: true,
})
.generateNodeStream(
{
type: "nodebuffer",
streamFiles: true,
},
(metadata) => {
const percent = Math.round(metadata.percent);
if (percent !== previousMetadata.percent) {
previousMetadata = {
currentFile: metadata.currentFile,
percent,
};
Logger.debug(
"utils",
`Writing zip file progress… %${percent}`,
{ currentFile: metadata.currentFile }
);
}
}
)
.pipe(fs.createWriteStream(path))
.on("finish", () => resolve(path))
.on("finish", () => {
Logger.debug("utils", "Writing zip complete", { path });
return resolve(path);
})
.on("error", reject);
}
);