Skip to content
Snippets Groups Projects
Commit dad3469f authored by Rodrigo Nascimento's avatar Rodrigo Nascimento
Browse files

Create migration to repopulate all avatars

parent 24fa9604
No related branches found
No related tags found
Loading
# Meteor.startup ->
# Migrations.add
# version: new Date("2015-06-01T00:26:05.197Z").getTime()
# up: ->
# Meteor.users.find({avatarOrigin: {$exists: false}, username: {$exists: true}}).forEach (user) ->
# avatars = getAvatarSuggestionForUser user
Meteor.startup ->
Migrations.add
version: new Date("2015-06-03T00:49:41.269Z").getTime()
up: ->
Meteor.users.find({avatarOrigin: {$exists: false}, username: {$exists: true}}).forEach (user) ->
avatars = getAvatarSuggestionForUser user
# services = Object.keys avatars
services = Object.keys avatars
# if services.length is 0
# return
if services.length is 0
return
# service = services[0]
# console.log user.username, '->', service
service = services[0]
console.log user.username, '->', service
# blob = avatars[service].blob
dataURI = avatars[service].blob
# file = new FS.File blob
# file.attachData blob, ->
# file.name user.username
{image, contentType} = RocketFile.dataURIParse dataURI
# Avatars.insert file, (err, fileObj) ->
# Meteor.users.update {_id: user._id}, {$set: {avatarOrigin: service}}
\ No newline at end of file
rs = RocketFile.bufferToStream new Buffer(image, 'base64')
ws = RocketFileAvatarInstance.createWriteStream "#{user.username}.jpg", contentType
ws.on 'end', Meteor.bindEnvironment ->
Meteor.users.update {_id: user._id}, {$set: {avatarOrigin: service}}
rs.pipe(ws)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment