Skip to content

Commit

Permalink
Remove dynamically compiled modules from mod_http_upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Janusz Jakubiec authored and Janusz Jakubiec committed Oct 27, 2021
1 parent d106506 commit ece5632
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
18 changes: 4 additions & 14 deletions src/http_upload/mod_http_upload.erl
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,7 @@
%% mongoose_module_metrics callbacks
-export([config_metrics/1]).

-ignore_xref([{mod_http_upload_backend, create_slot, 6},
behaviour_info/1, disco_local_items/1, process_disco_iq/5, process_iq/5]).

%%--------------------------------------------------------------------
%% Callbacks
%%--------------------------------------------------------------------

-callback create_slot(UTCDateTime :: calendar:datetime(), UUID :: binary(),
Filename :: unicode:unicode_binary(), ContentType :: binary() | undefined,
Size :: pos_integer(), Opts :: proplists:proplist()) ->
{PUTURL :: binary(), GETURL :: binary(), Headers :: #{binary() => binary()}}.
-ignore_xref([behaviour_info/1, disco_local_items/1, process_disco_iq/5, process_iq/5]).

%%--------------------------------------------------------------------
%% API
Expand All @@ -72,7 +62,7 @@ start(HostType, Opts) ->
[gen_iq_handler:add_iq_handler_for_subdomain(HostType, SubdomainPattern, Namespace,
Component, Fn, #{}, IQDisc) ||
{Component, Namespace, Fn} <- iq_handlers()],
gen_mod:start_backend_module(?MODULE, with_default_backend(Opts), [create_slot]),
mod_http_upload_backend:init(HostType, with_default_backend(Opts)),
ejabberd_hooks:add(hooks(HostType)),
ok.

Expand Down Expand Up @@ -157,7 +147,7 @@ process_iq(Acc, _From, _To, IQ = #iq{type = get, sub_el = Request}, _Extra) ->
Opts = module_opts(HostType),

{PutUrl, GetUrl, Headers} =
mod_http_upload_backend:create_slot(UTCDateTime, Token, Filename,
mod_http_upload_backend:create_slot(HostType, UTCDateTime, Token, Filename,
ContentType, Size, Opts),

compose_iq_reply(IQ, PutUrl, GetUrl, Headers);
Expand Down Expand Up @@ -209,7 +199,7 @@ get_urls(HostType, Filename, Size, ContentType, Timeout) ->
Token = generate_token(HostType),
Opts = module_opts(HostType),
NewOpts = gen_mod:set_opt(expiration_time, Opts, Timeout),
mod_http_upload_backend:create_slot(UTCDateTime, Token, Filename,
mod_http_upload_backend:create_slot(HostType, UTCDateTime, Token, Filename,
ContentType, Size, NewOpts).

%%--------------------------------------------------------------------
Expand Down
31 changes: 31 additions & 0 deletions src/http_upload/mod_http_upload_backend.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
%% Just a proxy interface module between the main mod_http_upload module and
%% the backend modules (i.e. mod_http_upload_s3).
-module(mod_http_upload_backend).

-export([init/2, create_slot/7]).

-define(MAIN_MODULE, mod_http_upload).
%%--------------------------------------------------------------------
%% Callbacks
%%--------------------------------------------------------------------

-callback create_slot(UTCDateTime :: calendar:datetime(), UUID :: binary(),
Filename :: unicode:unicode_binary(), ContentType :: binary() | undefined,
Size :: pos_integer(), Opts :: proplists:proplist()) ->
{PUTURL :: binary(), GETURL :: binary(), Headers :: #{binary() => binary()}}.

-spec init(HostType :: mongooseim:host_type(), Opts :: gen_mod:module_opts()) -> ok.
init(HostType, Opts) ->
mongoose_backend:init_per_host_type(HostType, ?MAIN_MODULE, [create_slot], Opts).

-spec create_slot(HostType::mongooseim:host_type(),
UTCDateTime :: calendar:datetime(),
UUID :: binary(),
Filename :: unicode:unicode_binary(),
ContentType :: binary() | undefined,
Size :: pos_integer(),
Opts :: proplists:proplist()) ->
{PUTURL :: binary(), GETURL :: binary(), Headers :: #{binary() => binary()}}.
create_slot(HostType, UTCDateTime, UUID, Filename, ContentType, Size, Opts) ->
Args = [UTCDateTime, UUID, Filename, ContentType, Size, Opts],
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
2 changes: 1 addition & 1 deletion src/http_upload/mod_http_upload_s3.erl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

-module(mod_http_upload_s3).
-author('[email protected]').
-behaviour(mod_http_upload).
-behaviour(mod_http_upload_backend).

-export([create_slot/6]).

Expand Down

0 comments on commit ece5632

Please sign in to comment.