diff --git a/api/function/controllers/function.js b/api/function/controllers/function.js index 7d7324f..481d237 100644 --- a/api/function/controllers/function.js +++ b/api/function/controllers/function.js @@ -12,19 +12,29 @@ module.exports = { const { name } = ctx.params; const entity = await strapi.services.function.findOne({ name }); - let script = () => { - return new Promise((resolve, reject) => { - PythonShell.run( - "./public" + entity.script.url, - null, - function (err, results) { - if (err) throw err; - resolve(results); - } - ); + + if (entity) { + let args = []; + + entity.input.forEach((input) => { + args.push(ctx.request.query[input.name] || input.defaultValue || ""); }); - }; - let output = await script(); + + let script = () => { + return new Promise((resolve, reject) => { + PythonShell.run( + `./public${entity.script.url}`, + { args: [...args] }, + function (err, results) { + if (err) throw err; + resolve(results); + } + ); + }); + }; + let output = await script(); + return output; + } return entity; }, diff --git a/api/category/config/routes.json b/api/type/config/routes.json similarity index 56% rename from api/category/config/routes.json rename to api/type/config/routes.json index 930f4ac..1d8cc28 100644 --- a/api/category/config/routes.json +++ b/api/type/config/routes.json @@ -2,48 +2,48 @@ "routes": [ { "method": "GET", - "path": "/categories", - "handler": "category.find", + "path": "/types", + "handler": "type.find", "config": { "policies": [] } }, { "method": "GET", - "path": "/categories/count", - "handler": "category.count", + "path": "/types/count", + "handler": "type.count", "config": { "policies": [] } }, { "method": "GET", - "path": "/categories/:id", - "handler": "category.findOne", + "path": "/types/:id", + "handler": "type.findOne", "config": { "policies": [] } }, { "method": "POST", - "path": "/categories", - "handler": "category.create", + "path": "/types", + "handler": "type.create", "config": { "policies": [] } }, { "method": "PUT", - "path": "/categories/:id", - "handler": "category.update", + "path": "/types/:id", + "handler": "type.update", "config": { "policies": [] } }, { "method": "DELETE", - "path": "/categories/:id", - "handler": "category.delete", + "path": "/types/:id", + "handler": "type.delete", "config": { "policies": [] } diff --git a/api/category/controllers/category.js b/api/type/controllers/type.js similarity index 100% rename from api/category/controllers/category.js rename to api/type/controllers/type.js diff --git a/api/category/models/category.js b/api/type/models/type.js similarity index 100% rename from api/category/models/category.js rename to api/type/models/type.js diff --git a/api/category/models/category.settings.json b/api/type/models/type.settings.json similarity index 74% rename from api/category/models/category.settings.json rename to api/type/models/type.settings.json index b7fedc6..31ddff1 100644 --- a/api/category/models/category.settings.json +++ b/api/type/models/type.settings.json @@ -1,13 +1,13 @@ { "kind": "collectionType", - "collectionName": "categories", + "collectionName": "types", "info": { - "name": "category" + "name": "type" }, "options": { "increments": true, "timestamps": true, - "draftAndPublish": true + "draftAndPublish": false }, "pluginOptions": {}, "attributes": { diff --git a/api/category/services/category.js b/api/type/services/type.js similarity index 100% rename from api/category/services/category.js rename to api/type/services/type.js diff --git a/components/argument/input.json b/components/argument/input.json index 1387a5e..953b8a5 100644 --- a/components/argument/input.json +++ b/components/argument/input.json @@ -10,8 +10,11 @@ "name": { "type": "string" }, - "category": { - "model": "category" + "defaultValue": { + "type": "string" + }, + "type": { + "model": "type" } } }