fix: Refactor attachment downloads during export to use promises (#5294
* Refactor attachment downloads during export to use promises instead of streams Date attachments in zip file correctly * tsc
This commit is contained in:
@@ -3,6 +3,7 @@ import path from "path";
|
||||
import JSZip from "jszip";
|
||||
import { find } from "lodash";
|
||||
import tmp from "tmp";
|
||||
import { bytesToHumanReadable } from "@shared/utils/files";
|
||||
import { ValidationError } from "@server/errors";
|
||||
import Logger from "@server/logging/Logger";
|
||||
import { trace } from "@server/logging/tracing";
|
||||
@@ -114,10 +115,14 @@ export default class ZipHelper {
|
||||
currentFile: metadata.currentFile,
|
||||
percent,
|
||||
};
|
||||
const memory = process.memoryUsage();
|
||||
Logger.debug(
|
||||
"utils",
|
||||
`Writing zip file progress… %${percent}`,
|
||||
{ currentFile: metadata.currentFile }
|
||||
`Writing zip file progress… ${percent}%`,
|
||||
{
|
||||
currentFile: metadata.currentFile,
|
||||
memory: bytesToHumanReadable(memory.rss),
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,19 +184,34 @@ export const getAWSKeyForFileOp = (teamId: string, name: string) => {
|
||||
return `${bucket}/${teamId}/${uuidv4()}/${name}-export.zip`;
|
||||
};
|
||||
|
||||
export const getFileByKey = (key: string) => {
|
||||
const params = {
|
||||
Bucket: AWS_S3_UPLOAD_BUCKET_NAME,
|
||||
Key: key,
|
||||
};
|
||||
|
||||
export const getFileStream = (key: string) => {
|
||||
try {
|
||||
return s3.getObject(params).createReadStream();
|
||||
return s3
|
||||
.getObject({
|
||||
Bucket: AWS_S3_UPLOAD_BUCKET_NAME,
|
||||
Key: key,
|
||||
})
|
||||
.createReadStream();
|
||||
} catch (err) {
|
||||
Logger.error("Error getting file from S3 by key", err, {
|
||||
Logger.error("Error getting file stream from S3 ", err, {
|
||||
key,
|
||||
});
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
export const getFileBuffer = async (key: string) => {
|
||||
const response = await s3
|
||||
.getObject({
|
||||
Bucket: AWS_S3_UPLOAD_BUCKET_NAME,
|
||||
Key: key,
|
||||
})
|
||||
.promise();
|
||||
|
||||
if (response.Body) {
|
||||
return response.Body as Blob;
|
||||
}
|
||||
|
||||
throw new Error("Error getting file buffer from S3");
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user