resolve merge conflicts
This commit is contained in:
@ -1,14 +1,20 @@
|
||||
var User = require('../models/User'),
|
||||
var async = require('async'),
|
||||
User = require('../models/User'),
|
||||
Challenge = require('./../models/Challenge'),
|
||||
Bonfire = require('./../models/Bonfire'),
|
||||
Story = require('./../models/Story'),
|
||||
Comment = require('./../models/Comment'),
|
||||
resources = require('./resources.json'),
|
||||
questions = resources.questions,
|
||||
steps = resources.steps,
|
||||
secrets = require('./../config/secrets'),
|
||||
Challenge = require('./../models/Challenge'),
|
||||
bonfires = require('../seed_data/bonfires.json');
|
||||
coursewares = require('../seed_data/coursewares.json');
|
||||
Client = require('node-rest-client').Client,
|
||||
client = new Client(),
|
||||
debug = require('debug')('freecc:cntr:bonfires');
|
||||
bonfires = require('../seed_data/bonfires.json'),
|
||||
coursewares = require('../seed_data/coursewares.json'),
|
||||
moment = require('moment'),
|
||||
https = require('https'),
|
||||
debug = require('debug')('freecc:cntr:resources'),
|
||||
cheerio = require('cheerio'),
|
||||
request = require('request'),
|
||||
R = require('ramda');
|
||||
|
||||
/**
|
||||
* GET /
|
||||
@ -21,6 +27,44 @@ module.exports = {
|
||||
title: 'Privacy'
|
||||
});
|
||||
},
|
||||
sitemap: function sitemap(req, res, next) {
|
||||
var appUrl = 'http://www.freecodecamp.com';
|
||||
var now = moment(new Date()).format('YYYY-MM-DD');
|
||||
|
||||
User.find({'profile.username': {'$ne': '' }}, function(err, users) {
|
||||
if (err) {
|
||||
debug('User err: ', err);
|
||||
return next(err);
|
||||
}
|
||||
Challenge.find({}, function (err, challenges) {
|
||||
if (err) {
|
||||
debug('User err: ', err);
|
||||
return next(err);
|
||||
}
|
||||
Bonfire.find({}, function (err, bonfires) {
|
||||
if (err) {
|
||||
debug('User err: ', err);
|
||||
return next(err);
|
||||
}
|
||||
Story.find({}, function (err, stories) {
|
||||
if (err) {
|
||||
debug('User err: ', err);
|
||||
return next(err);
|
||||
}
|
||||
res.header('Content-Type', 'application/xml');
|
||||
res.render('resources/sitemap', {
|
||||
appUrl: appUrl,
|
||||
now: now,
|
||||
users: users,
|
||||
challenges: challenges,
|
||||
bonfires: bonfires,
|
||||
stories: stories
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
deployAWebsite: function deployAWebsite(req, res) {
|
||||
res.render('resources/deploy-a-website', {
|
||||
@ -46,6 +90,12 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
|
||||
guideToOurNonprofitProjects: function guideToOurNonprofitProjects(req, res) {
|
||||
res.render('resources/guide-to-our-nonprofit-projects', {
|
||||
title: 'A guide to our Nonprofit Projects'
|
||||
});
|
||||
},
|
||||
|
||||
controlShortcuts: function controlShortcuts(req, res) {
|
||||
res.render('resources/control-shortcuts', {
|
||||
title: 'These Control Shortcuts will save you Hours'
|
||||
@ -83,23 +133,28 @@ module.exports = {
|
||||
},
|
||||
githubCalls: function(req, res) {
|
||||
var githubHeaders = {headers: {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1521.3 Safari/537.36'}, port:80 };
|
||||
client.get('https://api.github.com/repos/freecodecamp/freecodecamp/pulls?client_id=' + secrets.github.clientID + '&client_secret=' + secrets.github.clientSecret, githubHeaders, function(pulls, res3) {
|
||||
request('https://api.github.com/repos/freecodecamp/freecodecamp/pulls?client_id=' + secrets.github.clientID + '&client_secret=' + secrets.github.clientSecret, githubHeaders, function(err, status1, pulls) {
|
||||
pulls = pulls ? Object.keys(JSON.parse(pulls)).length : "Can't connect to github";
|
||||
client.get('https://api.github.com/repos/freecodecamp/freecodecamp/issues?client_id=' + secrets.github.clientID + '&client_secret=' + secrets.github.clientSecret, githubHeaders, function (issues, res4) {
|
||||
request('https://api.github.com/repos/freecodecamp/freecodecamp/issues?client_id=' + secrets.github.clientID + '&client_secret=' + secrets.github.clientSecret, githubHeaders, function (err, status2, issues) {
|
||||
issues = ((pulls === parseInt(pulls)) && issues) ? Object.keys(JSON.parse(issues)).length - pulls : "Can't connect to GitHub";
|
||||
res.send({"issues": issues, "pulls" : pulls});
|
||||
});
|
||||
});
|
||||
},
|
||||
trelloCalls: function(req, res) {
|
||||
client.get('https://trello.com/1/boards/BA3xVpz9/cards?key=' + secrets.trello.key, function(trello, res2) {
|
||||
trello = trello ? (JSON.parse(trello)).length : "Can't connect to to Trello";
|
||||
|
||||
|
||||
|
||||
trelloCalls: function(req, res, next) {
|
||||
request('https://trello.com/1/boards/BA3xVpz9/cards?key=' + secrets.trello.key, function(err, status, trello) {
|
||||
if (err) { return next(err); }
|
||||
trello = (status && status.statusCode == 200) ? (JSON.parse(trello)).length : "Can't connect to to Trello";
|
||||
res.send({"trello": trello});
|
||||
});
|
||||
},
|
||||
bloggerCalls: function(req, res) {
|
||||
client.get('https://www.googleapis.com/blogger/v3/blogs/2421288658305323950/posts?key=' + secrets.blogger.key, function (blog, res5) {
|
||||
var blog = blog.length > 100 ? JSON.parse(blog) : "";
|
||||
bloggerCalls: function(req, res, next) {
|
||||
request('https://www.googleapis.com/blogger/v3/blogs/2421288658305323950/posts?key=' + secrets.blogger.key, function (err, status, blog) {
|
||||
if (err) { return next(err); }
|
||||
blog = (status && status.statusCode == 200) ? JSON.parse(blog) : '';
|
||||
res.send({
|
||||
blog1Title: blog ? blog["items"][0]["title"] : "Can't connect to Blogger",
|
||||
blog1Link: blog ? blog["items"][0]["url"] : "http://blog.freecodecamp.com",
|
||||
@ -115,7 +170,13 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
|
||||
about: function(req, res) {
|
||||
about: function(req, res, next) {
|
||||
if (req.user) {
|
||||
if (!req.user.profile.picture || req.user.profile.picture === "https://s3.amazonaws.com/freecodecamp/favicons/apple-touch-icon-180x180.png") {
|
||||
req.user.profile.picture = "https://s3.amazonaws.com/freecodecamp/camper-image-placeholder.png";
|
||||
req.user.save();
|
||||
}
|
||||
}
|
||||
var date1 = new Date("10/15/2014");
|
||||
var date2 = new Date();
|
||||
var progressTimestamps = req.user.progressTimestamps;
|
||||
@ -136,20 +197,24 @@ module.exports = {
|
||||
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
|
||||
var daysRunning = Math.ceil(timeDiff / (1000 * 3600 * 24));
|
||||
var announcements = resources.announcements;
|
||||
function numberWithCommas(x) {
|
||||
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||
}
|
||||
User.count({}, function (err, c3) {
|
||||
if (err) {
|
||||
debug('User err: ', err);
|
||||
next(err);
|
||||
return next(err);
|
||||
}
|
||||
User.count({'points': {'$gt': 53}}, function (err, all) {
|
||||
if (err) {
|
||||
debug('User err: ', err);
|
||||
next(err);
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.render('resources/learn-to-code', {
|
||||
title: 'About Free Code Camp and Our Team of Volunteers',
|
||||
daysRunning: daysRunning,
|
||||
c3: c3,
|
||||
c3: numberWithCommas(c3),
|
||||
all: all,
|
||||
announcements: announcements
|
||||
});
|
||||
@ -172,10 +237,6 @@ module.exports = {
|
||||
return compliments[Math.floor(Math.random() * compliments.length)];
|
||||
},
|
||||
|
||||
numberOfBonfires: function() {
|
||||
return bonfires.length - 1;
|
||||
},
|
||||
|
||||
allBonfireIds: function() {
|
||||
return bonfires.map(function(elem) {
|
||||
return {
|
||||
@ -214,7 +275,7 @@ module.exports = {
|
||||
return {
|
||||
_id: elem._id,
|
||||
difficulty: elem.difficulty
|
||||
}
|
||||
};
|
||||
})
|
||||
.sort(function(a, b) {
|
||||
return a.difficulty - b.difficulty;
|
||||
@ -229,23 +290,91 @@ module.exports = {
|
||||
name: elem.name,
|
||||
difficulty: elem.difficulty,
|
||||
_id: elem._id
|
||||
}
|
||||
};
|
||||
})
|
||||
.sort(function(a, b) {
|
||||
return a.difficulty - b.difficulty;
|
||||
})
|
||||
.map (function(elem) {
|
||||
.sort(function(a, b) {
|
||||
return a.difficulty - b.difficulty;
|
||||
})
|
||||
.map (function(elem) {
|
||||
return {
|
||||
name : elem.name,
|
||||
name: elem.name,
|
||||
_id: elem._id
|
||||
}
|
||||
};
|
||||
});
|
||||
},
|
||||
whichEnvironment: function() {
|
||||
return process.env.NODE_ENV;
|
||||
},
|
||||
getURLTitle: function(url, callback) {
|
||||
debug('got url in meta scraping function', url);
|
||||
(function () {
|
||||
var result = {title: '', image: '', url: '', description: ''};
|
||||
request(url, function (error, response, body) {
|
||||
if (!error && response.statusCode === 200) {
|
||||
var $ = cheerio.load(body);
|
||||
var metaDescription = $("meta[name='description']");
|
||||
var metaImage = $("meta[property='og:image']");
|
||||
var urlImage = metaImage.attr('content') ? metaImage.attr('content') : '';
|
||||
var description = metaDescription.attr('content') ? metaDescription.attr('content') : '';
|
||||
result.title = $('title').text().length < 141 ? $('title').text() : $('title').text().slice(0, 137) + " ...";
|
||||
result.image = urlImage;
|
||||
result.description = description;
|
||||
callback(null, result);
|
||||
} else {
|
||||
callback('failed');
|
||||
}
|
||||
});
|
||||
})();
|
||||
},
|
||||
updateUserStoryPictures: function(userId, picture, username, cb) {
|
||||
|
||||
var counter = 0,
|
||||
foundStories,
|
||||
foundComments;
|
||||
|
||||
Story.find({'author.userId': userId}, function(err, stories) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
foundStories = stories;
|
||||
counter++;
|
||||
saveStoriesAndComments();
|
||||
});
|
||||
Comment.find({'author.userId': userId}, function(err, comments) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
foundComments = comments;
|
||||
counter++;
|
||||
saveStoriesAndComments();
|
||||
});
|
||||
|
||||
function saveStoriesAndComments() {
|
||||
if (counter !== 2) {
|
||||
return;
|
||||
}
|
||||
var tasks = [];
|
||||
R.forEach(function(comment) {
|
||||
comment.author.picture = picture;
|
||||
comment.author.username = username;
|
||||
comment.markModified('author');
|
||||
tasks.push(function(cb) {
|
||||
comment.save(cb);
|
||||
});
|
||||
}, foundComments);
|
||||
|
||||
R.forEach(function(story) {
|
||||
story.author.picture = picture;
|
||||
story.author.username = username;
|
||||
story.markModified('author');
|
||||
tasks.push(function(cb) {
|
||||
story.save(cb);
|
||||
});
|
||||
}, foundStories);
|
||||
async.parallel(tasks, function(err) {
|
||||
if (err) { return cb(err); }
|
||||
cb();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user