Skip to content

Commit 65b3760

Browse files
committed
backup
1 parent b7ff96d commit 65b3760

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

lib/publish.js

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Module dependencies.
1111
*/
1212
var prompt = require('prompt');
13-
var request = require('request');
13+
var request = require('./request');
1414
var _ = require('lodash');
1515
var debug = require('debug')('publish:general');
1616
var debug_assets = require('debug')('publish:asset');
@@ -192,38 +192,37 @@ Publish.prototype.init = function() {
192192
//proceed after confirmation
193193
return helper.confirm(config, inputs.language, backup, cb);
194194
},
195-
// function(cb) {
196-
// // login into cms, to get authtoken
197-
// api.credentials = {
198-
// user: {
199-
// email: inputs.username,
200-
// password: inputs.password
201-
// }
202-
// };
203-
// return utility.login(api.credentials, function(err, body) {
204-
// if (err) {
205-
// return cb(err);
206-
// } else if (body && body.user && body.user.authtoken) {
207-
// return cb(null, body.user.authtoken);
208-
// }
209-
// log(error(`Something went wrong while logging in..`));
210-
// return cb(body);
211-
// });
212-
// },
213-
function( /*authtoken, */ cb) {
214-
// headers.authtoken = authtoken;
215-
headers.authtoken = '***REMOVED***';
195+
function(cb) {
196+
// login into cms, to get authtoken
197+
api.credentials = {
198+
user: {
199+
email: inputs.username,
200+
password: inputs.password
201+
}
202+
};
203+
return utility.login(api.credentials, function(err, body) {
204+
if (err) {
205+
return cb(err);
206+
} else if (body && body.user && body.user.authtoken) {
207+
return cb(null, body.user.authtoken);
208+
}
209+
log(error(`Something went wrong while logging in..`));
210+
return cb(body);
211+
});
212+
},
213+
function(authtoken, cb) {
214+
headers.authtoken = authtoken;
216215
// get environment names from Contentstack
217216
return request({
218217
uri: `${api.host}/${api.version}${api.urls.environments}?$in=${inputs.environment.toString()}`,
219218
headers: headers,
220219
method: 'GET',
221220
json: true
222-
}, function(error, response) {
221+
}, function(error, body) {
223222
if (error) {
224223
return cb(error);
225-
} else if (response && response.body.environments && response.body.environments.length) {
226-
inputs.environment_ids = _.map(response.body.environments, 'uid');
224+
} else if (body.environments && body.environments.length) {
225+
inputs.environment_ids = _.map(body.environments, 'uid');
227226
return cb(null, null);
228227
}
229228
return cb(response.body);

lib/request.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var chalk = require('chalk');
1515
var pkg = require('../package');
1616

1717
var warning = chalk.yellow;
18+
var succcess = chalk.green;
1819
var error = chalk.red;
1920
var info = chalk.blue;
2021
var log = console.log;
@@ -59,6 +60,7 @@ var makeCall = module.exports = function(req, cb, RETRY) {
5960
}
6061
var timeDelay;
6162
if (response.statusCode >= 200 && response.statusCode <= 399) {
63+
log(succcess(`${req.method}: ${req.uri || req.url} completed succcessfully with ${response.statusCode} statusCode!`));
6264
return cb(null, body);
6365
} else if (response.statusCode === 429) {
6466
timeDelay = Math.pow(Math.SQRT2, RETRY) * 100;

0 commit comments

Comments
 (0)