Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F84166066
anonymize_filename.ex
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
anonymize_filename.ex
View Options
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule
Pleroma.Upload.Filter.AnonymizeFilename
do
@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
@config_impl
Application
.
compile_env
(
:pleroma
,
[
__MODULE__
,
:config_impl
],
Pleroma.Config
)
alias
Pleroma.Upload
def
filter
(%
Upload
{
name
:
name
}
=
upload
)
do
extension
=
List
.
last
(
String
.
split
(
name
,
"."
))
name
=
predefined_name
(
extension
)
||
random
(
extension
)
{
:ok
,
:filtered
,
%
Upload
{
upload
|
name
:
name
}}
end
def
filter
(
_
),
do
:
{
:ok
,
:noop
}
@spec
predefined_name
(
String
.
t
())
::
String
.
t
()
|
nil
defp
predefined_name
(
extension
)
do
with
name
when
not
is_nil
(
name
)
<-
@config_impl
.
get
([
__MODULE__
,
:text
]),
do
:
String
.
replace
(
name
,
"{extension}"
,
extension
)
end
defp
random
(
extension
)
do
string
=
10
|>
:crypto
.
strong_rand_bytes
()
|>
Base
.
url_encode64
(
padding
:
false
)
string
<>
"."
<>
extension
end
end
File Metadata
Details
Attached
Mime Type
text/x-ruby
Expires
Thu, Jun 4, 6:56 PM (14 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1537260
Default Alt Text
anonymize_filename.ex (1 KB)
Attached To
Mode
rPUBE pleroma-upstream
Attached
Detach File
Event Timeline
Log In to Comment