1 | "use strict";
|
2 | var __extends = (this && this.__extends) || function (d, b) {
|
3 | for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
4 | function __() { this.constructor = d; }
|
5 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
6 | };
|
7 | var job_1 = require("./job");
|
8 | var fileJob_1 = require("./fileJob");
|
9 | var fs = require("fs"), tmp = require("tmp"), url = require("url"), path = require("path"), _ = require("lodash");
|
10 |
|
11 |
|
12 |
|
13 | var WebhookJob = (function (_super) {
|
14 | __extends(WebhookJob, _super);
|
15 | |
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | function WebhookJob(e, request, response) {
|
22 | _super.call(this, e, "Webhook Job");
|
23 | this.request = request;
|
24 | this.response = response;
|
25 | this._responseSent = false;
|
26 | }
|
27 | Object.defineProperty(WebhookJob.prototype, "responseSent", {
|
28 | |
29 |
|
30 |
|
31 |
|
32 | get: function () {
|
33 | return this._responseSent;
|
34 | },
|
35 | |
36 |
|
37 |
|
38 |
|
39 | set: function (sent) {
|
40 | this._responseSent = sent;
|
41 | },
|
42 | enumerable: true,
|
43 | configurable: true
|
44 | });
|
45 | |
46 |
|
47 |
|
48 |
|
49 | WebhookJob.prototype.getResponse = function () {
|
50 | return this.response;
|
51 | };
|
52 | |
53 |
|
54 |
|
55 |
|
56 | WebhookJob.prototype.getRequest = function () {
|
57 | return this.request;
|
58 | };
|
59 | |
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 | WebhookJob.prototype.getQueryStringValue = function (parameter) {
|
71 | var wh = this;
|
72 | var url_parts = url.parse(wh.getRequest().url, true);
|
73 | return url_parts.query[parameter];
|
74 | };
|
75 | |
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 | WebhookJob.prototype.getQueryStringValues = function () {
|
86 | var wh = this;
|
87 | var url_parts = url.parse(wh.getRequest().url, true);
|
88 | return url_parts.query;
|
89 | };
|
90 | |
91 |
|
92 |
|
93 |
|
94 | WebhookJob.prototype.getFormDataFiles = function () {
|
95 | var wh = this;
|
96 | var files = wh.getRequest().files;
|
97 | var jobs = [];
|
98 | if (files) {
|
99 | files.forEach(function (file) {
|
100 | var job = new fileJob_1.FileJob(wh.e, file.path);
|
101 | job.rename(file.originalname);
|
102 | jobs.push(job);
|
103 | });
|
104 | }
|
105 | return jobs;
|
106 | };
|
107 | |
108 |
|
109 |
|
110 |
|
111 | WebhookJob.prototype.getFormDataValues = function () {
|
112 | var wh = this;
|
113 | var body = wh.getRequest().body;
|
114 | return body;
|
115 | };
|
116 | |
117 |
|
118 |
|
119 |
|
120 |
|
121 | WebhookJob.prototype.getFormDataValue = function (key) {
|
122 | var wh = this;
|
123 | var formData = wh.getFormDataValues();
|
124 | if (formData && key in formData) {
|
125 | return formData[key];
|
126 | }
|
127 | else {
|
128 | return false;
|
129 | }
|
130 | };
|
131 | |
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 | WebhookJob.prototype.getDataAsString = function (callback) {
|
143 | var wh = this;
|
144 | var req = wh.getRequest();
|
145 | var data = "";
|
146 | req.on("data", function (chunk) {
|
147 | data += chunk;
|
148 | });
|
149 | req.on("end", function () {
|
150 | callback(data);
|
151 | });
|
152 | };
|
153 | |
154 |
|
155 |
|
156 | WebhookJob.prototype.getParameters = function () {
|
157 | var wh = this;
|
158 | return _.merge(wh.getQueryStringValues(), wh.getFormDataValues());
|
159 | };
|
160 | |
161 |
|
162 |
|
163 |
|
164 |
|
165 | WebhookJob.prototype.getParameter = function (key) {
|
166 | var wh = this;
|
167 | if (_.has(wh.getParameters(), key)) {
|
168 | return wh.getParameters()[key];
|
169 | }
|
170 | else {
|
171 | return false;
|
172 | }
|
173 | };
|
174 | return WebhookJob;
|
175 | }(job_1.Job));
|
176 | exports.WebhookJob = WebhookJob;
|