Vulcan/packages/telescope-core/lib/router/server.js

66 lines
1.7 KiB
JavaScript
Raw Normal View History

2015-02-03 11:17:34 +09:00
var increasePostClicks = function(postId, ip){
2015-03-28 18:30:26 +09:00
2015-02-03 11:17:34 +09:00
var clickEvent = {
name: 'click',
properties: {
postId: postId,
ip: ip
}
};
2015-02-03 11:17:34 +09:00
// make sure this IP hasn't previously clicked on this post
var existingClickEvent = Events.findOne({name: 'click', 'properties.postId': postId, 'properties.ip': ip});
if(!existingClickEvent){
2015-05-11 18:20:05 +09:00
Events.log(clickEvent);
2015-02-03 11:17:34 +09:00
Posts.update(postId, { $inc: { clickCount: 1 }});
}
};
2015-02-03 11:17:34 +09:00
Meteor.startup(function (){
// Link Out
Router.route('/out', {
name: 'out',
where: 'server',
action: function(){
var query = this.request.query;
if(query.url){ // for some reason, query.url doesn't need to be decoded
var post = Posts.findOne({url: query.url});
if (post) {
2015-02-03 11:17:34 +09:00
var ip = this.request.connection.remoteAddress;
increasePostClicks(post._id, ip);
this.response.writeHead(302, {'Location': query.url});
} else {
// don't redirect if we can't find a post for that link
this.response.write('Invalid URL');
}
this.response.end();
}
}
});
// Account approved email
Router.route('/email/account-approved/:id?', {
name: 'accountApproved',
where: 'server',
action: function() {
var user = Meteor.users.findOne(this.params.id);
var emailProperties = {
profileUrl: Users.getProfileUrl(user),
username: Users.getUserName(user),
2015-03-28 18:30:26 +09:00
siteTitle: Settings.get('title'),
siteUrl: Telescope.utils.getSiteUrl()
};
var html = Handlebars.templates.emailAccountApproved(emailProperties);
this.response.write(buildEmailTemplate(html));
this.response.end();
}
});
2015-03-28 18:30:26 +09:00
});