Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: File attachments have no content when exporting room messages as file #30596

Merged
merged 4 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lucky-vans-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixed issue with file attachments in rooms' messages export having no content
11 changes: 7 additions & 4 deletions apps/meteor/app/file-upload/server/config/AmazonS3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ const get: FileUploadClass['get'] = async function (this: FileUploadClass, file,

const copy: FileUploadClass['copy'] = async function (this: FileUploadClass, file, out) {
const fileUrl = await this.store.getRedirectURL(file);
if (fileUrl) {
const request = /^https:/.test(fileUrl) ? https : http;
request.get(fileUrl, (fileRes) => fileRes.pipe(out));
} else {
if (!fileUrl) {
out.end();
return;
}

const request = /^https:/.test(fileUrl) ? https : http;
return new Promise((resolve) => {
request.get(fileUrl, (fileRes) => fileRes.pipe(out).on('finish', () => resolve()));
});
};

const AmazonS3Uploads = new FileUploadClass({
Expand Down
11 changes: 7 additions & 4 deletions apps/meteor/app/file-upload/server/config/GoogleStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ const get: FileUploadClass['get'] = async function (this: FileUploadClass, file,
const copy: FileUploadClass['copy'] = async function (this: FileUploadClass, file, out) {
const fileUrl = await this.store.getRedirectURL(file, false);

if (fileUrl) {
const request = /^https:/.test(fileUrl) ? https : http;
request.get(fileUrl, (fileRes) => fileRes.pipe(out));
} else {
if (!fileUrl) {
out.end();
return;
}

const request = /^https:/.test(fileUrl) ? https : http;
return new Promise((resolve) => {
request.get(fileUrl, (fileRes) => fileRes.pipe(out).on('finish', () => resolve()));
});
};

const GoogleCloudStorageUploads = new FileUploadClass({
Expand Down
4 changes: 3 additions & 1 deletion apps/meteor/app/file-upload/server/config/Webdav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ const get: FileUploadClass['get'] = async function (this: FileUploadClass, file,
};

const copy: FileUploadClass['copy'] = async function (this: FileUploadClass, file, out) {
(await this.store.getReadStream(file._id, file)).pipe(out);
return new Promise(async (resolve) => {
(await this.store.getReadStream(file._id, file)).pipe(out).on('finish', () => resolve());
});
};

const WebdavUploads = new FileUploadClass({
Expand Down
4 changes: 3 additions & 1 deletion apps/meteor/server/lib/dataExport/sendFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ export const sendFile = async (data: ExportFile, user: IUser): Promise<void> =>

await exportMessages();

const promises: Promise<void>[] = [];
for await (const attachmentData of fullFileList) {
await copyFileUpload(attachmentData, assetsPath);
promises.push(copyFileUpload(attachmentData, assetsPath));
}
await Promise.all(promises);

const exportFile = `${baseDir}-export.zip`;
await makeZipFile(exportPath, exportFile);
Expand Down
Loading