Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pleroma
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
kaniini
pleroma
Commits
0a95b559
Commit
0a95b559
authored
6 years ago
by
normandy
Browse files
Options
Downloads
Patches
Plain Diff
Add missing file extension if file does not have one
parent
678df59d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/pleroma/upload.ex
+24
-5
24 additions, 5 deletions
lib/pleroma/upload.ex
test/upload_test.exs
+13
-0
13 additions, 0 deletions
test/upload_test.exs
with
37 additions
and
5 deletions
lib/pleroma/upload.ex
+
24
−
5
View file @
0a95b559
...
...
@@ -86,10 +86,15 @@ defmodule Pleroma.Upload do
end
defp
create_name
(
uuid
,
ext
,
type
)
do
if
type
==
"application/octet-stream"
do
String
.
downcase
(
Enum
.
join
([
uuid
,
ext
],
"."
))
else
String
.
downcase
(
Enum
.
join
([
uuid
,
List
.
last
(
String
.
split
(
type
,
"/"
))],
"."
))
case
type
do
"application/octet-stream"
->
String
.
downcase
(
Enum
.
join
([
uuid
,
ext
],
"."
))
"audio/mpeg"
->
String
.
downcase
(
Enum
.
join
([
uuid
,
"mp3"
],
"."
))
_
->
String
.
downcase
(
Enum
.
join
([
uuid
,
List
.
last
(
String
.
split
(
type
,
"/"
))],
"."
))
end
end
...
...
@@ -105,7 +110,21 @@ defmodule Pleroma.Upload do
if
should_dedupe
do
create_name
(
uuid
,
List
.
last
(
String
.
split
(
file
.
filename
,
"."
)),
type
)
else
file
.
filename
unless
String
.
contains?
(
file
.
filename
,
"."
)
do
case
type
do
"image/png"
->
file
.
filename
<>
".png"
"image/jpeg"
->
file
.
filename
<>
".jpg"
"image/gif"
->
file
.
filename
<>
".gif"
"video/webm"
->
file
.
filename
<>
".webm"
"video/mp4"
->
file
.
filename
<>
".mp4"
"audio/mpeg"
->
file
.
filename
<>
".mp3"
"audio/ogg"
->
file
.
filename
<>
".ogg"
"audio/wav"
->
file
.
filename
<>
".wav"
_
->
file
.
filename
end
else
file
.
filename
end
end
end
...
...
This diff is collapsed.
Click to expand it.
test/upload_test.exs
+
13
−
0
View file @
0a95b559
...
...
@@ -43,5 +43,18 @@ defmodule Pleroma.UploadTest do
data
=
Upload
.
store
(
file
,
true
)
assert
hd
(
data
[
"url"
])[
"mediaType"
]
==
"image/jpeg"
end
test
"adds missing extension"
do
File
.
cp!
(
"test/fixtures/image.jpg"
,
"test/fixtures/image_tmp.jpg"
)
file
=
%
Plug
.
Upload
{
content_type:
"image/jpg"
,
path:
Path
.
absname
(
"test/fixtures/image_tmp.jpg"
),
filename:
"an [image"
}
data
=
Upload
.
store
(
file
,
false
)
assert
data
[
"name"
]
==
"an [image.jpg"
end
end
end
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