From 4a641579e112130489a3fa6d4e284c344b652b4e Mon Sep 17 00:00:00 2001 From: NotTimTam Date: Thu, 12 Sep 2024 18:32:43 -0700 Subject: [PATCH] Bugfix. --- controllers/convert.js | 33 +++++++++++++++++---------------- package.json | 2 +- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/controllers/convert.js b/controllers/convert.js index 6699daf..329071f 100644 --- a/controllers/convert.js +++ b/controllers/convert.js @@ -88,20 +88,21 @@ export const convert = async (req, res) => { const parsedOptions = options && JSON.parse(options); - for (const { label, required } of moduleObject.options) { - // If a value is required, but none is provided - if ( - required && - (!parsedOptions.hasOwnProperty(label) || - parsedOptions[label] === undefined || - parsedOptions[label] === null) - ) - return res - .status(400) - .send( - `The "${moduleObject.label}" module requires a value for the option "${label}", but none was provided.` - ); - } + if (moduleObject.options) + for (const { label, required } of moduleObject.options) { + // If a value is required, but none is provided + if ( + required && + (!parsedOptions.hasOwnProperty(label) || + parsedOptions[label] === undefined || + parsedOptions[label] === null) + ) + return res + .status(400) + .send( + `The "${moduleObject.label}" module requires a value for the option "${label}", but none was provided.` + ); + } if (parsedOptions) { for (const [option, value] of Object.entries(parsedOptions)) { @@ -138,9 +139,9 @@ export const convert = async (req, res) => { const job = fileConverter.createJob(files, moduleObject, parsedOptions); - job.run(); // Start the job asynchronously without awaiting it. + res.status(200).send({ jobId: job._id }); - return res.status(200).send({ jobId: job._id }); + job.run(); // Start the job asynchronously without awaiting it. } catch (err) { return await unlinkAndGo(req.files, () => handleError(res, err)); } diff --git a/package.json b/package.json index f32e3b0..ac528f7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nottimtam/file-converter", - "version": "1.2.5", + "version": "1.2.6", "description": "A headless, self-hostable, open-source file conversion express middleware.", "main": "index.js", "type": "module",