python function cms

master
km0 3 years ago
parent faf4107eee
commit 2d55f7ce34

@ -12,11 +12,19 @@ module.exports = {
const { name } = ctx.params; const { name } = ctx.params;
const entity = await strapi.services.function.findOne({ name }); const entity = await strapi.services.function.findOne({ name });
if (entity) {
let args = [];
entity.input.forEach((input) => {
args.push(ctx.request.query[input.name] || input.defaultValue || "");
});
let script = () => { let script = () => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
PythonShell.run( PythonShell.run(
"./public" + entity.script.url, `./public${entity.script.url}`,
null, { args: [...args] },
function (err, results) { function (err, results) {
if (err) throw err; if (err) throw err;
resolve(results); resolve(results);
@ -25,6 +33,8 @@ module.exports = {
}); });
}; };
let output = await script(); let output = await script();
return output;
}
return entity; return entity;
}, },

@ -2,48 +2,48 @@
"routes": [ "routes": [
{ {
"method": "GET", "method": "GET",
"path": "/categories", "path": "/types",
"handler": "category.find", "handler": "type.find",
"config": { "config": {
"policies": [] "policies": []
} }
}, },
{ {
"method": "GET", "method": "GET",
"path": "/categories/count", "path": "/types/count",
"handler": "category.count", "handler": "type.count",
"config": { "config": {
"policies": [] "policies": []
} }
}, },
{ {
"method": "GET", "method": "GET",
"path": "/categories/:id", "path": "/types/:id",
"handler": "category.findOne", "handler": "type.findOne",
"config": { "config": {
"policies": [] "policies": []
} }
}, },
{ {
"method": "POST", "method": "POST",
"path": "/categories", "path": "/types",
"handler": "category.create", "handler": "type.create",
"config": { "config": {
"policies": [] "policies": []
} }
}, },
{ {
"method": "PUT", "method": "PUT",
"path": "/categories/:id", "path": "/types/:id",
"handler": "category.update", "handler": "type.update",
"config": { "config": {
"policies": [] "policies": []
} }
}, },
{ {
"method": "DELETE", "method": "DELETE",
"path": "/categories/:id", "path": "/types/:id",
"handler": "category.delete", "handler": "type.delete",
"config": { "config": {
"policies": [] "policies": []
} }

@ -1,13 +1,13 @@
{ {
"kind": "collectionType", "kind": "collectionType",
"collectionName": "categories", "collectionName": "types",
"info": { "info": {
"name": "category" "name": "type"
}, },
"options": { "options": {
"increments": true, "increments": true,
"timestamps": true, "timestamps": true,
"draftAndPublish": true "draftAndPublish": false
}, },
"pluginOptions": {}, "pluginOptions": {},
"attributes": { "attributes": {

@ -10,8 +10,11 @@
"name": { "name": {
"type": "string" "type": "string"
}, },
"category": { "defaultValue": {
"model": "category" "type": "string"
},
"type": {
"model": "type"
} }
} }
} }

Loading…
Cancel
Save