feat(sharing): add ability to share avatar. adds static page with avatar

screen, and generates image from it
This commit is contained in:
Tyler Renelle 2014-11-07 17:04:41 -07:00
parent cd2d861860
commit e6a99f33a9
4 changed files with 104 additions and 3 deletions

View file

@ -25,5 +25,10 @@
"PAYPAL_SIGNATURE": "PAYPAL_SIGNATURE",
"EMAIL_SERVER_URL": "http://example.com",
"EMAIL_SERVER_AUTH_USER": "user",
"EMAIL_SERVER_AUTH_PASSWORD": "password"
"EMAIL_SERVER_AUTH_PASSWORD": "password",
"S3":{
"accessKeyId":"accessKeyId",
"secretAccessKey":"secretAccessKey"
}
}

View file

@ -25,17 +25,18 @@
"grunt-nodemon": "~0.3.0",
"habitrpg-shared": "git://github.com/HabitRPG/habitrpg-shared#develop",
"icalendar": "git://github.com/lefnire/node-icalendar#master",
"jade": "~1.7.0",
"js2xmlparser": "~0.1.2",
"lodash": "~2.4.1",
"jade": "~1.7.0",
"method-override": "~2.2.0",
"mongoose": "~3.8.17",
"moment": "~2.8.3",
"mongoose": "~3.8.17",
"mongoose-id-autoinc": "~2013.7.14-4",
"nconf": "~0.6.9",
"newrelic": "~1.11.2",
"nib": "~1.0.1",
"nodemailer": "~0.5.2",
"pageres": "^1.0.1",
"passport": "~0.2.1",
"passport-facebook": "Fonger/passport-facebook#a8f98adcddad99caa9a918bc7b76462c92c5c9fd",
"paypal-express-checkout": "git://github.com/HabitRPG/node-paypal-express-checkout#habitrpg",
@ -43,6 +44,7 @@
"paypal-recurring": "git://github.com/jaybryant/paypal-recurring#656b496f43440893c984700191666a5c5c535dca",
"pretty-data": "git://github.com/vkiryukhin/pretty-data#master",
"request": "~2.44.0",
"s3": "^4.3.1",
"stripe": "*",
"swagger-node-express": "git://github.com/lefnire/swagger-node-express#habitrpg",
"universal-analytics": "~0.3.2",

View file

@ -28,6 +28,50 @@ _.each(pages, function(name){
});
})
var mongoose = require('mongoose');
router.get('/static/avatar-:uuid.html', i18n.getUserLanguage, middleware.locals, function(req, res) {
mongoose.model('User').findById(req.params.uuid).select('stats profile items achievements preferences backer contributor').exec(function(err, user){
res.render('avatar-static', {
title: user.profile.name,
env: _.defaults({user:user},res.locals.habitrpg)
});
})
});
var Pageres = require('pageres'); //https://github.com/sindresorhus/pageres
var s3 = require('s3'); //https://github.com/andrewrk/node-s3-client
var bucket = 'habitrpg-dev';
var client = s3.createClient({
s3Options: {
accessKeyId: nconf.get("S3").accessKeyId,
secretAccessKey: nconf.get("S3").secretAccessKey
}
});
router.get('/static/avatar-:uuid.png', i18n.getUserLanguage, middleware.locals, function(req, res, next) {
var filename = 'avatar-'+req.params.uuid+'.png';
new Pageres({delay: 1})
.src(nconf.get('BASE_URL')+'/static/avatar-'+req.params.uuid+'.html', ['140x147'], {crop: true, filename: filename.replace('.png','')})
.dest(__dirname)//TODO Delete this aftewards, or stream directly to s3 instead
.run(function (err, file) {
if (err) return next(err);
var params = {
localFile: __dirname + "/" + filename,
s3Params: { Bucket: bucket, Key: filename }
};
var uploader = client.uploadFile(params);
uploader.on('error', function(err) {
console.error("unable to upload:", err.stack);
});
//uploader.on('progress', function() {
// console.log("progress", uploader.progressMd5Amount,
// uploader.progressAmount, uploader.progressTotal);
//});
uploader.on('end', function() {
res.json(200,{file: s3.getPublicUrlHttp(bucket,filename)});
console.log("done uploading");
});
});
});
// --------- Redirects --------
router.get('/static/extensions', function(req, res) {

50
views/avatar-static.jade Normal file
View file

@ -0,0 +1,50 @@
doctype html
html(ng-app="habitrpg")
head
title=title
link(rel='shortcut icon', href='#{env.getBuildUrl("favicon.ico")}?v=3')
meta(charset='utf-8')
meta(name='viewport', content='width=device-width, initial-scale=1.0')
meta(name='apple-mobile-web-app-capable', content='yes')
script(type='text/javascript').
window.env = !{JSON.stringify(env)};
!= env.getManifestFiles("app")
script(type='text/javascript').
hello.init({
facebook : window.env.FACEBOOK_KEY
});
window.habitrpg
.controller('StaticAvatarCtrl', ['$scope', '$http', function($scope, $http){
$scope.profile = window.env.user;
$scope.postToWall = function(network, customMessage) {
hello(network).login({scope: 'publish'}).then(function (auth) {
$http.get('/static/avatar-'+$scope.profile._id+'.png').success(function(r){
//TODO experiment with just the page as a link
hello(auth.network).api('/me/feed', 'post', {
picture: r.file, // also see link, picture, icon //https://developers.facebook.com/docs/graph-api/reference/v2.2/status#publishing
message: customMessage || "Check out my HabitRPG progress!"
}).then(function (r) {
debugger;
});
})
});
}
}])
//webfonts
link(href='//fonts.googleapis.com/css?family=Lato:300,400,700,400italic,700italic', rel='stylesheet', type='text/css')
body(ng-cloak)
include ./shared/header/avatar
div(ng-controller='StaticAvatarCtrl')
+herobox({main:true})
button.btn.btn-primary(ng-click='postToWall("facebook", customMessage)') Post to Facebook
textarea(placeholder="Check out my HabitRPG progress!",ng-model="customMessage")