python function cms

master
km0 3 years ago
parent faf4107eee
commit 2d55f7ce34

@ -12,11 +12,19 @@ module.exports = {
const { name } = ctx.params;
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 = () => {
return new Promise((resolve, reject) => {
PythonShell.run(
"./public" + entity.script.url,
null,
`./public${entity.script.url}`,
{ args: [...args] },
function (err, results) {
if (err) throw err;
resolve(results);
@ -25,6 +33,8 @@ module.exports = {
});
};
let output = await script();
return output;
}
return entity;
},

@ -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": []
}

@ -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": {

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

Loading…
Cancel
Save