From 3b27f61ffa737dd6f4f9ec3a50c248d9077ddb51 Mon Sep 17 00:00:00 2001 From: href Date: Fri, 7 Dec 2018 14:07:11 +0100 Subject: [PATCH 1/2] AnonymizeFilename: allow for a pre-defined text instead of random string Improve docs --- config/config.md | 11 +++++++++++ .../upload/filter/anonymize_filename.ex | 19 ++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/config/config.md b/config/config.md index d90d18566..7f97f7342 100644 --- a/config/config.md +++ b/config/config.md @@ -19,6 +19,17 @@ Note: `strip_exif` has been replaced by `Pleroma.Upload.Filter.Mogrify`. * `args`: List of actions for the `mogrify` command like `"strip"` or `["strip", {"impode", "1"}]`. +## Pleroma.Upload.Filter.Dedupe + +No specific configuration. + +## Pleroma.Upload.Filter.AnonymizeFilename + +This filter remplaces the filename (not the path) of an upload. For complete obfuscation, add +`Pleroma.Upload.Filter.Dedupe` before AnonymizeFilename. + +* `text`: Text to remplace filenames in links. If empty, `{random}.extension` will be used. + ## :uri_schemes * `valid_schemes`: List of the scheme part that is considered valid to be an URL diff --git a/lib/pleroma/upload/filter/anonymize_filename.ex b/lib/pleroma/upload/filter/anonymize_filename.ex index a83e764e5..39eed7af3 100644 --- a/lib/pleroma/upload/filter/anonymize_filename.ex +++ b/lib/pleroma/upload/filter/anonymize_filename.ex @@ -1,10 +1,23 @@ defmodule Pleroma.Upload.Filter.AnonymizeFilename do - @moduledoc "Replaces the original filename with a randomly generated string." + @moduledoc """ + Replaces the original filename with a pre-defined text or randomly generated string. + + Should be used after `Pleroma.Upload.Filter.Dedupe`. + """ @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}} + name = Pleroma.Config.get([__MODULE__, :text], random(extension)) + {:ok, %Pleroma.Upload{upload | name: name}} + end + + defp random(extension) do + string = + 10 + |> :crypto.strong_rand_bytes() + |> Base.url_encode64(padding: false) + + string <> "." <> extension end end From f079ca7181a907416b77c2f81307049036f74aa9 Mon Sep 17 00:00:00 2001 From: href Date: Sat, 8 Dec 2018 11:09:35 +0100 Subject: [PATCH 2/2] Remove french. --- config/config.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/config.md b/config/config.md index 7f97f7342..a32c4cbde 100644 --- a/config/config.md +++ b/config/config.md @@ -25,10 +25,10 @@ No specific configuration. ## Pleroma.Upload.Filter.AnonymizeFilename -This filter remplaces the filename (not the path) of an upload. For complete obfuscation, add +This filter replaces the filename (not the path) of an upload. For complete obfuscation, add `Pleroma.Upload.Filter.Dedupe` before AnonymizeFilename. -* `text`: Text to remplace filenames in links. If empty, `{random}.extension` will be used. +* `text`: Text to replace filenames in links. If empty, `{random}.extension` will be used. ## :uri_schemes * `valid_schemes`: List of the scheme part that is considered valid to be an URL