aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorrinpatch <rinpatch@sdf.org>2019-03-12 09:10:19 +0300
committerrinpatch <rinpatch@sdf.org>2019-03-12 09:10:19 +0300
commit5a73cae2be8e9b490ed4a610347998f1120740f0 (patch)
tree6fbfb750916b4df54d98c3c6cbb065025485ab4d /lib
parent8e6b8506105a304bca9159bfcd5cc7cb9516e387 (diff)
downloadpleroma-5a73cae2be8e9b490ed4a610347998f1120740f0.tar.gz
WIP: Stop mangling filenames
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/plugs/uploaded_media.ex10
-rw-r--r--lib/pleroma/upload.ex10
2 files changed, 14 insertions, 6 deletions
diff --git a/lib/pleroma/plugs/uploaded_media.ex b/lib/pleroma/plugs/uploaded_media.ex
index 13aa8641a..15f447ded 100644
--- a/lib/pleroma/plugs/uploaded_media.ex
+++ b/lib/pleroma/plugs/uploaded_media.ex
@@ -24,6 +24,16 @@ defmodule Pleroma.Plugs.UploadedMedia do
end
def call(%{request_path: <<"/", @path, "/", file::binary>>} = conn, opts) do
+ conn =
+ case fetch_query_params(conn) do
+ %{query_params: %{"name" => name}} = conn ->
+ conn
+ |> put_resp_header("Content-Disposition", "filename=\"#{name}\"")
+
+ conn ->
+ conn
+ end
+
config = Pleroma.Config.get([Pleroma.Upload])
with uploader <- Keyword.fetch!(config, :uploader),
diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex
index 1a97e9fde..ae461d434 100644
--- a/lib/pleroma/upload.ex
+++ b/lib/pleroma/upload.ex
@@ -70,7 +70,7 @@ defmodule Pleroma.Upload do
%{
"type" => "Link",
"mediaType" => upload.content_type,
- "href" => url_from_spec(opts.base_url, url_spec)
+ "href" => url_from_spec(opts.base_url, url_spec, upload.name)
}
],
"name" => Map.get(opts, :description) || upload.name
@@ -219,14 +219,12 @@ defmodule Pleroma.Upload do
tmp_path
end
- defp url_from_spec(base_url, {:file, path}) do
- path =
- path
- |> URI.encode(&char_unescaped?/1)
+ defp url_from_spec(base_url, {:file, path}, name) do
+ path = URI.encode(path, &char_unescaped?/1) <> "?name=#{URI.encode(name, &char_unescaped?/1)}"
[base_url, "media", path]
|> Path.join()
end
- defp url_from_spec(_base_url, {:url, url}), do: url
+ defp url_from_spec(_base_url, {:url, url}, _name), do: url
end