Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pleroma
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
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
Nick Thomas
pleroma
Commits
e942e1e5
Commit
e942e1e5
authored
7 years ago
by
eal
Browse files
Options
Downloads
Patches
Plain Diff
Correct mimetype on bad uploads.
parent
77e272df
Branches
1079-unsuccessful-message-deliveries-tracking
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
+9
-1
9 additions, 1 deletion
lib/pleroma/upload.ex
test/upload_test.exs
+12
-0
12 additions, 0 deletions
test/upload_test.exs
with
21 additions
and
1 deletion
lib/pleroma/upload.ex
+
9
−
1
View file @
e942e1e5
...
...
@@ -8,11 +8,19 @@ defmodule Pleroma.Upload do
result_file
=
Path
.
join
(
upload_folder
,
file
.
filename
)
File
.
cp!
(
file
.
path
,
result_file
)
# fix content type on some image uploads
matches
=
Regex
.
named_captures
(
~r/\.(?<ext>(jpg|jpeg|png|gif))$/i
,
file
.
filename
)
content_type
=
if
file
.
content_type
==
"application/octet-stream"
and
matches
do
if
matches
[
"ext"
]
==
"jpg"
,
do
:
"image/jpeg"
,
else
:
"image/
#{
matches
[
"ext"
]
}
"
else
file
.
content_type
end
%{
"type"
=>
"Image"
,
"url"
=>
[%{
"type"
=>
"Link"
,
"mediaType"
=>
file
.
content_type
,
"mediaType"
=>
content_type
,
"href"
=>
url_for
(
Path
.
join
(
uuid
,
:cow_uri
.
urlencode
(
file
.
filename
)))
}],
"name"
=>
file
.
filename
,
...
...
This diff is collapsed.
Click to expand it.
test/upload_test.exs
+
12
−
0
View file @
e942e1e5
...
...
@@ -9,5 +9,17 @@ defmodule Pleroma.UploadTest do
assert
data
[
"name"
]
==
"an [image.jpg"
assert
List
.
first
(
data
[
"url"
])[
"href"
]
==
"http://localhost:4001/media/
#{
data
[
"uuid"
]
}
/an%20%5Bimage.jpg"
end
test
"fixes an incorrect content type"
do
file
=
%
Plug
.
Upload
{
content_type:
"application/octet-stream"
,
path:
Path
.
absname
(
"test/fixtures/image.jpg"
),
filename:
"an [image.jpg"
}
data
=
Upload
.
store
(
file
)
assert
hd
(
data
[
"url"
])[
"mediaType"
]
==
"image/jpeg"
end
test
"does not modify a valid content type"
do
file
=
%
Plug
.
Upload
{
content_type:
"image/png"
,
path:
Path
.
absname
(
"test/fixtures/image.jpg"
),
filename:
"an [image.jpg"
}
data
=
Upload
.
store
(
file
)
assert
hd
(
data
[
"url"
])[
"mediaType"
]
==
"image/png"
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