X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;ds=inline;f=lib%2Fpleroma%2Fupload%2Ffilter%2Fanonymize_filename.ex;h=7e62b3d136e046ab728617d1954cd6a04008a384;hb=173e977e283789a814278c63bc81f40a13942e21;hp=c26e4f32ce5ea0bf4b7127e00fd99d983d108803;hpb=2791ce9a1ff2365ac7256f5e1dc2324dee2f82c9;p=akkoma
diff --git a/lib/pleroma/upload/filter/anonymize_filename.ex b/lib/pleroma/upload/filter/anonymize_filename.ex
index c26e4f32c..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-2018 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