24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-18 22:15:20 +02:00

Introduce 'rate_limit' option of mod_avatar

The option controls how many avatars a user can upload per minute.
The option takes positive integer values. The default is 10.
Note that the option only takes effect when an avatar is about
to convert to a different format, i.e. it implies that `convert`
option is configured.
This commit is contained in:
Evgeniy Khramtsov 2018-02-05 23:12:36 +03:00
parent 3327da72a6
commit 232b66b0f4
2 changed files with 10 additions and 4 deletions

View File

@ -31,7 +31,7 @@
{p1_oauth2, ".*", {git, "https://github.com/processone/p1_oauth2", {tag, "0.6.2"}}},
{jose, ".*", {git, "https://github.com/potatosalad/erlang-jose", {tag, "1.8.4"}}},
{fs, ".*", {git, "https://github.com/synrc/fs", "bed9467"}},
{eimp, ".*", {git, "https://github.com/processone/eimp", "c7201d18"}},
{eimp, ".*", {git, "https://github.com/processone/eimp", "6858909d"}},
{if_var_true, stun, {stun, ".*", {git, "https://github.com/processone/stun", {tag, "1.0.20"}}}},
{if_var_true, sip, {esip, ".*", {git, "https://github.com/processone/esip", {tag, "1.0.21"}}}},
{if_var_true, mysql, {p1_mysql, ".*", {git, "https://github.com/processone/p1_mysql",

View File

@ -316,7 +316,10 @@ convert_avatar(LUser, LServer, Data, Rules) ->
true ->
?DEBUG("Converting avatar of ~s@~s: ~s -> ~s",
[LUser, LServer, Type, NewType]),
case eimp:convert(Data, NewType) of
RateLimit = gen_mod:get_module_opt(LServer, ?MODULE, rate_limit),
Opts = [{limit_by, {LUser, LServer}},
{rate_limit, RateLimit}],
case eimp:convert(Data, NewType, Opts) of
{ok, NewData} ->
{ok, encode_mime_type(NewType), NewData};
{error, Reason} = Err ->
@ -434,8 +437,11 @@ mod_opt_type({convert, From}) ->
true -> To
end
end
end.
end;
mod_opt_type(rate_limit) ->
fun(I) when is_integer(I), I > 0 -> I end.
mod_options(_) ->
[{convert,
[{rate_limit, 10},
{convert,
[{T, undefined} || T <- [default|eimp:supported_formats()]]}].