Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Rocket.Chat
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RocketChat
Rocket.Chat
Commits
dad3469f
Commit
dad3469f
authored
9 years ago
by
Rodrigo Nascimento
Browse files
Options
Downloads
Patches
Plain Diff
Create migration to repopulate all avatars
parent
24fa9604
No related branches found
No related tags found
Loading
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
server/startup/migrations/v0.1.2.coffee
+19
-17
19 additions, 17 deletions
server/startup/migrations/v0.1.2.coffee
with
19 additions
and
17 deletions
server/startup/migrations/v0.1.2.coffee
+
19
−
17
View file @
dad3469f
#
Meteor.startup ->
#
Migrations.add
#
version: new Date("2015-06-0
1
T00:
26:05.197
Z").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-0
3
T00:
49:41.269
Z"
).
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment