Remove reference to request and instead use the http module

pull/1265/head
graywolf336 10 years ago
parent 8927bbecc1
commit 3eb818d3d3
  1. 1
      .meteor/packages
  2. 1
      .meteor/versions
  3. 39
      server/methods/setAvatarFromService.coffee

@ -109,5 +109,4 @@ yasaricli:slugify
yasinuslu:blaze-meta
# sanjo:jasmine
# velocity:html-reporter
froatsnook:request
rocketchat:tutum

@ -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

@ -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

Loading…
Cancel
Save