The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/server/methods/setAvatarFromService.coffee

22 lines
790 B

Meteor.methods
setAvatarFromService: (dataURI, contentType, service) ->
if not Meteor.userId()
throw new Meteor.Error('invalid-user', "[methods] setAvatarFromService -> Invalid user")
console.log '[methods] setAvatarFromService -> '.green, 'userId:', Meteor.userId(), 'arguments:', arguments
user = Meteor.user()
if service is 'initials'
Meteor.users.update {_id: user._id}, {$set: {avatarOrigin: service}}
return
{image, contentType} = RocketChatFile.dataURIParse dataURI
rs = RocketChatFile.bufferToStream new Buffer(image, 'base64')
ws = RocketChatFileAvatarInstance.createWriteStream "#{user.username}.jpg", contentType
ws.on 'end', Meteor.bindEnvironment ->
Meteor.users.update {_id: user._id}, {$set: {avatarOrigin: service}}
rs.pipe(ws)
return