X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fupload.ex;h=762d813d98a279f409f248e148a5742a26a0e9d7;hb=cb1a3e196cc752fef4e73b0bfb4b2d02b71e0535;hp=ce2a1b69633344607415767f4d58bb9ffdfda8af;hpb=3a3a3996b7a37d281745586fa40bbabd5299a1ce;p=akkoma
diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex
index ce2a1b696..762d813d9 100644
--- a/lib/pleroma/upload.ex
+++ b/lib/pleroma/upload.ex
@@ -1,10 +1,10 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2020 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
@@ -37,6 +37,7 @@ defmodule Pleroma.Upload do
Plug.Upload.t()
| (data_uri_string :: String.t())
| {:from_local, name :: String.t(), id :: String.t(), path :: String.t()}
+ | map()
@type option ::
{:type, :avatar | :banner | :background}
@@ -70,7 +71,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
@@ -85,6 +86,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
@@ -101,7 +106,7 @@ defmodule Pleroma.Upload do
{Pleroma.Config.get!([:instance, :upload_limit]), "Document"}
end
- opts = %{
+ %{
activity_type: Keyword.get(opts, :activity_type, activity_type),
size_limit: Keyword.get(opts, :size_limit, size_limit),
uploader: Keyword.get(opts, :uploader, Pleroma.Config.get([__MODULE__, :uploader])),
@@ -114,37 +119,6 @@ defmodule Pleroma.Upload do
Pleroma.Config.get([__MODULE__, :base_url], Pleroma.Web.base_url())
)
}
-
- # TODO: 1.0+ : remove old config compatibility
- opts =
- if Pleroma.Config.get([__MODULE__, :strip_exif]) == true &&
- !Enum.member?(opts.filters, Pleroma.Upload.Filter.Mogrify) do
- Logger.warn("""
- Pleroma: configuration `:instance, :strip_exif` is deprecated, please instead set:
-
- :pleroma, Pleroma.Upload, [filters: [Pleroma.Upload.Filter.Mogrify]]
-
- :pleroma, Pleroma.Upload.Filter.Mogrify, args: ["strip", "auto-orient"]
- """)
-
- Pleroma.Config.put([Pleroma.Upload.Filter.Mogrify], args: ["strip", "auto-orient"])
- Map.put(opts, :filters, opts.filters ++ [Pleroma.Upload.Filter.Mogrify])
- else
- opts
- end
-
- if Pleroma.Config.get([:instance, :dedupe_media]) == true &&
- !Enum.member?(opts.filters, Pleroma.Upload.Filter.Dedupe) do
- Logger.warn("""
- Pleroma: configuration `:instance, :dedupe_media` is deprecated, please instead set:
-
- :pleroma, Pleroma.Upload, [filters: [Pleroma.Upload.Filter.Dedupe]]
- """)
-
- Map.put(opts, :filters, opts.filters ++ [Pleroma.Upload.Filter.Dedupe])
- else
- opts
- end
end
defp prepare_upload(%Plug.Upload{} = file, opts) do
@@ -180,7 +154,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
@@ -215,16 +189,25 @@ 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 =
- path
- |> URI.encode()
- |> String.replace("?", "%3F")
- |> String.replace(":", "%3A")
+ URI.encode(path, &char_unescaped?/1) <>
+ if Pleroma.Config.get([__MODULE__, :link_name], false) do
+ "?name=#{URI.encode(name, &char_unescaped?/1)}"
+ else
+ ""
+ end
+
+ prefix =
+ if is_nil(Pleroma.Config.get([__MODULE__, :base_url])) do
+ "media"
+ else
+ ""
+ end
- [base_url, "media", path]
+ [base_url, prefix, 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