Skip to content
Snippets Groups Projects
Commit 61ef96ce authored by graywolf336's avatar graywolf336
Browse files

Allow the avatars to be set via a provided url, must currently be a jpg

parent 2efecc79
No related branches found
No related tags found
No related merge requests found
......@@ -109,3 +109,4 @@ yasaricli:slugify
yasinuslu:blaze-meta
# sanjo:jasmine
# velocity:html-reporter
froatsnook:request
......@@ -42,6 +42,7 @@ email@1.0.7
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.6
......
......@@ -43,6 +43,15 @@ Template.avatarPrompt.events
toastr.error t('Error_too_many_requests', parseInt(err.details.timeToReset / 1000))
else
toastr.success t('Avatar_changed_successfully')
else if @service is 'url'
if _.trim $('#avatarurl').val()
Meteor.call 'setAvatarFromService', $('#avatarurl').val(), '', @service, (err) ->
if err?.details?.timeToReset?
toastr.error t('Error_too_many_requests', parseInt(err.details.timeToReset / 1000))
else
toastr.success t('Avatar_changed_successfully')
else
toastr.error t('Please_enter_value_for_url')
else
Meteor.call 'setAvatarFromService', @blob, @contentType, @service, (err) ->
if err?.details?.timeToReset?
......
......@@ -58,6 +58,17 @@
{{/unless}}
</div>
</div>
<div class="avatar-suggestion-item">
{{#with service='url'}}
<div class="avatar question-mark icon-upload"></div>
<div class="action">
<div class="input-line">
<input type="text" name="avatarurl" id="avatarurl" />
<button type="button" class="button primary select-service">{{_ "Use_url_for_avatar"}}</button>
</div>
</div>
{{/with}}
</div>
{{#if suggestions.ready}}
{{> avatarSuggestion suggestions.avatars.gravatar}}
......
......@@ -265,6 +265,7 @@
"Please_wait" : "Please wait",
"Please_wait_activation" : "Please wait, this can take some time.",
"Please_wait_statistics" : "Please wait, statistics are being generated.",
"Please_enter_value_for_url": "Please enter a value for the url of your avatar.",
"Powered_by" : "Powered by",
"Preferences" : "Preferences",
"Preferences_saved" : "Preferences saved",
......@@ -386,6 +387,7 @@
"Use_service_avatar" : "Use %s avatar",
"Use_this_username" : "Use this username",
"Use_uploaded_avatar" : "Use uploaded avatar",
"Use_url_for_avatar": "Use url for avatar",
"User_added" : "User <em>__user_added__</em> added.",
"User_added_by" : "User <em>__user_added__</em> added by <em>__user_by__</em>.",
"User_Channels" : "User Channels",
......@@ -428,4 +430,4 @@
"You_will_not_be_able_to_recover" : "You will not be able to recover this message!",
"Your_entry_has_been_deleted" : "Your entry has been deleted.",
"Your_Open_Source_solution" : "Your own Open Source chat solution"
}
\ No newline at end of file
}
......@@ -11,6 +11,29 @@ Meteor.methods
RocketChat.models.Users.setAvatarOrigin user._id, service
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)
return
{image, contentType} = RocketChatFile.dataURIParse dataURI
rs = RocketChatFile.bufferToStream new Buffer(image, 'base64')
......
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