Skip to content
Snippets Groups Projects
Unverified Commit dce6d452 authored by Rodrigo Nascimento's avatar Rodrigo Nascimento Committed by GitHub
Browse files

refactor: Remove Promise.await from importer-pendind-file.js (#28812)

parent 1746e49c
No related branches found
No related tags found
No related merge requests found
...@@ -69,8 +69,8 @@ export class PendingFileImporter extends Base { ...@@ -69,8 +69,8 @@ export class PendingFileImporter extends Base {
})(); })();
}; };
const completeFile = (details) => { const completeFile = async (details) => {
Promise.await(this.addCountCompleted(1)); await this.addCountCompleted(1);
count--; count--;
currentSize -= details.size; currentSize -= details.size;
}; };
...@@ -132,54 +132,48 @@ export class PendingFileImporter extends Base { ...@@ -132,54 +132,48 @@ export class PendingFileImporter extends Base {
reportProgress(); reportProgress();
}), }),
); );
res.on( res.on('error', async (error) => {
'error', await completeFile(details);
Meteor.bindEnvironment((error) => { logError(error);
completeFile(details); });
logError(error);
}), res.on('end', async () => {
); try {
// Bypass the fileStore filters
const file = await fileStore._doInsert(details, Buffer.concat(rawData));
const url = FileUpload.getPath(`${file._id}/${encodeURI(file.name)}`);
const attachment = {
title: file.name,
title_link: url,
};
if (/^image\/.+/.test(file.type)) {
attachment.image_url = url;
attachment.image_type = file.type;
attachment.image_size = file.size;
attachment.image_dimensions = file.identify != null ? file.identify.size : undefined;
}
res.on( if (/^audio\/.+/.test(file.type)) {
'end', attachment.audio_url = url;
Meteor.bindEnvironment(async () => { attachment.audio_type = file.type;
try { attachment.audio_size = file.size;
// Bypass the fileStore filters
const file = await fileStore._doInsert(details, Buffer.concat(rawData));
const url = FileUpload.getPath(`${file._id}/${encodeURI(file.name)}`);
const attachment = {
title: file.name,
title_link: url,
};
if (/^image\/.+/.test(file.type)) {
attachment.image_url = url;
attachment.image_type = file.type;
attachment.image_size = file.size;
attachment.image_dimensions = file.identify != null ? file.identify.size : undefined;
}
if (/^audio\/.+/.test(file.type)) {
attachment.audio_url = url;
attachment.audio_type = file.type;
attachment.audio_size = file.size;
}
if (/^video\/.+/.test(file.type)) {
attachment.video_url = url;
attachment.video_type = file.type;
attachment.video_size = file.size;
}
Promise.await(Messages.setImportFileRocketChatAttachment(_importFile.id, url, attachment));
completeFile(details);
} catch (error) {
completeFile(details);
logError(error);
} }
}),
); if (/^video\/.+/.test(file.type)) {
attachment.video_url = url;
attachment.video_type = file.type;
attachment.video_size = file.size;
}
await Messages.setImportFileRocketChatAttachment(_importFile.id, url, attachment);
await completeFile(details);
} catch (error) {
await completeFile(details);
logError(error);
}
});
}), }),
); );
} catch (error) { } catch (error) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment