Skip to content

Commit

Permalink
fix: remove required property file
Browse files Browse the repository at this point in the history
  • Loading branch information
himito committed Nov 23, 2020
1 parent 93596c3 commit 739923c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
9 changes: 7 additions & 2 deletions libs/imitator.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ function runImitator(model, property, options, outputFolder, socket) {
const modelName = path.basename(model, path.extname(model));
const outputPrefix = path.join(outputFolder, modelName);

const propertyOptional = property ? [property] : [];

// imitator execution
const imitator = spawn(command, [
...extraArguments,
model,
property,
...propertyOptional,
'-output-prefix',
outputPrefix,
...options,
Expand Down Expand Up @@ -96,7 +98,10 @@ function runImitator(model, property, options, outputFolder, socket) {

// files generated by imitator
const files = await glob(`${outputPrefix}*.!(zip)`);
files.push(property);

if (property) {
files.push(property);
}

socket.emit('imitator_output', modelName, 'files', {
path: path.basename(outputFolder),
Expand Down
31 changes: 21 additions & 10 deletions routes/imitator.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,30 @@ router.post('/run', upload, async (req, res) => {
// @ts-ignore
const models = req.files.models;

// @ts-ignore
const property = req.files.property[0];

// check required fields
if (models.length === 0 || !property) {
throw new Error('Model and property fields are required');
if (models.length === 0) {
throw new Error('Model field is required');
}

// root folder where the outputs will be stored
const destination = models[0].destination;

// identifier of the run
const identifier = uuidv4();
const outputFolder = path.join(property.destination, identifier);
const outputFolder = path.join(destination, identifier);
debug('output folder: ', outputFolder);

const propertyPath = await utils.moveToFolder(outputFolder, [property]);
debug('property file: ', propertyPath[0]);
// @ts-ignore
const property = req.files.property && req.files.property[0];
debug('property: ', property);

let propertyPath = null;

// @ts-ignore
if (property) {
propertyPath = (await utils.moveToFolder(outputFolder, [property]))[0];
debug('property file: ', propertyPath);
}

const modelsPath = await utils.moveToFolder(outputFolder, models);
debug('model paths: ', modelsPath);
Expand All @@ -132,7 +141,7 @@ router.post('/run', upload, async (req, res) => {
// run all the experiments asynchronously
const outputs = await Promise.all(
modelsPath.map((m) =>
runImitator(m, propertyPath[0], options, outputFolder, io)
runImitator(m, propertyPath, options, outputFolder, io)
)
);
debug('imitator outputs: ', outputs);
Expand All @@ -142,9 +151,11 @@ router.post('/run', upload, async (req, res) => {
identifier,
outputs,
models: models.map((m) => m.originalname),
property: property.originalname,
property: property && property.originalname,
};

debug('result: ', result);

res.json({ result });
} catch (error) {
res.status(400).json({ error: error.message });
Expand Down
2 changes: 1 addition & 1 deletion views/partials/submit-form.pug
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ div(class="card w-3/4 m-auto col-span-2")

div(class="mb-4")
label(for="property", class="label") Property
input(name="property", type="file", id="property", placeholder="~/my-property.imiprop", accept=".imiprop", required, class="input w-full")
input(name="property", type="file", id="property", placeholder="~/my-property.imiprop", accept=".imiprop", class="input w-full")

div(class="mb-4")
label(for="options", class="label") Options
Expand Down

1 comment on commit 739923c

@himito
Copy link
Contributor Author

@himito himito commented on 739923c May 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix #1

Please sign in to comment.