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
47881d65
Unverified
Commit
47881d65
authored
8 years ago
by
Aaron Ogle
Browse files
Options
Downloads
Patches
Plain Diff
If file is not an image / audio / video or larger then 10 mb don't try and show a preview
parent
c732a803
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/rocketchat-ui/client/lib/fileUpload.coffee
+55
-18
55 additions, 18 deletions
packages/rocketchat-ui/client/lib/fileUpload.coffee
with
55 additions
and
18 deletions
packages/rocketchat-ui/client/lib/fileUpload.coffee
+
55
−
18
View file @
47881d65
...
...
@@ -5,6 +5,31 @@ readAsDataURL = (file, callback) ->
reader
.
readAsDataURL
file
getUploadPreview
=
(
file
,
callback
)
->
if
file
.
file
.
type
.
indexOf
(
'audio'
)
>
-
1
or
file
.
file
.
type
.
indexOf
(
'video'
)
>
-
1
or
file
.
file
.
type
.
indexOf
(
'image'
)
>
-
1
file
.
type
=
file
.
file
.
type
.
split
(
'/'
)[
0
]
readAsDataURL
file
.
file
,
(
content
)
->
callback
(
file
,
content
)
else
callback
(
file
,
null
)
formatBytes
=
(
bytes
,
decimals
)
->
if
bytes
==
0
return
'0 Bytes'
k
=
1000
dm
=
decimals
+
1
or
3
sizes
=
[
'Bytes'
'KB'
'MB'
'GB'
'TB'
'PB'
]
i
=
Math
.
floor
(
Math
.
log
(
bytes
)
/
Math
.
log
(
k
))
parseFloat
((
bytes
/
k
**
i
).
toFixed
(
dm
))
+
' '
+
sizes
[
i
]
readAsArrayBuffer
=
(
file
,
callback
)
->
reader
=
new
FileReader
()
reader
.
onload
=
(
ev
)
->
...
...
@@ -23,29 +48,29 @@ readAsArrayBuffer = (file, callback) ->
swal
.
close
()
return
readAsDataURL
file
.
file
,
(
fileContent
)
->
if
not
RocketChat
.
fileUploadIsValidContentType
file
.
file
.
type
swal
title
:
t
(
'FileUpload_MediaType_NotAccepted'
)
text
:
file
.
file
.
type
||
"*.
#{
s
.
strRightBack
(
file
.
file
.
name
,
'.'
)
}
"
type
:
'error'
timer
:
3000
return
if
file
.
file
.
size
is
0
swal
title
:
t
(
'FileUpload_File_Empty'
)
type
:
'error'
timer
:
1000
return
if
not
RocketChat
.
fileUploadIsValidContentType
file
.
file
.
type
swal
title
:
t
(
'FileUpload_MediaType_NotAccepted'
)
text
:
file
.
file
.
type
||
"*.
#{
s
.
strRightBack
(
file
.
file
.
name
,
'.'
)
}
"
type
:
'error'
timer
:
3000
return
if
file
.
file
.
size
is
0
swal
title
:
t
(
'FileUpload_File_Empty'
)
type
:
'error'
timer
:
1000
return
getUploadPreview
file
,
(
file
,
preview
)
->
text
=
''
if
file
.
type
is
'audio'
text
=
"""
<div class='upload-preview'>
<audio style="width: 100%;" controls="controls">
<source src="
#{
fileContent
}
" type="audio/wav">
<source src="
#{
preview
}
" type="audio/wav">
Your browser does not support the audio element.
</audio>
</div>
...
...
@@ -58,7 +83,7 @@ readAsArrayBuffer = (file, callback) ->
text
=
"""
<div class='upload-preview'>
<video style="width: 100%;" controls="controls">
<source src="
#{
fileContent
}
" type="video/webm">
<source src="
#{
preview
}
" type="video/webm">
Your browser does not support the video element.
</video>
</div>
...
...
@@ -67,10 +92,22 @@ readAsArrayBuffer = (file, callback) ->
<input id='file-description' style='display: inherit;' value='' placeholder='
#{
t
(
"Upload_file_description"
)
}
'>
</div>
"""
else
if
file
.
type
is
'image'
text
=
"""
<div class='upload-preview'>
<div class='upload-preview-file' style='background-image: url(
#{
preview
}
)'></div>
</div>
<div class='upload-preview-title'>
<input id='file-name' style='display: inherit;' value='
#{
Handlebars
.
_escape
(
file
.
name
)
}
' placeholder='
#{
t
(
"Upload_file_name"
)
}
'>
<input id='file-description' style='display: inherit;' value='' placeholder='
#{
t
(
"Upload_file_description"
)
}
'>
</div>
"""
else
fileSize
=
formatBytes
(
file
.
file
.
size
)
text
=
"""
<div class='upload-preview'>
<div
class='upload-preview-file' style='background-image: url(
#{
fileContent
}
)'>
</div>
<div
>
#{
Handlebars
.
_escape
(
file
.
name
)
}
-
#{
fileSize
}
</div>
</div>
<div class='upload-preview-title'>
<input id='file-name' style='display: inherit;' value='
#{
Handlebars
.
_escape
(
file
.
name
)
}
' placeholder='
#{
t
(
"Upload_file_name"
)
}
'>
...
...
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