python function cms

master
km0 3 years ago
parent faf4107eee
commit 2d55f7ce34

@ -12,19 +12,29 @@ 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 });
let script = () => {
return new Promise((resolve, reject) => { if (entity) {
PythonShell.run( let args = [];
"./public" + entity.script.url,
null, entity.input.forEach((input) => {
function (err, results) { args.push(ctx.request.query[input.name] || input.defaultValue || "");
if (err) throw err;
resolve(results);
}
);
}); });
};
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; 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