1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const formidable = require("formidable");
|
4 | class Request {
|
5 | constructor(request) {
|
6 | this.request = request;
|
7 | }
|
8 | getBody() {
|
9 | return this.request.body;
|
10 | }
|
11 | getForm() {
|
12 | return new Promise((resolve, reject) => {
|
13 | let r = this.getRequestSource();
|
14 | let form = new formidable.IncomingForm();
|
15 | form.hash = 'md5';
|
16 | form.parse(r, (error, fields, files) => {
|
17 | if (error) {
|
18 | return reject(error);
|
19 | }
|
20 | return resolve({
|
21 | fields,
|
22 | files: files
|
23 | });
|
24 | });
|
25 | });
|
26 | }
|
27 | getHeaders() {
|
28 | return this.request.headers;
|
29 | }
|
30 | getHeader(name) {
|
31 | let value = this.request.headers[name.toLowerCase()];
|
32 | if (typeof value === 'string') {
|
33 | return value;
|
34 | }
|
35 | else {
|
36 | return value && value[0] ? value[0] : null;
|
37 | }
|
38 | }
|
39 | getQueryVariables() {
|
40 | return this.request.query;
|
41 | }
|
42 | getParams() {
|
43 | return this.request.params;
|
44 | }
|
45 | getParam(name) {
|
46 | return this.request.params[name];
|
47 | }
|
48 | getIP() {
|
49 | return this.request.ip;
|
50 | }
|
51 | getForwardedIP() {
|
52 | return this.getHeader('X-Forwarded-FOR');
|
53 | }
|
54 | getHostname() {
|
55 | return this.request.hostname;
|
56 | }
|
57 | getMethod() {
|
58 | return this.request.method;
|
59 | }
|
60 | getURL() {
|
61 | return this.request.originalUrl;
|
62 | }
|
63 | isSecure() {
|
64 | return this.request.secure;
|
65 | }
|
66 | pipe(destination) {
|
67 | return this.request.pipe(destination);
|
68 | }
|
69 | unpipe(source) {
|
70 | this.request.unpipe(source);
|
71 | }
|
72 | getRequestSource() {
|
73 | return this.request;
|
74 | }
|
75 | }
|
76 | exports.Request = Request;
|
77 |
|
\ | No newline at end of file |