]> granicus.if.org Git - ejabberd/commitdiff
Introduce 'rate_limit' option of mod_avatar
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Mon, 5 Feb 2018 20:12:36 +0000 (23:12 +0300)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Mon, 5 Feb 2018 20:12:36 +0000 (23:12 +0300)
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.

rebar.config
src/mod_avatar.erl

index 512065fe4b9f3325f4ef5c4ff7fca00c418d0102..aaefcdb591875975064986bd733355ac41fb545c 100644 (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",
index 48e963ff6a0551015463daa8a16b62890c816e85..640f5f6b4e1183873f4060975085fe2c42b1c1d5 100644 (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()]]}].