n8n-nodes-elearning-magic 0.1.15 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,7 +2,5 @@ import type { IWebhookFunctions, INodeTypeDescription, IWebhookResponseData } fr
|
|
|
2
2
|
import { Node } from 'n8n-workflow';
|
|
3
3
|
export declare class ElearningMagicTrigger extends Node {
|
|
4
4
|
description: INodeTypeDescription;
|
|
5
|
-
webhook(
|
|
6
|
-
private validateAuth;
|
|
7
|
-
private handleBinaryData;
|
|
5
|
+
webhook(this: IWebhookFunctions): Promise<IWebhookResponseData>;
|
|
8
6
|
}
|
|
@@ -10,6 +10,37 @@ const n8n_workflow_1 = require("n8n-workflow");
|
|
|
10
10
|
const description_1 = require("./description");
|
|
11
11
|
const error_1 = require("./error");
|
|
12
12
|
const utils_1 = require("./utils");
|
|
13
|
+
const handleBinaryData = async (context, prepareOutput) => {
|
|
14
|
+
var _a, _b, _c, _d;
|
|
15
|
+
const req = context.getRequestObject();
|
|
16
|
+
const options = context.getNodeParameter('options', {});
|
|
17
|
+
const binaryFile = await (0, tmp_promise_1.file)({ prefix: 'elearning-magic-webhook-' });
|
|
18
|
+
try {
|
|
19
|
+
await (0, promises_2.pipeline)(req, (0, fs_1.createWriteStream)(binaryFile.path));
|
|
20
|
+
const returnItem = {
|
|
21
|
+
json: {
|
|
22
|
+
headers: req.headers,
|
|
23
|
+
params: req.params,
|
|
24
|
+
query: req.query,
|
|
25
|
+
body: {},
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
const stats = await (0, promises_1.stat)(binaryFile.path);
|
|
29
|
+
if (stats.size) {
|
|
30
|
+
const binaryPropertyName = ((_a = options.binaryPropertyName) !== null && _a !== void 0 ? _a : 'data');
|
|
31
|
+
const fileName = (_c = (_b = req.contentDisposition) === null || _b === void 0 ? void 0 : _b.filename) !== null && _c !== void 0 ? _c : (0, uuid_1.v4)();
|
|
32
|
+
const binaryData = await context.nodeHelpers.copyBinaryFile(binaryFile.path, fileName, (_d = req.contentType) !== null && _d !== void 0 ? _d : 'application/octet-stream');
|
|
33
|
+
returnItem.binary = { [binaryPropertyName]: binaryData };
|
|
34
|
+
}
|
|
35
|
+
return { workflowData: prepareOutput(returnItem) };
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
throw new n8n_workflow_1.NodeOperationError(context.getNode(), error);
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
await binaryFile.cleanup();
|
|
42
|
+
}
|
|
43
|
+
};
|
|
13
44
|
class ElearningMagicTrigger extends n8n_workflow_1.Node {
|
|
14
45
|
constructor() {
|
|
15
46
|
super(...arguments);
|
|
@@ -51,15 +82,15 @@ class ElearningMagicTrigger extends n8n_workflow_1.Node {
|
|
|
51
82
|
],
|
|
52
83
|
};
|
|
53
84
|
}
|
|
54
|
-
async webhook(
|
|
55
|
-
const { typeVersion: nodeVersion } =
|
|
56
|
-
const options =
|
|
57
|
-
const req =
|
|
58
|
-
const resp =
|
|
85
|
+
async webhook() {
|
|
86
|
+
const { typeVersion: nodeVersion } = this.getNode();
|
|
87
|
+
const options = this.getNodeParameter('options', {});
|
|
88
|
+
const req = this.getRequestObject();
|
|
89
|
+
const resp = this.getResponseObject();
|
|
59
90
|
const requestMethod = req.method;
|
|
60
91
|
let validationData;
|
|
61
92
|
try {
|
|
62
|
-
validationData = await
|
|
93
|
+
validationData = await (0, utils_1.validateWebhookAuthentication)(this);
|
|
63
94
|
}
|
|
64
95
|
catch (error) {
|
|
65
96
|
if (error instanceof error_1.WebhookAuthorizationError) {
|
|
@@ -69,18 +100,18 @@ class ElearningMagicTrigger extends n8n_workflow_1.Node {
|
|
|
69
100
|
}
|
|
70
101
|
throw error;
|
|
71
102
|
}
|
|
72
|
-
const prepareOutput = (0, utils_1.setupOutputConnection)(
|
|
103
|
+
const prepareOutput = (0, utils_1.setupOutputConnection)(this, requestMethod, {
|
|
73
104
|
jwtPayload: validationData,
|
|
74
105
|
});
|
|
75
106
|
if (options.binaryData) {
|
|
76
|
-
return await
|
|
107
|
+
return await handleBinaryData(this, prepareOutput);
|
|
77
108
|
}
|
|
78
109
|
if (req.contentType === 'multipart/form-data') {
|
|
79
|
-
return await (0, utils_1.handleFormData)(
|
|
110
|
+
return await (0, utils_1.handleFormData)(this, prepareOutput);
|
|
80
111
|
}
|
|
81
112
|
if (nodeVersion > 1 && !req.body) {
|
|
82
113
|
try {
|
|
83
|
-
return await
|
|
114
|
+
return await handleBinaryData(this, prepareOutput);
|
|
84
115
|
}
|
|
85
116
|
catch (error) { }
|
|
86
117
|
}
|
|
@@ -98,39 +129,5 @@ class ElearningMagicTrigger extends n8n_workflow_1.Node {
|
|
|
98
129
|
workflowData: prepareOutput(response),
|
|
99
130
|
};
|
|
100
131
|
}
|
|
101
|
-
async validateAuth(context) {
|
|
102
|
-
return await (0, utils_1.validateWebhookAuthentication)(context);
|
|
103
|
-
}
|
|
104
|
-
async handleBinaryData(context, prepareOutput) {
|
|
105
|
-
var _a, _b, _c, _d;
|
|
106
|
-
const req = context.getRequestObject();
|
|
107
|
-
const options = context.getNodeParameter('options', {});
|
|
108
|
-
const binaryFile = await (0, tmp_promise_1.file)({ prefix: 'elearning-magic-webhook-' });
|
|
109
|
-
try {
|
|
110
|
-
await (0, promises_2.pipeline)(req, (0, fs_1.createWriteStream)(binaryFile.path));
|
|
111
|
-
const returnItem = {
|
|
112
|
-
json: {
|
|
113
|
-
headers: req.headers,
|
|
114
|
-
params: req.params,
|
|
115
|
-
query: req.query,
|
|
116
|
-
body: {},
|
|
117
|
-
},
|
|
118
|
-
};
|
|
119
|
-
const stats = await (0, promises_1.stat)(binaryFile.path);
|
|
120
|
-
if (stats.size) {
|
|
121
|
-
const binaryPropertyName = ((_a = options.binaryPropertyName) !== null && _a !== void 0 ? _a : 'data');
|
|
122
|
-
const fileName = (_c = (_b = req.contentDisposition) === null || _b === void 0 ? void 0 : _b.filename) !== null && _c !== void 0 ? _c : (0, uuid_1.v4)();
|
|
123
|
-
const binaryData = await context.nodeHelpers.copyBinaryFile(binaryFile.path, fileName, (_d = req.contentType) !== null && _d !== void 0 ? _d : 'application/octet-stream');
|
|
124
|
-
returnItem.binary = { [binaryPropertyName]: binaryData };
|
|
125
|
-
}
|
|
126
|
-
return { workflowData: prepareOutput(returnItem) };
|
|
127
|
-
}
|
|
128
|
-
catch (error) {
|
|
129
|
-
throw new n8n_workflow_1.NodeOperationError(context.getNode(), error);
|
|
130
|
-
}
|
|
131
|
-
finally {
|
|
132
|
-
await binaryFile.cleanup();
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
132
|
}
|
|
136
133
|
exports.ElearningMagicTrigger = ElearningMagicTrigger;
|