|
|
|
|
@ -17,6 +17,10 @@ export const setUserAvatar = function(user, dataURI, contentType, service) { |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
result = HTTP.get(dataURI, { npmRequestOptions: { encoding: 'binary', rejectUnauthorized: false } }); |
|
|
|
|
if (!result) { |
|
|
|
|
console.log(`Not a valid response, from the avatar url: ${ dataURI }`); |
|
|
|
|
throw new Meteor.Error('error-avatar-invalid-url', `Invalid avatar URL: ${ dataURI }`, { function: 'setUserAvatar', url: dataURI }); |
|
|
|
|
} |
|
|
|
|
} catch (error) { |
|
|
|
|
if (!error.response || error.response.statusCode !== 404) { |
|
|
|
|
console.log(`Error while handling the setting of the avatar from a url (${ dataURI }) for ${ user.username }:`, error); |
|
|
|
|
@ -26,12 +30,12 @@ export const setUserAvatar = function(user, dataURI, contentType, service) { |
|
|
|
|
|
|
|
|
|
if (result.statusCode !== 200) { |
|
|
|
|
console.log(`Not a valid response, ${ result.statusCode }, from the avatar url: ${ dataURI }`); |
|
|
|
|
throw new Meteor.Error('error-avatar-invalid-url', `Invalid avatar URL: ${ dataURI }`, { function: 'RocketChat.setUserAvatar', url: dataURI }); |
|
|
|
|
throw new Meteor.Error('error-avatar-invalid-url', `Invalid avatar URL: ${ dataURI }`, { function: 'setUserAvatar', url: dataURI }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!/image\/.+/.test(result.headers['content-type'])) { |
|
|
|
|
console.log(`Not a valid content-type from the provided url, ${ result.headers['content-type'] }, from the avatar url: ${ dataURI }`); |
|
|
|
|
throw new Meteor.Error('error-avatar-invalid-url', `Invalid avatar URL: ${ dataURI }`, { function: 'RocketChat.setUserAvatar', url: dataURI }); |
|
|
|
|
throw new Meteor.Error('error-avatar-invalid-url', `Invalid avatar URL: ${ dataURI }`, { function: 'setUserAvatar', url: dataURI }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
encoding = 'binary'; |
|
|
|
|
|