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
397c8e58
Commit
397c8e58
authored
9 years ago
by
Rodrigo Nascimento
Browse files
Options
Downloads
Patches
Plain Diff
Expose Assets methods via RocketChat.Assets
parent
a779074a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/rocketchat-assets/server/assets.coffee
+52
-41
52 additions, 41 deletions
packages/rocketchat-assets/server/assets.coffee
with
52 additions
and
41 deletions
packages/rocketchat-assets/server/assets.coffee
+
52
−
41
View file @
397c8e58
...
...
@@ -10,11 +10,11 @@ mime.extensions['image/vnd.microsoft.icon'] = ['ico']
assets
=
'logo'
:
label
:
'logo (svg, png)'
label
:
'logo (svg, png
, jpg
)'
defaultUrl
:
'images/logo/logo.svg'
constraints
:
type
:
'image'
extensions
:
[
'svg'
,
'png'
]
extensions
:
[
'svg'
,
'png'
,
'jpg'
,
'jpeg'
]
width
:
undefined
height
:
undefined
'favicon'
:
...
...
@@ -75,6 +75,52 @@ assets =
height
:
256
RocketChat
.
Assets
=
new
class
setAsset
:
(
binaryContent
,
contentType
,
asset
)
->
if
not
assets
[
asset
]
?
throw
new
Meteor
.
Error
"Invalid_asset"
extension
=
mime
.
extension
(
contentType
)
if
extension
not
in
assets
[
asset
].
constraints
.
extensions
throw
new
Meteor
.
Error
"Invalid_file_type"
,
contentType
file
=
new
Buffer
(
binaryContent
,
'binary'
)
if
assets
[
asset
].
constraints
.
width
?
or
assets
[
asset
].
constraints
.
height
?
dimensions
=
sizeOf
file
if
assets
[
asset
].
constraints
.
width
?
and
assets
[
asset
].
constraints
.
width
isnt
dimensions
.
width
throw
new
Meteor
.
Error
"Invalid_file_width"
if
assets
[
asset
].
constraints
.
height
?
and
assets
[
asset
].
constraints
.
height
isnt
dimensions
.
height
throw
new
Meteor
.
Error
"Invalid_file_height"
rs
=
RocketChatFile
.
bufferToStream
file
RocketChatAssetsInstance
.
deleteFile
asset
ws
=
RocketChatAssetsInstance
.
createWriteStream
asset
,
contentType
ws
.
on
'end'
,
Meteor
.
bindEnvironment
->
Meteor
.
setTimeout
->
RocketChat
.
settings
.
updateById
"Assets_
#{
asset
}
"
,
{
url
:
"/assets/
#{
asset
}
.
#{
extension
}
"
defaultUrl
:
assets
[
asset
].
defaultUrl
}
,
200
rs
.
pipe
ws
return
unsetAsset
:
(
asset
)
->
if
not
assets
[
asset
]
?
throw
new
Meteor
.
Error
"Invalid_asset"
RocketChatAssetsInstance
.
deleteFile
asset
RocketChat
.
settings
.
updateById
"Assets_
#{
asset
}
"
,
{
defaultUrl
:
assets
[
asset
].
defaultUrl
}
return
refreshClients
:
->
process
.
emit
(
'message'
,
{
refresh
:
'client'
})
RocketChat
.
settings
.
addGroup
'Assets'
for
key
,
value
of
assets
do
(
key
,
value
)
->
...
...
@@ -175,9 +221,9 @@ Meteor.methods
unless
hasPermission
throw
new
Meteor
.
Error
'manage-assets-not-allowed'
,
"[methods] unsetAsset -> Manage assets not allowed"
process
.
emit
(
'message'
,
{
refresh
:
'client'
})
RocketChat
.
Assets
.
refreshClients
Meteor
.
methods
unsetAsset
:
(
asset
)
->
unless
Meteor
.
userId
()
throw
new
Meteor
.
Error
'invalid-user'
,
"[methods] unsetAsset -> Invalid user"
...
...
@@ -186,15 +232,9 @@ Meteor.methods
unless
hasPermission
throw
new
Meteor
.
Error
'manage-assets-not-allowed'
,
"[methods] unsetAsset -> Manage assets not allowed"
if
not
assets
[
asset
]
?
throw
new
Meteor
.
Error
"Invalid_asset"
RocketChatAssetsInstance
.
deleteFile
asset
RocketChat
.
settings
.
updateById
"Assets_
#{
asset
}
"
,
{
defaultUrl
:
assets
[
asset
].
defaultUrl
}
RocketChat
.
Assets
.
unsetAsset
asset
Meteor
.
methods
setAsset
:
(
binaryContent
,
contentType
,
asset
)
->
unless
Meteor
.
userId
()
throw
new
Meteor
.
Error
'invalid-user'
,
"[methods] setAsset -> Invalid user"
...
...
@@ -203,36 +243,7 @@ Meteor.methods
unless
hasPermission
throw
new
Meteor
.
Error
'manage-assets-not-allowed'
,
"[methods] unsetAsset -> Manage assets not allowed"
if
not
assets
[
asset
]
?
throw
new
Meteor
.
Error
"Invalid_asset"
extension
=
mime
.
extension
(
contentType
)
if
extension
not
in
assets
[
asset
].
constraints
.
extensions
throw
new
Meteor
.
Error
"Invalid_file_type"
,
contentType
file
=
new
Buffer
(
binaryContent
,
'binary'
)
if
assets
[
asset
].
constraints
.
width
?
or
assets
[
asset
].
constraints
.
height
?
dimensions
=
sizeOf
file
if
assets
[
asset
].
constraints
.
width
?
and
assets
[
asset
].
constraints
.
width
isnt
dimensions
.
width
throw
new
Meteor
.
Error
"Invalid_file_width"
if
assets
[
asset
].
constraints
.
height
?
and
assets
[
asset
].
constraints
.
height
isnt
dimensions
.
height
throw
new
Meteor
.
Error
"Invalid_file_height"
rs
=
RocketChatFile
.
bufferToStream
file
RocketChatAssetsInstance
.
deleteFile
asset
ws
=
RocketChatAssetsInstance
.
createWriteStream
asset
,
contentType
ws
.
on
'end'
,
Meteor
.
bindEnvironment
->
Meteor
.
setTimeout
->
RocketChat
.
settings
.
updateById
"Assets_
#{
asset
}
"
,
{
url
:
"/assets/
#{
asset
}
.
#{
extension
}
"
defaultUrl
:
assets
[
asset
].
defaultUrl
}
,
200
rs
.
pipe
ws
RocketChat
.
Assets
.
setAsset
binaryContent
,
contentType
,
asset
return
...
...
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