From: Evgeniy Khramtsov Date: Mon, 5 Feb 2018 20:12:36 +0000 (+0300) Subject: Introduce 'rate_limit' option of mod_avatar X-Git-Tag: 18.03~87 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=232b66b0f4cd66ddca4ab98a903d8617e79e2a34;p=ejabberd 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. --- diff --git a/rebar.config b/rebar.config index 512065fe4..aaefcdb59 100644 --- a/rebar.config +++ b/rebar.config @@ -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", diff --git a/src/mod_avatar.erl b/src/mod_avatar.erl index 48e963ff6..640f5f6b4 100644 --- a/src/mod_avatar.erl +++ b/src/mod_avatar.erl @@ -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()]]}].