apps: make uploadFile async

This commit is contained in:
Girish Ramakrishnan
2021-10-21 15:15:39 -07:00
parent fbaee89c7b
commit 2e3070a5c6
2 changed files with 15 additions and 20 deletions

View File

@@ -783,7 +783,7 @@ async function listBackups(req, res, next) {
next(new HttpSuccess(200, { backups: result }));
}
function uploadFile(req, res, next) {
async function uploadFile(req, res, next) {
assert.strictEqual(typeof req.app, 'object');
if (typeof req.query.file !== 'string' || !req.query.file) return next(new HttpError(400, 'file query argument must be provided'));
@@ -791,11 +791,11 @@ function uploadFile(req, res, next) {
req.clearTimeout();
apps.uploadFile(req.app, req.files.file.path, req.query.file, function (error) {
if (error) return next(BoxError.toHttpError(error));
const [error] = await safe(apps.uploadFile(req.app, req.files.file.path, req.query.file));
safe.fs.unlinkSync(req.files.file.path); // remove file in /tmp
next(new HttpSuccess(202, {}));
});
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(202, {}));
}
function downloadFile(req, res, next) {