X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fupload.ex;h=c47d6524111b3c40014b71b49a2a4d8d090f842d;hb=42422f3ff2d3a918f04e2d73b8d2f6867a51b5a7;hp=744abec56cdb2b913155ce560958c5bf7f9b09ec;hpb=2791ce9a1ff2365ac7256f5e1dc2324dee2f82c9;p=akkoma
diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex
index 744abec56..c47d65241 100644
--- a/lib/pleroma/upload.ex
+++ b/lib/pleroma/upload.ex
@@ -1,10 +1,10 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Upload do
@moduledoc """
- # Upload
+ Manage user uploads
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 ::
- 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}
@@ -69,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(upload, opts.base_url, url_spec)
}
],
"name" => Map.get(opts, :description) || upload.name
@@ -84,6 +85,10 @@ defmodule Pleroma.Upload do
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
@@ -123,10 +128,10 @@ defmodule Pleroma.Upload do
: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
@@ -179,7 +184,7 @@ defmodule Pleroma.Upload do
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
@@ -214,10 +219,18 @@ defmodule Pleroma.Upload do
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 =
+ 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
- defp url_from_spec(_base_url, {:url, url}), do: url
+ defp url_from_spec(_upload, _base_url, {:url, url}), do: url
end