cloudcms-server 4.0.0-beta.1 → 4.0.0-beta.2

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/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  },
7
7
  "name": "cloudcms-server",
8
8
  "description": "Cloud CMS Application Server Module",
9
- "version": "4.0.0-beta.1",
9
+ "version": "4.0.0-beta.2",
10
10
  "repository": {
11
11
  "type": "git",
12
12
  "url": "git://github.com/gitana/cloudcms-server.git"
package/util/cloudcms.js CHANGED
@@ -399,36 +399,34 @@ exports = module.exports = function()
399
399
  "headers": headers,
400
400
  "responseType": "stream"
401
401
  }, function(err, response) {
402
-
402
+
403
403
  if (err) {
404
404
  closeWriteStream(tempStream);
405
405
  return cb(err);
406
406
  }
407
-
407
+
408
408
  if (response.status >= 200 && response.status <= 204)
409
409
  {
410
410
  response.data.pipe(tempStream).on("close", function (err) {
411
-
412
- if (err)
413
- {
411
+
412
+ if (err) {
414
413
  // some went wrong at disk io level?
415
414
  return failFast(tempStream, err);
416
415
  }
417
-
416
+
418
417
  contentStore.existsFile(filePath, function (exists) {
419
-
418
+
420
419
  if (exists) {
421
-
420
+
422
421
  // write cache file
423
422
  var cacheInfo = buildCacheInfo(response);
424
423
  if (!cacheInfo) {
425
424
  return cb(null, filePath, null);
426
425
  }
427
-
426
+
428
427
  contentStore.writeFile(cacheFilePath, JSON.stringify(cacheInfo, null, " "), function (err) {
429
-
430
- if (err)
431
- {
428
+
429
+ if (err) {
432
430
  // failed to write cache file, thus the whole thing is invalid
433
431
  return safeRemove(contentStore, cacheFilePath, function () {
434
432
  failFast(tempStream, {
@@ -436,12 +434,10 @@ exports = module.exports = function()
436
434
  });
437
435
  });
438
436
  }
439
-
437
+
440
438
  cb(null, filePath, cacheInfo);
441
439
  });
442
- }
443
- else
444
- {
440
+ } else {
445
441
  // for some reason, file wasn't found
446
442
  // roll back the whole thing
447
443
  safeRemove(contentStore, cacheFilePath, function () {
@@ -451,7 +447,7 @@ exports = module.exports = function()
451
447
  });
452
448
  }
453
449
  });
454
-
450
+
455
451
  }).on("error", function (err) {
456
452
  failFast(tempStream, err);
457
453
  });
@@ -459,35 +455,30 @@ exports = module.exports = function()
459
455
  else
460
456
  {
461
457
  // some kind of http error (usually permission denied or invalid_token)
462
-
458
+
463
459
  var body = "";
464
-
460
+
465
461
  response.data.on('data', function (chunk) {
466
462
  body += chunk;
467
463
  });
468
-
469
- response.on('end', function () {
470
-
464
+
465
+ response.data.on('end', function () {
466
+
471
467
  var afterCleanup = function () {
472
-
468
+
473
469
  // see if it is "invalid_token"
474
470
  // if so, we can automatically retry
475
471
  var isInvalidToken = false;
476
- try
477
- {
472
+ try {
478
473
  var json = JSON.parse(body);
479
- if (json && json.error === "invalid_token")
480
- {
474
+ if (json && json.error === "invalid_token") {
481
475
  isInvalidToken = true;
482
476
  }
483
- }
484
- catch (e)
485
- {
477
+ } catch (e) {
486
478
  // swallow
487
479
  }
488
-
489
- if (isInvalidToken)
490
- {
480
+
481
+ if (isInvalidToken) {
491
482
  // fire for retry
492
483
  return _refreshAccessTokenAndRetry(contentStore, gitana, uri, filePath, attemptCount, maxAttemptsAllowed, {
493
484
  "message": "Unable to load asset from remote store",
@@ -495,7 +486,7 @@ exports = module.exports = function()
495
486
  "body": body
496
487
  }, cb);
497
488
  }
498
-
489
+
499
490
  // otherwise, it's not worth retrying at this time
500
491
  cb({
501
492
  "message": "Unable to load asset from remote store",
@@ -503,10 +494,10 @@ exports = module.exports = function()
503
494
  "body": body
504
495
  });
505
496
  };
506
-
497
+
507
498
  // ensure stream is closed
508
499
  closeWriteStream(tempStream);
509
-
500
+
510
501
  // clean things up
511
502
  safeRemove(contentStore, cacheFilePath, function () {
512
503
  safeRemove(contentStore, filePath, function () {
@@ -514,18 +505,18 @@ exports = module.exports = function()
514
505
  });
515
506
  });
516
507
  });
517
-
508
+
518
509
  }
519
-
520
- }).on('error', function (e) {
521
- failFast(tempStream, e);
522
-
523
- }).on('end', function (e) {
524
-
525
- // ensure stream is closed
526
- closeWriteStream(tempStream);
527
-
528
- }).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();
529
520
 
530
521
  tempStream.on("error", function (e) {
531
522
  process.log("Temp stream errored out");
package/util/request.js CHANGED
@@ -28,7 +28,13 @@ module.exports = function(config, callback)
28
28
  {
29
29
  // request config - https://github.com/request/request#requestoptions-callback
30
30
  // axios config - https://www.npmjs.com/package/axios
31
-
31
+
32
+ if (!callback) {
33
+ callback = function(err, response, data) {
34
+ // nothing
35
+ };
36
+ }
37
+
32
38
  var requestConfig = {};
33
39
  requestConfig.url = config.uri || config.url;
34
40
  requestConfig.method = config.method || "get";
@@ -109,7 +115,7 @@ module.exports = function(config, callback)
109
115
  }
110
116
  */
111
117
 
112
- axios.request(requestConfig).then(function(response) {
118
+ return axios.request(requestConfig).then(function(response) {
113
119
  callback(null, response, response.data);
114
120
  }, function(error) {
115
121
  callback(error);