projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'tests/web/mastodon_api/search_controller' into 'develop'
[akkoma]
/
lib
/
pleroma
/
upload.ex
diff --git
a/lib/pleroma/upload.ex
b/lib/pleroma/upload.ex
index 1d8b073afc5db34f88865becefc38b6611fa7487..c47d6524111b3c40014b71b49a2a4d8d090f842d 100644
(file)
--- a/
lib/pleroma/upload.ex
+++ b/
lib/pleroma/upload.ex
@@
-4,7
+4,7
@@
defmodule Pleroma.Upload do
@moduledoc """
defmodule Pleroma.Upload do
@moduledoc """
- # Upload
+ Manage user uploads
Options:
* `:type`: presets for activity type (defaults to Document) and size limits from app configuration
Options:
* `:type`: presets for activity type (defaults to Document) and size limits from app configuration
@@
-34,8
+34,9
@@
defmodule Pleroma.Upload do
require Logger
@type source ::
require Logger
@type source ::
- Plug.Upload.t() | data_uri_string ::
- String.t() | {:from_local, name :: String.t(), id :: String.t(), path :: String.t()}
+ Plug.Upload.t()
+ | (data_uri_string :: String.t())
+ | {:from_local, name :: String.t(), id :: String.t(), path :: String.t()}
@type option ::
{:type, :avatar | :banner | :background}
@type option ::
{:type, :avatar | :banner | :background}
@@
-69,7
+70,7
@@
defmodule Pleroma.Upload do
%{
"type" => "Link",
"mediaType" => upload.content_type,
%{
"type" => "Link",
"mediaType" => upload.content_type,
- "href" => url_from_spec(opts.base_url, url_spec)
+ "href" => url_from_spec(
upload,
opts.base_url, url_spec)
}
],
"name" => Map.get(opts, :description) || upload.name
}
],
"name" => Map.get(opts, :description) || upload.name
@@
-84,6
+85,10
@@
defmodule Pleroma.Upload do
end
end
end
end
+ def char_unescaped?(char) do
+ URI.char_unreserved?(char) or char == ?/
+ end
+
defp get_opts(opts) do
{size_limit, activity_type} =
case Keyword.get(opts, :type) do
defp get_opts(opts) do
{size_limit, activity_type} =
case Keyword.get(opts, :type) do
@@
-123,10
+128,10
@@
defmodule Pleroma.Upload do
:pleroma, Pleroma.Upload, [filters: [Pleroma.Upload.Filter.Mogrify]]
:pleroma, Pleroma.Upload, [filters: [Pleroma.Upload.Filter.Mogrify]]
- :pleroma, Pleroma.Upload.Filter.Mogrify, args:
"strip"
+ :pleroma, Pleroma.Upload.Filter.Mogrify, args:
["strip", "auto-orient"]
""")
""")
- Pleroma.Config.put([Pleroma.Upload.Filter.Mogrify], args:
"strip"
)
+ Pleroma.Config.put([Pleroma.Upload.Filter.Mogrify], args:
["strip", "auto-orient"]
)
Map.put(opts, :filters, opts.filters ++ [Pleroma.Upload.Filter.Mogrify])
else
opts
Map.put(opts, :filters, opts.filters ++ [Pleroma.Upload.Filter.Mogrify])
else
opts
@@
-179,7
+184,7
@@
defmodule Pleroma.Upload do
end
# For Mix.Tasks.MigrateLocalUploads
end
# For Mix.Tasks.MigrateLocalUploads
- defp prepare_upload(
upload = %__MODULE__{tempfile: path}
, _opts) do
+ defp prepare_upload(
%__MODULE__{tempfile: path} = upload
, _opts) do
with {:ok, content_type} <- Pleroma.MIME.file_mime_type(path) do
{:ok, %__MODULE__{upload | content_type: content_type}}
end
with {:ok, content_type} <- Pleroma.MIME.file_mime_type(path) do
{:ok, %__MODULE__{upload | content_type: content_type}}
end
@@
-214,15
+219,18
@@
defmodule Pleroma.Upload do
tmp_path
end
tmp_path
end
- defp url_from_spec(base_url, {:file, path}) do
+ defp url_from_spec(
%__MODULE__{name: name},
base_url, {:file, path}) do
path =
path =
- path
- |> URI.encode()
- |> String.replace("?", "%3F")
+ URI.encode(path, &char_unescaped?/1) <>
+ if Pleroma.Config.get([__MODULE__, :link_name], false) do
+ "?name=#{URI.encode(name, &char_unescaped?/1)}"
+ else
+ ""
+ end
[base_url, "media", path]
|> Path.join()
end
[base_url, "media", path]
|> Path.join()
end
- defp url_from_spec(_base_url, {:url, url}), do: url
+ defp url_from_spec(_
upload, _
base_url, {:url, url}), do: url
end
end