f90089e1bf
Use Upload Media logic from Pleroma Backend changes for picture upload Move AS <-> Model conversion to separate module Front changes Downgrade apollo-client: https://github.com/Akryum/vue-apollo/issues/577 Signed-off-by: Thomas Citharel <tcit@tcit.fr>
29 lines
937 B
Elixir
29 lines
937 B
Elixir
# Portions of this file are derived from Pleroma:
|
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/upload/filter/anonymize_filename.ex
|
|
|
|
defmodule MobilizonWeb.Upload.Filter.AnonymizeFilename do
|
|
@moduledoc """
|
|
Replaces the original filename with a pre-defined text or randomly generated string.
|
|
|
|
Should be used after `MobilizonWeb.Upload.Filter.Dedupe`.
|
|
"""
|
|
@behaviour MobilizonWeb.Upload.Filter
|
|
|
|
def filter(upload) do
|
|
extension = List.last(String.split(upload.name, "."))
|
|
name = Mobilizon.CommonConfig.get([__MODULE__, :text], random(extension))
|
|
{:ok, %MobilizonWeb.Upload{upload | name: name}}
|
|
end
|
|
|
|
defp random(extension) do
|
|
string =
|
|
10
|
|
|> :crypto.strong_rand_bytes()
|
|
|> Base.url_encode64(padding: false)
|
|
|
|
string <> "." <> extension
|
|
end
|
|
end
|