cloudcms-server 3.2.296 → 3.2.298
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.
- package/duster/helpers/sample/nyt.js +6 -7
- package/framework/controllers.js +0 -1
- package/index.js +8 -0
- package/insight/insight.js +1 -4
- package/middleware/admin/admin.js +1 -1
- package/middleware/awareness/plugins/editorial.js +5 -15
- package/middleware/driver-config/driver-config.js +0 -6
- package/middleware/form/form.js +15 -30
- package/middleware/stores/store.js +0 -3
- package/middleware/virtual-config/virtual-config.js +8 -8
- package/middleware/virtual-files/virtual-files.js +0 -3
- package/middleware/welcome/welcome.js +0 -3
- package/package.json +5 -6
- package/util/auth.js +7 -18
- package/util/cloudcms.js +54 -60
- package/util/proxy-factory.js +1 -4
- package/util/renditions.js +10 -10
- package/util/request.js +135 -0
- package/util/util.js +12 -18
- package/d1/index.js +0 -629
- package/d1/index.js.works +0 -203
- package/d1/package.json +0 -86
- package/d1/package.json.works +0 -14
- package/util/proxy-factory.http2-proxy.js +0 -281
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
var request = require("../../../util/request");
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Sample New York Times Events tag for Dust.
|
|
3
5
|
*
|
|
@@ -49,7 +51,6 @@ exports = module.exports = function(app, dust, callback)
|
|
|
49
51
|
return map(chunk, function(chunk) {
|
|
50
52
|
setTimeout(function() {
|
|
51
53
|
|
|
52
|
-
var request = require("request");
|
|
53
54
|
var API_KEY = "3d8d573ec0ae966ea57245357cfcf57f:1:70698955";
|
|
54
55
|
|
|
55
56
|
var url = "http://api.nytimes.com/svc/events/v2/listings.json?api-key=" + API_KEY;
|
|
@@ -77,17 +78,16 @@ exports = module.exports = function(app, dust, callback)
|
|
|
77
78
|
|
|
78
79
|
//console.log("URL:" + url);
|
|
79
80
|
|
|
80
|
-
|
|
81
|
-
request(url, function (error, response, body) {
|
|
81
|
+
request(url, function (error, response, json) {
|
|
82
82
|
|
|
83
|
-
if (error || response.
|
|
83
|
+
if (error || response.status !== 200)
|
|
84
84
|
{
|
|
85
85
|
if (error) {
|
|
86
86
|
console.log("ERROR: " + error);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
if (response.
|
|
90
|
-
console.log("STATUS CODE: " + response.
|
|
89
|
+
if (response.status !== 200) {
|
|
90
|
+
console.log("STATUS CODE: " + response.status);
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
chunk.write("There was an error loading this section");
|
|
@@ -96,7 +96,6 @@ exports = module.exports = function(app, dust, callback)
|
|
|
96
96
|
return;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
var json = JSON.parse(body);
|
|
100
99
|
console.log("BODY: " + JSON.stringify(json, null, " "));
|
|
101
100
|
|
|
102
101
|
var resultObject = {
|
package/framework/controllers.js
CHANGED
package/index.js
CHANGED
|
@@ -75,6 +75,14 @@ https.globalAgent = new HttpsKeepAliveAgent({
|
|
|
75
75
|
freeSocketTimeout: 60000
|
|
76
76
|
});
|
|
77
77
|
|
|
78
|
+
// install dns cache
|
|
79
|
+
const CacheableLookup = require("cacheable-lookup");
|
|
80
|
+
const cacheable = new CacheableLookup({
|
|
81
|
+
// Set any custom options here
|
|
82
|
+
});
|
|
83
|
+
cacheable.install(http.globalAgent);
|
|
84
|
+
cacheable.install(https.globalAgent);
|
|
85
|
+
|
|
78
86
|
// disable for now
|
|
79
87
|
/*
|
|
80
88
|
// report http/https socket state every minute
|
package/insight/insight.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
var http = require("http");
|
|
2
|
-
var path = require("path");
|
|
3
|
-
var request = require("request");
|
|
4
1
|
var util = require("../util/util");
|
|
5
2
|
|
|
6
3
|
/**
|
|
@@ -147,7 +144,7 @@ var doSend = function(callback)
|
|
|
147
144
|
// if it fails, we add it back to the queue
|
|
148
145
|
util.retryGitanaRequest(log, gitana, requestConfig, 1, function(err, response, body) {
|
|
149
146
|
|
|
150
|
-
if (response && response.
|
|
147
|
+
if (response && response.status === 200 && body)
|
|
151
148
|
{
|
|
152
149
|
console.log("Insight sync for warehouse: " + warehouseId + " succeeded");
|
|
153
150
|
}
|
|
@@ -116,7 +116,7 @@ exports = module.exports = function()
|
|
|
116
116
|
|
|
117
117
|
if (!credentials || credentials.name !== configuration.username || credentials.pass !== configuration.password)
|
|
118
118
|
{
|
|
119
|
-
res.
|
|
119
|
+
res.status(401);
|
|
120
120
|
util.setHeader(res, 'WWW-Authenticate', 'Basic realm="admin"');
|
|
121
121
|
res.end('Admin access denied');
|
|
122
122
|
return;
|
|
@@ -3,12 +3,9 @@ exports = module.exports = {};
|
|
|
3
3
|
var util = require("../../../util/util");
|
|
4
4
|
var socketUtil = require("../../../util/socket");
|
|
5
5
|
|
|
6
|
-
var request = require("request");
|
|
6
|
+
var request = require("../../../util/request");
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
var https = require("https");
|
|
10
|
-
|
|
11
|
-
exports.bindSocket = function(socket, provider)
|
|
8
|
+
exports.bindSocket = function(socket, provider, io)
|
|
12
9
|
{
|
|
13
10
|
socketUtil.bindGitana(socket, function() {
|
|
14
11
|
|
|
@@ -63,27 +60,20 @@ exports.bindSocket = function(socket, provider)
|
|
|
63
60
|
qs["force"] = true;
|
|
64
61
|
}
|
|
65
62
|
|
|
66
|
-
var agent = http.globalAgent;
|
|
67
|
-
if (process.env.GITANA_PROXY_SCHEME === "https")
|
|
68
|
-
{
|
|
69
|
-
agent = https.globalAgent;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
63
|
request({
|
|
73
64
|
"method": "POST",
|
|
74
65
|
"url": URL,
|
|
75
66
|
"qs": {},
|
|
76
67
|
"json": json,
|
|
77
68
|
"headers": headers,
|
|
78
|
-
"agent": agent,
|
|
79
69
|
"timeout": process.defaultHttpTimeoutMs
|
|
80
|
-
}, function(err, response,
|
|
70
|
+
}, function(err, response, json) {
|
|
81
71
|
|
|
82
|
-
if (err || (
|
|
72
|
+
if (err || (json && json.error)) {
|
|
83
73
|
return callback(err);
|
|
84
74
|
}
|
|
85
75
|
|
|
86
|
-
callback(null,
|
|
76
|
+
callback(null, json._doc, json.branchId);
|
|
87
77
|
});
|
|
88
78
|
};
|
|
89
79
|
});
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
var path = require('path');
|
|
2
|
-
var http = require('http');
|
|
3
|
-
var request = require('request');
|
|
4
1
|
var util = require("../../util/util");
|
|
5
|
-
var Gitana = require("gitana");
|
|
6
|
-
|
|
7
|
-
var fs = require("fs");
|
|
8
2
|
|
|
9
3
|
/**
|
|
10
4
|
* Retrieves local driver configuration for hosts from Cloud CMS.
|
package/middleware/form/form.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
var path = require("path");
|
|
2
|
-
var fs = require("fs");
|
|
3
1
|
var util = require("../../util/util");
|
|
4
|
-
var request = require("request");
|
|
5
2
|
|
|
6
3
|
var http = require("http");
|
|
7
4
|
var https = require("https");
|
|
8
5
|
|
|
6
|
+
var request = require("../../util/request");
|
|
7
|
+
|
|
9
8
|
/**
|
|
10
9
|
* Form middleware.
|
|
11
10
|
*
|
|
@@ -126,41 +125,32 @@ exports = module.exports = function()
|
|
|
126
125
|
var headers = {};
|
|
127
126
|
headers["Authorization"] = req.gitana.platform().getDriver().getHttpHeaders()["Authorization"];
|
|
128
127
|
|
|
129
|
-
var agent = http.globalAgent;
|
|
130
|
-
if (process.env.GITANA_PROXY_SCHEME === "https")
|
|
131
|
-
{
|
|
132
|
-
agent = https.globalAgent;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
128
|
request({
|
|
136
129
|
"method": "POST",
|
|
137
130
|
"url": URL,
|
|
138
131
|
"qs": {},
|
|
139
132
|
"json": form,
|
|
140
133
|
"headers": headers,
|
|
141
|
-
"agent": agent,
|
|
142
134
|
"timeout": process.defaultHttpTimeoutMs
|
|
143
|
-
}, function(err, response,
|
|
135
|
+
}, function(err, response, json) {
|
|
144
136
|
|
|
145
137
|
console.log("Response error: " + JSON.stringify(err));
|
|
146
138
|
console.log("Response: " + JSON.stringify(response,null,2));
|
|
147
|
-
console.log("Body: " + JSON.stringify(
|
|
139
|
+
console.log("Body: " + JSON.stringify(json,null,2));
|
|
148
140
|
|
|
149
|
-
if (err || (
|
|
141
|
+
if (err || (json && json.error))
|
|
150
142
|
{
|
|
151
143
|
if (failureUrl)
|
|
152
144
|
{
|
|
153
145
|
return res.redirect(failureUrl);
|
|
154
146
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
});
|
|
163
|
-
}
|
|
147
|
+
|
|
148
|
+
res.status(500);
|
|
149
|
+
res.json({
|
|
150
|
+
"ok": false,
|
|
151
|
+
"err": err || json.message,
|
|
152
|
+
"message": json
|
|
153
|
+
});
|
|
164
154
|
|
|
165
155
|
return;
|
|
166
156
|
}
|
|
@@ -199,21 +189,16 @@ exports = module.exports = function()
|
|
|
199
189
|
var headers = {};
|
|
200
190
|
headers["Authorization"] = req.gitana.platform().getDriver().getHttpHeaders()["Authorization"];
|
|
201
191
|
|
|
202
|
-
var agent = http.globalAgent;
|
|
203
|
-
if (process.env.GITANA_PROXY_SCHEME === "https")
|
|
204
|
-
{
|
|
205
|
-
agent = https.globalAgent;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
192
|
request({
|
|
209
193
|
"method": "POST",
|
|
210
194
|
"url": URL,
|
|
211
195
|
"qs": {},
|
|
212
196
|
"json": form,
|
|
213
197
|
"headers": headers,
|
|
214
|
-
"agent": agent,
|
|
215
198
|
"timeout": process.defaultHttpTimeoutMs
|
|
216
|
-
}
|
|
199
|
+
}, function(err, response, json) {
|
|
200
|
+
response.data.pipe(res);
|
|
201
|
+
});
|
|
217
202
|
|
|
218
203
|
});
|
|
219
204
|
};
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
//var path = require('path');
|
|
2
|
-
//var http = require('http');
|
|
3
|
-
//var request = require('request');
|
|
4
1
|
var util = require("../../util/util");
|
|
5
2
|
|
|
6
3
|
/**
|
|
@@ -93,9 +90,9 @@ exports = module.exports = function()
|
|
|
93
90
|
|
|
94
91
|
util.retryGitanaRequest(logMethod, gitana, requestConfig, 2, function(err, response, body) {
|
|
95
92
|
|
|
96
|
-
if (response && response.
|
|
93
|
+
if (response && response.status === 200 && body)
|
|
97
94
|
{
|
|
98
|
-
var config =
|
|
95
|
+
var config = body.config;
|
|
99
96
|
if (!config)
|
|
100
97
|
{
|
|
101
98
|
// nothing found
|
|
@@ -113,9 +110,9 @@ exports = module.exports = function()
|
|
|
113
110
|
else
|
|
114
111
|
{
|
|
115
112
|
logMethod("Load virtual driver config failed");
|
|
116
|
-
if (response && response.
|
|
113
|
+
if (response && response.status)
|
|
117
114
|
{
|
|
118
|
-
logMethod("Response status code: " + response.
|
|
115
|
+
logMethod("Response status code: " + response.status);
|
|
119
116
|
}
|
|
120
117
|
if (err) {
|
|
121
118
|
logMethod("Err: " + JSON.stringify(err));
|
|
@@ -123,7 +120,10 @@ exports = module.exports = function()
|
|
|
123
120
|
if (body) {
|
|
124
121
|
logMethod("Body: " + body);
|
|
125
122
|
}
|
|
126
|
-
var message =
|
|
123
|
+
var message = null;
|
|
124
|
+
if (body) {
|
|
125
|
+
message = JSON.stringify(body);
|
|
126
|
+
}
|
|
127
127
|
if (!message) {
|
|
128
128
|
message = "Unable to load virtual driver configuration";
|
|
129
129
|
}
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
},
|
|
7
7
|
"name": "cloudcms-server",
|
|
8
8
|
"description": "Cloud CMS Application Server Module",
|
|
9
|
-
"version": "3.2.
|
|
9
|
+
"version": "3.2.298",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "git://github.com/gitana/cloudcms-server.git"
|
|
@@ -22,9 +22,11 @@
|
|
|
22
22
|
"async": "^3.2.3",
|
|
23
23
|
"async-lock": "^1.3.2",
|
|
24
24
|
"aws-sdk": "^2.1208.0",
|
|
25
|
+
"axios": "^1.5.0",
|
|
25
26
|
"basic-auth": "^2.0.1",
|
|
26
27
|
"body-parser": "^1.20.0",
|
|
27
28
|
"bytes": "^2.5.0",
|
|
29
|
+
"cacheable-lookup": "^6.1.0",
|
|
28
30
|
"canoe": "^0.3.3",
|
|
29
31
|
"clone": "^2.1.2",
|
|
30
32
|
"connect-flash": "^0.1.1",
|
|
@@ -33,17 +35,15 @@
|
|
|
33
35
|
"consolidate": "^0.14.5",
|
|
34
36
|
"cookie-parser": "^1.4.4",
|
|
35
37
|
"debug": "^2.6.9",
|
|
36
|
-
"dns-lookup-cache": "^1.0.4",
|
|
37
38
|
"dustjs-helpers": "1.7.4",
|
|
38
39
|
"dustjs-linkedin": "3.0.1",
|
|
39
40
|
"errorhandler": "^1.5.1",
|
|
40
|
-
"express": "^4.18.
|
|
41
|
+
"express": "^4.18.2",
|
|
41
42
|
"express-session": "^1.17.3",
|
|
42
43
|
"express-useragent": "^1.0.15",
|
|
43
44
|
"extend-with-super": "^2.0.0",
|
|
44
45
|
"fast-proxy": "^2.2.0",
|
|
45
|
-
"
|
|
46
|
-
"gitana": "^1.0.322",
|
|
46
|
+
"gitana": "^1.0.324",
|
|
47
47
|
"handlebars": "^4.4.2",
|
|
48
48
|
"hbs": "^4.0.5",
|
|
49
49
|
"helmet": "^4.6.0",
|
|
@@ -77,7 +77,6 @@
|
|
|
77
77
|
"recursive-readdir": "^2.2.2",
|
|
78
78
|
"redis": "^4.2.0",
|
|
79
79
|
"redlock": "4.2.0",
|
|
80
|
-
"request": "^2.88.0",
|
|
81
80
|
"request-param": "^1.0.1",
|
|
82
81
|
"response-time": "^2.3.2",
|
|
83
82
|
"semver": "^7.3.7",
|
package/util/auth.js
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
|
-
var path = require('path');
|
|
2
|
-
var fs = require('fs');
|
|
3
1
|
var os = require('os');
|
|
4
2
|
var _util = require("util");
|
|
5
|
-
var util = require("./util");
|
|
6
|
-
var request = require("request");
|
|
7
|
-
var http = require("http");
|
|
8
|
-
var https = require("https");
|
|
9
3
|
var async = require("async");
|
|
4
|
+
var LRUCache = require("lru-cache");
|
|
10
5
|
|
|
11
|
-
var
|
|
6
|
+
var request = require("./request");
|
|
12
7
|
|
|
13
8
|
// trusted profile cache size 100
|
|
14
|
-
var TRUSTED_PROFILE_CACHE = new
|
|
9
|
+
var TRUSTED_PROFILE_CACHE = new LRUCache({
|
|
15
10
|
max:100,
|
|
16
|
-
|
|
11
|
+
maxAge: 1000 * 60 * 15 // 15 minutes
|
|
17
12
|
});
|
|
18
13
|
|
|
19
14
|
// user entry cache size 100
|
|
20
|
-
var USER_ENTRY_CACHE = new
|
|
15
|
+
var USER_ENTRY_CACHE = new LRUCache({
|
|
21
16
|
max: 100,
|
|
22
|
-
|
|
17
|
+
maxAge: 1000 * 60 * 15 // 15 minutes
|
|
23
18
|
});
|
|
24
19
|
|
|
25
20
|
var Gitana = require("gitana");
|
|
@@ -139,15 +134,12 @@ var impersonate = exports.impersonate = function(req, key, targetUser, callback)
|
|
|
139
134
|
var headers = {};
|
|
140
135
|
headers["Authorization"] = req.gitana.platform().getDriver().getHttpHeaders()["Authorization"];
|
|
141
136
|
|
|
142
|
-
var agent = util.getAgent(req.gitanaConfig.baseURL);
|
|
143
|
-
|
|
144
137
|
request({
|
|
145
138
|
"method": "POST",
|
|
146
139
|
"url": req.gitanaConfig.baseURL + "/auth/impersonate/" + targetUser.getDomainId() + "/" + targetUser.getId(),
|
|
147
140
|
"qs": {},
|
|
148
141
|
"json": {},
|
|
149
142
|
"headers": headers,
|
|
150
|
-
"agent": agent,
|
|
151
143
|
"timeout": process.defaultHttpTimeoutMs
|
|
152
144
|
}, function(err, response, json) {
|
|
153
145
|
|
|
@@ -336,7 +328,7 @@ var syncProfile = exports.syncProfile = function(req, res, strategy, domainId, p
|
|
|
336
328
|
_handleSyncUser(req, strategy, settings, key, domainId, providerId, providerUserId, token, refreshToken, userObject, groupsArray, function (err, gitanaUser) {
|
|
337
329
|
|
|
338
330
|
if (err) {
|
|
339
|
-
|
|
331
|
+
releaseLockFn();
|
|
340
332
|
return callback(err);
|
|
341
333
|
}
|
|
342
334
|
|
|
@@ -448,8 +440,6 @@ var __handleSyncUser = function(req, strategy, settings, key, domainId, provider
|
|
|
448
440
|
var headers = {};
|
|
449
441
|
headers["Authorization"] = authorizationHeader;
|
|
450
442
|
|
|
451
|
-
var agent = util.getAgent(req.gitanaConfig.baseURL);
|
|
452
|
-
|
|
453
443
|
if (!userObject) {
|
|
454
444
|
userObject = {};
|
|
455
445
|
}
|
|
@@ -475,7 +465,6 @@ var __handleSyncUser = function(req, strategy, settings, key, domainId, provider
|
|
|
475
465
|
},
|
|
476
466
|
"json": json,
|
|
477
467
|
"headers": headers,
|
|
478
|
-
"agent": agent,
|
|
479
468
|
"timeout": process.defaultHttpTimeoutMs
|
|
480
469
|
};
|
|
481
470
|
|
package/util/cloudcms.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
var path = require('path');
|
|
2
|
-
var fs = require('fs');
|
|
2
|
+
//var fs = require('fs');
|
|
3
3
|
var util = require("./util");
|
|
4
|
-
var request = require("request");
|
|
5
4
|
|
|
6
5
|
var http = require("http");
|
|
7
6
|
var https = require("https");
|
|
8
7
|
|
|
8
|
+
var request = require("./request");
|
|
9
|
+
|
|
9
10
|
exports = module.exports = function()
|
|
10
11
|
{
|
|
11
12
|
var toCacheFilePath = function(filePath)
|
|
@@ -396,36 +397,36 @@ exports = module.exports = function()
|
|
|
396
397
|
"url": URL,
|
|
397
398
|
"qs": {},
|
|
398
399
|
"headers": headers,
|
|
399
|
-
"
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
400
|
+
"responseType": "stream"
|
|
401
|
+
}, function(err, response) {
|
|
402
|
+
|
|
403
|
+
if (err) {
|
|
404
|
+
closeWriteStream(tempStream);
|
|
405
|
+
return cb(err);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if (response.status >= 200 && response.status <= 204)
|
|
406
409
|
{
|
|
407
|
-
response.pipe(tempStream).on("close", function (err) {
|
|
408
|
-
|
|
409
|
-
if (err)
|
|
410
|
-
{
|
|
410
|
+
response.data.pipe(tempStream).on("close", function (err) {
|
|
411
|
+
|
|
412
|
+
if (err) {
|
|
411
413
|
// some went wrong at disk io level?
|
|
412
414
|
return failFast(tempStream, err);
|
|
413
415
|
}
|
|
414
|
-
|
|
416
|
+
|
|
415
417
|
contentStore.existsFile(filePath, function (exists) {
|
|
416
|
-
|
|
418
|
+
|
|
417
419
|
if (exists) {
|
|
418
|
-
|
|
420
|
+
|
|
419
421
|
// write cache file
|
|
420
422
|
var cacheInfo = buildCacheInfo(response);
|
|
421
423
|
if (!cacheInfo) {
|
|
422
424
|
return cb(null, filePath, null);
|
|
423
425
|
}
|
|
424
|
-
|
|
426
|
+
|
|
425
427
|
contentStore.writeFile(cacheFilePath, JSON.stringify(cacheInfo, null, " "), function (err) {
|
|
426
|
-
|
|
427
|
-
if (err)
|
|
428
|
-
{
|
|
428
|
+
|
|
429
|
+
if (err) {
|
|
429
430
|
// failed to write cache file, thus the whole thing is invalid
|
|
430
431
|
return safeRemove(contentStore, cacheFilePath, function () {
|
|
431
432
|
failFast(tempStream, {
|
|
@@ -433,12 +434,10 @@ exports = module.exports = function()
|
|
|
433
434
|
});
|
|
434
435
|
});
|
|
435
436
|
}
|
|
436
|
-
|
|
437
|
+
|
|
437
438
|
cb(null, filePath, cacheInfo);
|
|
438
439
|
});
|
|
439
|
-
}
|
|
440
|
-
else
|
|
441
|
-
{
|
|
440
|
+
} else {
|
|
442
441
|
// for some reason, file wasn't found
|
|
443
442
|
// roll back the whole thing
|
|
444
443
|
safeRemove(contentStore, cacheFilePath, function () {
|
|
@@ -448,7 +447,7 @@ exports = module.exports = function()
|
|
|
448
447
|
});
|
|
449
448
|
}
|
|
450
449
|
});
|
|
451
|
-
|
|
450
|
+
|
|
452
451
|
}).on("error", function (err) {
|
|
453
452
|
failFast(tempStream, err);
|
|
454
453
|
});
|
|
@@ -456,54 +455,49 @@ exports = module.exports = function()
|
|
|
456
455
|
else
|
|
457
456
|
{
|
|
458
457
|
// some kind of http error (usually permission denied or invalid_token)
|
|
459
|
-
|
|
458
|
+
|
|
460
459
|
var body = "";
|
|
461
|
-
|
|
462
|
-
response.on('data', function (chunk) {
|
|
460
|
+
|
|
461
|
+
response.data.on('data', function (chunk) {
|
|
463
462
|
body += chunk;
|
|
464
463
|
});
|
|
465
|
-
|
|
466
|
-
response.on('end', function () {
|
|
467
|
-
|
|
464
|
+
|
|
465
|
+
response.data.on('end', function () {
|
|
466
|
+
|
|
468
467
|
var afterCleanup = function () {
|
|
469
|
-
|
|
468
|
+
|
|
470
469
|
// see if it is "invalid_token"
|
|
471
470
|
// if so, we can automatically retry
|
|
472
471
|
var isInvalidToken = false;
|
|
473
|
-
try
|
|
474
|
-
{
|
|
472
|
+
try {
|
|
475
473
|
var json = JSON.parse(body);
|
|
476
|
-
if (json && json.error === "invalid_token")
|
|
477
|
-
{
|
|
474
|
+
if (json && json.error === "invalid_token") {
|
|
478
475
|
isInvalidToken = true;
|
|
479
476
|
}
|
|
480
|
-
}
|
|
481
|
-
catch (e)
|
|
482
|
-
{
|
|
477
|
+
} catch (e) {
|
|
483
478
|
// swallow
|
|
484
479
|
}
|
|
485
|
-
|
|
486
|
-
if (isInvalidToken)
|
|
487
|
-
{
|
|
480
|
+
|
|
481
|
+
if (isInvalidToken) {
|
|
488
482
|
// fire for retry
|
|
489
483
|
return _refreshAccessTokenAndRetry(contentStore, gitana, uri, filePath, attemptCount, maxAttemptsAllowed, {
|
|
490
484
|
"message": "Unable to load asset from remote store",
|
|
491
|
-
"code": response.
|
|
485
|
+
"code": response.status,
|
|
492
486
|
"body": body
|
|
493
487
|
}, cb);
|
|
494
488
|
}
|
|
495
|
-
|
|
489
|
+
|
|
496
490
|
// otherwise, it's not worth retrying at this time
|
|
497
491
|
cb({
|
|
498
492
|
"message": "Unable to load asset from remote store",
|
|
499
|
-
"code": response.
|
|
493
|
+
"code": response.status,
|
|
500
494
|
"body": body
|
|
501
495
|
});
|
|
502
496
|
};
|
|
503
|
-
|
|
497
|
+
|
|
504
498
|
// ensure stream is closed
|
|
505
499
|
closeWriteStream(tempStream);
|
|
506
|
-
|
|
500
|
+
|
|
507
501
|
// clean things up
|
|
508
502
|
safeRemove(contentStore, cacheFilePath, function () {
|
|
509
503
|
safeRemove(contentStore, filePath, function () {
|
|
@@ -511,18 +505,18 @@ exports = module.exports = function()
|
|
|
511
505
|
});
|
|
512
506
|
});
|
|
513
507
|
});
|
|
514
|
-
|
|
508
|
+
|
|
515
509
|
}
|
|
516
|
-
|
|
517
|
-
}).on('error', function (e) {
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
}).on('end', function (e) {
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
}).end();
|
|
510
|
+
});
|
|
511
|
+
// }).on('error', function (e) {
|
|
512
|
+
// failFast(tempStream, e);
|
|
513
|
+
//
|
|
514
|
+
// }).on('end', function (e) {
|
|
515
|
+
//
|
|
516
|
+
// // ensure stream is closed
|
|
517
|
+
// closeWriteStream(tempStream);
|
|
518
|
+
//
|
|
519
|
+
// }).end();
|
|
526
520
|
|
|
527
521
|
tempStream.on("error", function (e) {
|
|
528
522
|
process.log("Temp stream errored out");
|
|
@@ -561,7 +555,7 @@ exports = module.exports = function()
|
|
|
561
555
|
var downloadNode = function(contentStore, gitana, repositoryId, branchId, nodeId, attachmentId, nodePath, locale, forceReload, callback)
|
|
562
556
|
{
|
|
563
557
|
// ensure path starts with "/"
|
|
564
|
-
if (nodePath && nodePath.
|
|
558
|
+
if (nodePath && !nodePath.startsWith("/")) {
|
|
565
559
|
nodePath = "/" + nodePath;
|
|
566
560
|
}
|
|
567
561
|
|
|
@@ -672,7 +666,7 @@ exports = module.exports = function()
|
|
|
672
666
|
}
|
|
673
667
|
|
|
674
668
|
// ensure path starts with "/"
|
|
675
|
-
if (nodePath && nodePath.
|
|
669
|
+
if (nodePath && !nodePath.startsWith("/")) {
|
|
676
670
|
nodePath = "/" + nodePath;
|
|
677
671
|
}
|
|
678
672
|
|