aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorhref <href@random.sh>2018-11-30 19:33:34 +0100
committerhref <href@random.sh>2018-11-30 19:33:34 +0100
commite9982c521b187136fd197d11a1e5d9b022da5e38 (patch)
tree988d9c6ffe5b0cc96c29e0e3015cf7500e25c217 /lib
parentca24ad2a2babed0700a38effb74910008d58f6ea (diff)
downloadpleroma-e9982c521b187136fd197d11a1e5d9b022da5e38.tar.gz
Upload filter: anonymize filename
It replaces the original filename with a randomly generated string.
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/upload/filter/anonymize_filename.ex10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/pleroma/upload/filter/anonymize_filename.ex b/lib/pleroma/upload/filter/anonymize_filename.ex
new file mode 100644
index 000000000..a83e764e5
--- /dev/null
+++ b/lib/pleroma/upload/filter/anonymize_filename.ex
@@ -0,0 +1,10 @@
+defmodule Pleroma.Upload.Filter.AnonymizeFilename do
+ @moduledoc "Replaces the original filename with a randomly generated string."
+ @behaviour Pleroma.Upload.Filter
+
+ def filter(upload) do
+ extension = List.last(String.split(upload.name, "."))
+ string = Base.url_encode64(:crypto.strong_rand_bytes(10), padding: false)
+ {:ok, %Pleroma.Upload{upload | name: string <> "." <> extension}}
+ end
+end