Skip to content

Commit

Permalink
fix avatar sharing and caching (30 minutes)
Browse files Browse the repository at this point in the history
  • Loading branch information
paglias committed May 22, 2016
1 parent 1e83dda commit 4c8ad80
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions website/server/controllers/top-level/dataexport.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ api.exportUserAvatarHtml = {
if (!member) throw new NotFound(res.t('userWithIDNotFound', {userId: memberId}));
res.render('avatar-static', {
title: member.profile.name,
env: _.defaults({member}, res.locals.habitrpg),
env: _.defaults({user: member}, res.locals.habitrpg),
});
},
};
Expand All @@ -197,7 +197,7 @@ api.exportUserAvatarPng = {
let memberId = req.params.memberId;

let filename = `avatars/${memberId}.png`;
let s3url = `https://${S3_BUCKET}+'.s3.amazonaws.com/${filename}`;
let s3url = `https://${S3_BUCKET}.s3.amazonaws.com/${filename}`;

let response;
try {
Expand All @@ -208,9 +208,9 @@ api.exportUserAvatarPng = {
}
}

// cache images for 10 minutes on aws, else upload a new one
if (response && response.statusCode === 200 && moment().diff(response.headers['last-modified'], 'minutes') < 10) {
return res.redirect(301, s3url);
// cache images for 30 minutes on aws, else upload a new one
if (response && response.statusCode === 200 && moment().diff(response.headers['last-modified'], 'minutes') < 30) {
return res.redirect(s3url);
}

let [stream] = await new Pageres()
Expand All @@ -226,7 +226,7 @@ api.exportUserAvatarPng = {
ACL: 'public-read',
StorageClass: 'REDUCED_REDUNDANCY',
ContentType: 'image/png',
Expires: moment().add({minutes: 3}).toDate(),
Expires: moment().add({minutes: 5}).toDate(),
Body: stream,
});

Expand Down

0 comments on commit 4c8ad80

Please sign in to comment.