X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fupload%2Ffilter%2Fanonymize_filename.ex;h=7e62b3d136e046ab728617d1954cd6a04008a384;hb=52fc59f125c10ad73b9fd1a0639b6dc5681776ca;hp=5ca53a79ba46ac7609a24e2e00ffc74c47bcec0d;hpb=b73a1a33de76dc848037a5d0e951866bd21f92c4;p=akkoma
diff --git a/lib/pleroma/upload/filter/anonymize_filename.ex b/lib/pleroma/upload/filter/anonymize_filename.ex
index 5ca53a79b..7e62b3d13 100644
--- a/lib/pleroma/upload/filter/anonymize_filename.ex
+++ b/lib/pleroma/upload/filter/anonymize_filename.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Upload.Filter.AnonymizeFilename do
@@ -10,10 +10,21 @@ defmodule Pleroma.Upload.Filter.AnonymizeFilename do
"""
@behaviour Pleroma.Upload.Filter
- def filter(upload) do
- extension = List.last(String.split(upload.name, "."))
- name = Pleroma.Config.get([__MODULE__, :text], random(extension))
- {:ok, %Pleroma.Upload{upload | name: name}}
+ alias Pleroma.Config
+ alias Pleroma.Upload
+
+ def filter(%Upload{name: name} = upload) do
+ extension = List.last(String.split(name, "."))
+ name = predefined_name(extension) || random(extension)
+ {:ok, :filtered, %Upload{upload | name: name}}
+ end
+
+ def filter(_), do: {:ok, :noop}
+
+ @spec predefined_name(String.t()) :: String.t() | nil
+ defp predefined_name(extension) do
+ with name when not is_nil(name) <- Config.get([__MODULE__, :text]),
+ do: String.replace(name, "{extension}", extension)
end
defp random(extension) do