diff --git a/.meteor/packages b/.meteor/packages index 59a9aa4b678..d16b2be6adf 100644 --- a/.meteor/packages +++ b/.meteor/packages @@ -109,5 +109,4 @@ yasaricli:slugify yasinuslu:blaze-meta # sanjo:jasmine # velocity:html-reporter -froatsnook:request rocketchat:tutum diff --git a/.meteor/versions b/.meteor/versions index 61f7761f8f5..b2a52c59f3e 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -42,7 +42,6 @@ email@1.0.8 facebook@1.2.2 fastclick@1.0.7 francocatena:status@1.5.0 -froatsnook:request@2.64.0 geojson-utils@1.0.4 github@1.1.4 google@1.1.7 diff --git a/server/methods/setAvatarFromService.coffee b/server/methods/setAvatarFromService.coffee index efe29b838d6..cdcd27f5b3d 100644 --- a/server/methods/setAvatarFromService.coffee +++ b/server/methods/setAvatarFromService.coffee @@ -12,26 +12,25 @@ Meteor.methods return if service is 'url' - headReq = request.headSync dataURI - - if headReq.response.statusCode != 200 - console.log "Not a valid response, #{headReq.response.statusCode}, from the avatar url:", dataURI - throw new Meteor.Error('invalid-avatar-url', '[methods] setAvatarFromService -> url service -> error on checking the image type') - - if headReq.response.headers['content-type'] isnt 'image/jpeg' - throw new Meteor.Error('invalid-image-url', '[methods] setAvatarFromService -> url service -> Invalid url, it is not a jpeg') - - image = request.getSync dataURI, { encoding: null } - ars = RocketChatFile.bufferToStream image.body - aws = RocketChatFileAvatarInstance.createWriteStream "#{user.username}.jpg", headReq.response.headers['content-type'] - aws.on 'end', Meteor.bindEnvironment -> - Meteor.setTimeout -> - console.log "Set #{user.username}'s avatar from the url: #{dataURI}" - RocketChat.models.Users.setAvatarOrigin user._id, service - RocketChat.Notifications.notifyAll 'updateAvatar', { username: user.username } - , 500 - - ars.pipe(aws) + try + result = HTTP.get dataURI, npmRequestOptions: {encoding: 'binary'} + + if result.statusCode isnt 200 + console.log "Not a valid response, #{result.statusCode}, from the avatar url: #{dataURI}" + throw new Meteor.Error('invalid-avatar-url', '[methods] setAvatarFromService -> url service -> error on getting the avatar from url') + + ars = RocketChatFile.bufferToStream new Buffer(result.content, 'binary') + aws = RocketChatFileAvatarInstance.createWriteStream "#{user.username}.jpg", result.headers['content-type'] + aws.on 'end', Meteor.bindEnvironment -> + Meteor.setTimeout -> + console.log "Set #{user.username}'s avatar from the url: #{dataURI}" + RocketChat.models.Users.setAvatarOrigin user._id, service + RocketChat.Notifications.notifyAll 'updateAvatar', { username: user.username } + , 500 + + ars.pipe(aws) + catch e + throw e return {image, contentType} = RocketChatFile.dataURIParse dataURI