WIP: Stop mangling filenames
This commit is contained in:
parent
8e6b850610
commit
5a73cae2be
2 changed files with 14 additions and 6 deletions
|
@ -24,6 +24,16 @@ defmodule Pleroma.Plugs.UploadedMedia do
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(%{request_path: <<"/", @path, "/", file::binary>>} = conn, opts) do
|
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])
|
config = Pleroma.Config.get([Pleroma.Upload])
|
||||||
|
|
||||||
with uploader <- Keyword.fetch!(config, :uploader),
|
with uploader <- Keyword.fetch!(config, :uploader),
|
||||||
|
|
|
@ -70,7 +70,7 @@ defmodule Pleroma.Upload do
|
||||||
%{
|
%{
|
||||||
"type" => "Link",
|
"type" => "Link",
|
||||||
"mediaType" => upload.content_type,
|
"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
|
"name" => Map.get(opts, :description) || upload.name
|
||||||
|
@ -219,14 +219,12 @@ defmodule Pleroma.Upload do
|
||||||
tmp_path
|
tmp_path
|
||||||
end
|
end
|
||||||
|
|
||||||
defp url_from_spec(base_url, {:file, path}) do
|
defp url_from_spec(base_url, {:file, path}, name) do
|
||||||
path =
|
path = URI.encode(path, &char_unescaped?/1) <> "?name=#{URI.encode(name, &char_unescaped?/1)}"
|
||||||
path
|
|
||||||
|> URI.encode(&char_unescaped?/1)
|
|
||||||
|
|
||||||
[base_url, "media", path]
|
[base_url, "media", path]
|
||||||
|> Path.join()
|
|> Path.join()
|
||||||
end
|
end
|
||||||
|
|
||||||
defp url_from_spec(_base_url, {:url, url}), do: url
|
defp url_from_spec(_base_url, {:url, url}, _name), do: url
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue