[NEW] Add input to set time for avatar cache control (#10958)

* Add input to set time for avatar cache control

* Change description of avatar cache time
pull/11097/head
Marcos Spessatto Defendi 7 years ago committed by Rodrigo Nascimento
parent acc671ee9e
commit 237f21f472
  1. 4
      packages/rocketchat-i18n/i18n/en.i18n.json
  2. 4
      packages/rocketchat-lib/server/startup/settings.js
  3. 5
      server/startup/avatar.js

@ -35,6 +35,8 @@
"Accounts_AllowUserAvatarChange": "Allow User Avatar Change",
"Accounts_AllowUsernameChange": "Allow Username Change",
"Accounts_AllowUserProfileChange": "Allow User Profile Change",
"Accounts_AvatarCacheTime": "Avatar cache time",
"Accounts_AvatarCacheTime_description": "Number of seconds the http protocol is told to cache the avatar images.",
"Accounts_AvatarResize": "Resize Avatars",
"Accounts_AvatarSize": "Avatar Size",
"Accounts_BlockedDomainsList": "Blocked Domains List",
@ -2702,4 +2704,4 @@
"Your_push_was_sent_to_s_devices": "Your push was sent to %s devices",
"Your_server_link": "Your server link",
"Your_workspace_is_ready": "Your workspace is ready to use 🎉"
}
}

@ -454,6 +454,10 @@ RocketChat.settings.addGroup('Accounts', function() {
value: true
}
});
this.add('Accounts_AvatarCacheTime', 3600, {
type: 'int',
i18nDescription: 'Accounts_AvatarCacheTime_description'
});
return this.add('Accounts_SetDefaultAvatar', true, {
type: 'boolean'

@ -7,6 +7,7 @@ Meteor.startup(function() {
const params = {
username: decodeURIComponent(req.url.replace(/^\//, '').replace(/\?.*$/, ''))
};
const cacheTime = req.query.cacheTime || RocketChat.settings.get('Accounts_AvatarCacheTime');
if (_.isEmpty(params.username)) {
res.writeHead(403);
@ -47,7 +48,7 @@ Meteor.startup(function() {
return;
}
res.setHeader('Cache-Control', 'public, max-age=0');
res.setHeader('Cache-Control', `public, max-age=${ cacheTime }`);
res.setHeader('Expires', '-1');
res.setHeader('Content-Disposition', 'inline');
res.setHeader('Last-Modified', file.uploadedAt.toUTCString());
@ -57,7 +58,7 @@ Meteor.startup(function() {
return FileUpload.get(file, req, res);
} else {
res.setHeader('Content-Type', 'image/svg+xml');
res.setHeader('Cache-Control', 'public, max-age=0');
res.setHeader('Cache-Control', `public, max-age=${ cacheTime }`);
res.setHeader('Expires', '-1');
res.setHeader('Last-Modified', 'Thu, 01 Jan 2015 00:00:00 GMT');

Loading…
Cancel
Save