Merge branch 'anonymize-filter-text' into 'develop'
AnonymizeFilename: allow for a pre-defined text instead of random string See merge request pleroma/pleroma!516
This commit is contained in:
commit
0554d91dcd
2 changed files with 27 additions and 3 deletions
|
@ -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"}]`.
|
* `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 replaces the filename (not the path) of an upload. For complete obfuscation, add
|
||||||
|
`Pleroma.Upload.Filter.Dedupe` before AnonymizeFilename.
|
||||||
|
|
||||||
|
* `text`: Text to replace filenames in links. If empty, `{random}.extension` will be used.
|
||||||
|
|
||||||
## :uri_schemes
|
## :uri_schemes
|
||||||
* `valid_schemes`: List of the scheme part that is considered valid to be an URL
|
* `valid_schemes`: List of the scheme part that is considered valid to be an URL
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,23 @@
|
||||||
defmodule Pleroma.Upload.Filter.AnonymizeFilename do
|
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
|
@behaviour Pleroma.Upload.Filter
|
||||||
|
|
||||||
def filter(upload) do
|
def filter(upload) do
|
||||||
extension = List.last(String.split(upload.name, "."))
|
extension = List.last(String.split(upload.name, "."))
|
||||||
string = Base.url_encode64(:crypto.strong_rand_bytes(10), padding: false)
|
name = Pleroma.Config.get([__MODULE__, :text], random(extension))
|
||||||
{:ok, %Pleroma.Upload{upload | name: string <> "." <> 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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue