1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | exports.lints = function lintResults(req, res) {
|
27 | const util = require("util");
|
28 |
|
29 | var customer,
|
30 | org,
|
31 | api,
|
32 | revision,
|
33 | authorization = req.get("Authorization"),
|
34 | formatter;
|
35 |
|
36 | if (req.method === "GET") {
|
37 | customer = req.query.customer;
|
38 | org = req.query.org;
|
39 | api = req.query.api;
|
40 | revision = req.query.revision;
|
41 | formatter = req.query.formatter;
|
42 | } else if (req.method === "POST") {
|
43 | customer = req.body.customer;
|
44 | org = req.body.organization;
|
45 | api = req.body.api;
|
46 | revision = req.body.revision;
|
47 | formatter = req.body.formatter;
|
48 | }
|
49 |
|
50 |
|
51 | if (!formatter) {
|
52 | if (req.accepts("json")) {
|
53 | formatter = "json.js";
|
54 | } else if (req.accepts("xml")) {
|
55 | formatter = "jslint-xml.js";
|
56 | } else if (req.accepts("text")) {
|
57 | formatter = "unix.js";
|
58 | } else {
|
59 | formatter = "html.js";
|
60 | }
|
61 | }
|
62 |
|
63 | if (!org && customer) {
|
64 |
|
65 |
|
66 | var str = '';
|
67 |
|
68 | var options = {
|
69 | host: 'nucleus-api-test.apigee.com',
|
70 | path: '/sfdc/account_orgs'
|
71 | };
|
72 |
|
73 | var callback = function(response) {
|
74 | response.on('data', function (chunk) {
|
75 | str += chunk;
|
76 | });
|
77 |
|
78 | response.on('end', function () {
|
79 | console.log(str);
|
80 |
|
81 | res.send(str);
|
82 | });
|
83 | }
|
84 |
|
85 | var req = http.request(options, callback);
|
86 | req.end();
|
87 |
|
88 | }else{
|
89 |
|
90 | }
|
91 |
|
92 | if (!org || !api || !revision || !req.get("Authorization")) {
|
93 |
|
94 | res
|
95 | .status(400)
|
96 | .send(
|
97 | "org(" +
|
98 | org +
|
99 | "), api(" +
|
100 | api +
|
101 | "), and revision(" +
|
102 | revision +
|
103 | ") are required parameters and authorization header is required"
|
104 | );
|
105 | } else {
|
106 |
|
107 |
|
108 | const configuration = {
|
109 | source: {
|
110 | type: "ManagementServer",
|
111 | org,
|
112 | api,
|
113 | revision,
|
114 | authorization
|
115 | },
|
116 | output: function(report) {
|
117 | if (req.query.debug) {
|
118 | console.log(report);
|
119 | }
|
120 | },
|
121 | apiUpload: {
|
122 | destPath: "https://csdata-test.apigee.net/v1/lintresults",
|
123 | authorization,
|
124 | organization: org
|
125 | },
|
126 | formatter
|
127 | };
|
128 |
|
129 | var bl = require("./lib/package/bundleLinter.js");
|
130 | bl.lint(configuration, function(result, err) {
|
131 | if (err) {
|
132 | console.log(util.inspect(err, { showHidden: false, depth: 3 }));
|
133 | res.status(err.status).send(err.message);
|
134 | } else {
|
135 | res.status(200).send(result.apiUploadResponse);
|
136 | }
|
137 | });
|
138 | }
|
139 | };
|