Migrate backend to n8n

This commit is contained in:
Sandra
2022-05-17 10:09:36 +02:00
parent 270467d686
commit 94f50deda1
21 changed files with 143 additions and 642 deletions

View File

@@ -0,0 +1,59 @@
{
"name": "timings.okaeri.cloud/v1/parse",
"nodes": [
{
"parameters": {},
"name": "Start",
"type": "n8n-nodes-base.start",
"typeVersion": 1,
"position": [
240,
300
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "timings-api.okaeri.cloud/v1/parse",
"responseMode": "lastNode",
"options": {}
},
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 1,
"position": [
740,
320
],
"webhookId": "a63ac908-a85d-4581-adbf-a58ad5c05ed4"
},
{
"parameters": {
"functionCode": "const parseReport = (text) => {\n\n const start = new Date();\n const lines = text.split(/\\r?\\n/);\n\n const metadata = {};\n let header = null;\n const records = [];\n\n for (const line of lines) {\n\n // empty\n if (!line) {\n continue\n }\n\n // metadata\n if (line.startsWith(\"#\")) {\n if (!line.includes(\":\")) {\n continue;\n }\n const parts = line.substring(1).split(\":\", 2);\n if (parts.length !== 2) {\n return {error: `Invalid metadata: '${line}'`};\n }\n const key = parts[0].trim().toLowerCase();\n metadata[key] = parts[1].trim();\n continue;\n }\n\n // header\n if (header === null) {\n const parts = line.split(\",\");\n if (parts.length < 2) {\n return {error: `Invalid header: '${line}'`};\n }\n header = parts;\n continue;\n }\n\n // data\n const parts = line.split(\",\");\n if (parts.length !== header.length) {\n return {error: `Invalid record: '${line}'`};\n }\n\n records.push(parts.map(value => {\n const floatValue = parseFloat(value);\n if (Number.isNaN(floatValue)) {\n return {error: `Invalid number '${value}' in: '${line}'`}\n }\n return floatValue;\n }));\n }\n\n if (header === null || records.length < 2) {\n return {error: \"Invalid report\"};\n }\n\n return {\n meta: metadata,\n header: header,\n data: records,\n stats: {\n parseTime: `PT${((new Date() - start) / 1000)}S`\n }\n }\n};\n\nif (items.length === 0) {\n items[0].json = {error: \"No report file found in the request.\"};\n} else if (items.length > 1) {\n items[0].json = {error: \"More than one file found in the request.\"}\n} else {\n const data = items[0].binary.file.data;\n const text = Buffer.from(data, \"base64\").toString(\"utf8\");\n items[0].json = parseReport(text)\n}\n\nreturn items;\n"
},
"name": "Function",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
960,
320
]
}
],
"connections": {
"Webhook": {
"main": [
[
{
"node": "Function",
"type": "main",
"index": 0
}
]
]
}
},
"active": true,
"settings": {},
"id": 1
}