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>
20 lines
755 B
Elixir
20 lines
755 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/dedupe.ex
|
|
|
|
defmodule MobilizonWeb.Upload.Filter.Dedupe do
|
|
@moduledoc """
|
|
Names the file after its hash to avoid dedupes
|
|
"""
|
|
@behaviour MobilizonWeb.Upload.Filter
|
|
alias MobilizonWeb.Upload
|
|
|
|
def filter(%Upload{name: name} = upload) do
|
|
extension = String.split(name, ".") |> List.last()
|
|
shasum = :crypto.hash(:sha256, File.read!(upload.tempfile)) |> Base.encode16(case: :lower)
|
|
filename = shasum <> "." <> extension
|
|
{:ok, %Upload{upload | id: shasum, path: filename}}
|
|
end
|
|
end
|