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

25 lines
928 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(), 'contentType:', contentType, 'service:', service
user = Meteor.user()
if service is 'initials'
RocketChat.models.Users.setAvatarOrigin user._id, service
return
{image, contentType} = RocketChatFile.dataURIParse dataURI
rs = RocketChatFile.bufferToStream new Buffer(image, 'base64')
ws = RocketChatFileAvatarInstance.createWriteStream encodeURIComponent("#{user.username}.jpg"), contentType
ws.on 'end', Meteor.bindEnvironment ->
Meteor.setTimeout ->
RocketChat.models.Users.setAvatarOrigin user._id, service
RocketChat.Notifications.notifyAll 'updateAvatar', {username: user.username}
, 500
rs.pipe(ws)
return