mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-28 16:34:13 +01:00
mod_http_upload: Apply cosmetic changes
This commit is contained in:
parent
842db2ca15
commit
113c315857
@ -117,7 +117,7 @@
|
|||||||
width :: integer()}).
|
width :: integer()}).
|
||||||
|
|
||||||
-type state() :: #state{}.
|
-type state() :: #state{}.
|
||||||
-type slot() :: [binary()].
|
-type slot() :: [binary(), ...].
|
||||||
-type media_info() :: #media_info{}.
|
-type media_info() :: #media_info{}.
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
@ -450,7 +450,7 @@ process(LocalPath, #request{method = Method, host = Host, ip = IP})
|
|||||||
[Path, ?ADDR_TO_STR(IP)]),
|
[Path, ?ADDR_TO_STR(IP)]),
|
||||||
http_response(Host, 403);
|
http_response(Host, 403);
|
||||||
{error, enoent} ->
|
{error, enoent} ->
|
||||||
?INFO_MSG("Cannot serve ~s to ~s: No such file or directory",
|
?INFO_MSG("Cannot serve ~s to ~s: No such file",
|
||||||
[Path, ?ADDR_TO_STR(IP)]),
|
[Path, ?ADDR_TO_STR(IP)]),
|
||||||
http_response(Host, 404);
|
http_response(Host, 404);
|
||||||
{error, eisdir} ->
|
{error, eisdir} ->
|
||||||
@ -636,7 +636,7 @@ create_slot(#state{service_url = ServiceURL},
|
|||||||
[jlib:jid_to_string(JID), File]),
|
[jlib:jid_to_string(JID), File]),
|
||||||
{ok, PutURL, GetURL};
|
{ok, PutURL, GetURL};
|
||||||
Lines ->
|
Lines ->
|
||||||
?ERROR_MSG("Cannot parse data received for ~s from <~s>: ~p",
|
?ERROR_MSG("Can't parse data received for ~s from <~s>: ~p",
|
||||||
[jlib:jid_to_string(JID), ServiceURL, Lines]),
|
[jlib:jid_to_string(JID), ServiceURL, Lines]),
|
||||||
{error, ?ERR_SERVICE_UNAVAILABLE}
|
{error, ?ERR_SERVICE_UNAVAILABLE}
|
||||||
end;
|
end;
|
||||||
@ -754,7 +754,7 @@ iq_disco_info(Lang, Name) ->
|
|||||||
-spec store_file(binary(), binary(),
|
-spec store_file(binary(), binary(),
|
||||||
integer() | undefined,
|
integer() | undefined,
|
||||||
integer() | undefined,
|
integer() | undefined,
|
||||||
binary(), binary(), boolean())
|
binary(), slot(), boolean())
|
||||||
-> ok | {ok, [{binary(), binary()}], binary()} | {error, term()}.
|
-> ok | {ok, [{binary(), binary()}], binary()} | {error, term()}.
|
||||||
|
|
||||||
store_file(Path, Data, FileMode, DirMode, GetPrefix, LocalPath, Thumbnail) ->
|
store_file(Path, Data, FileMode, DirMode, GetPrefix, LocalPath, Thumbnail) ->
|
||||||
@ -763,10 +763,8 @@ store_file(Path, Data, FileMode, DirMode, GetPrefix, LocalPath, Thumbnail) ->
|
|||||||
case identify(Path) of
|
case identify(Path) of
|
||||||
{ok, MediaInfo} ->
|
{ok, MediaInfo} ->
|
||||||
case convert(Path, MediaInfo) of
|
case convert(Path, MediaInfo) of
|
||||||
pass ->
|
|
||||||
ok;
|
|
||||||
{ok, OutPath} ->
|
{ok, OutPath} ->
|
||||||
[UserDir, RandDir|_] = LocalPath,
|
[UserDir, RandDir | _] = LocalPath,
|
||||||
FileName = filename:basename(OutPath),
|
FileName = filename:basename(OutPath),
|
||||||
URL = str:join([GetPrefix, UserDir,
|
URL = str:join([GetPrefix, UserDir,
|
||||||
RandDir, FileName], <<$/>>),
|
RandDir, FileName], <<$/>>),
|
||||||
@ -774,7 +772,9 @@ store_file(Path, Data, FileMode, DirMode, GetPrefix, LocalPath, Thumbnail) ->
|
|||||||
{ok,
|
{ok,
|
||||||
[{<<"Content-Type">>,
|
[{<<"Content-Type">>,
|
||||||
<<"text/xml; charset=utf-8">>}],
|
<<"text/xml; charset=utf-8">>}],
|
||||||
xml:element_to_binary(ThumbEl)}
|
xml:element_to_binary(ThumbEl)};
|
||||||
|
pass ->
|
||||||
|
ok
|
||||||
end;
|
end;
|
||||||
pass ->
|
pass ->
|
||||||
ok
|
ok
|
||||||
@ -871,47 +871,47 @@ code_to_message(500) -> <<"Internal server error.">>;
|
|||||||
code_to_message(_Code) -> <<"">>.
|
code_to_message(_Code) -> <<"">>.
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Image manipulation stuff
|
%% Image manipulation stuff.
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
-spec identify(binary()) -> {ok, media_info()} | pass.
|
-spec identify(binary()) -> {ok, media_info()} | pass.
|
||||||
|
|
||||||
identify(Path) ->
|
identify(Path) ->
|
||||||
Cmd = io_lib:fwrite("identify -format \"ok %m %h %w\" ~s", [Path]),
|
Cmd = io_lib:format("identify -format 'ok %m %h %w' ~s", [Path]),
|
||||||
Res = string:strip(os:cmd(Cmd), right, $\n),
|
Res = string:strip(os:cmd(Cmd), right, $\n),
|
||||||
case string:tokens(Res, " ") of
|
case string:tokens(Res, " ") of
|
||||||
["ok", T, H, W] ->
|
["ok", T, H, W] ->
|
||||||
{ok, #media_info{
|
{ok, #media_info{type = list_to_binary(string:to_lower(T)),
|
||||||
type = list_to_binary(string:to_lower(T)),
|
height = list_to_integer(H),
|
||||||
height = list_to_integer(H),
|
width = list_to_integer(W)}};
|
||||||
width = list_to_integer(W)}};
|
|
||||||
_ ->
|
_ ->
|
||||||
?DEBUG("failed to identify type of ~s: ~s", [Path, Res]),
|
?DEBUG("Cannot identify type of ~s: ~s", [Path, Res]),
|
||||||
pass
|
pass
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec convert(binary(), media_info()) -> {ok, binary()} | pass.
|
-spec convert(binary(), media_info()) -> {ok, binary()} | pass.
|
||||||
|
|
||||||
convert(Path, #media_info{type = T, width = W, height = H}) ->
|
convert(Path, #media_info{type = T, width = W, height = H}) ->
|
||||||
if W*H >= 25000000 ->
|
if W * H >= 25000000 ->
|
||||||
?DEBUG("the image ~s is more than 25 Mbpx", [Path]),
|
?DEBUG("The image ~s is more than 25 Mpix", [Path]),
|
||||||
pass;
|
pass;
|
||||||
(W =< 300) and (H =< 300) ->
|
W =< 300, H =< 300 ->
|
||||||
{ok, Path};
|
{ok, Path};
|
||||||
T == <<"gif">>; T == <<"jpeg">>; T == <<"png">>; T == <<"webp">> ->
|
T == <<"gif">>; T == <<"jpeg">>; T == <<"png">>; T == <<"webp">> ->
|
||||||
Dir = filename:dirname(Path),
|
Dir = filename:dirname(Path),
|
||||||
FileName = <<(randoms:get_string())/binary, $., T/binary>>,
|
FileName = <<(randoms:get_string())/binary, $., T/binary>>,
|
||||||
OutPath = filename:join(Dir, FileName),
|
OutPath = filename:join(Dir, FileName),
|
||||||
Cmd = io_lib:fwrite("convert -resize 300 ~s ~s", [Path, OutPath]),
|
Cmd = io_lib:format("convert -resize 300 ~s ~s", [Path, OutPath]),
|
||||||
case os:cmd(Cmd) of
|
case os:cmd(Cmd) of
|
||||||
"" ->
|
"" ->
|
||||||
{ok, OutPath};
|
{ok, OutPath};
|
||||||
Err ->
|
Err ->
|
||||||
?ERROR_MSG("failed to convert ~s to ~s: ~s",
|
?ERROR_MSG("Failed to convert ~s to ~s: ~s",
|
||||||
[Path, OutPath, string:strip(Err, right, $\n)]),
|
[Path, OutPath, string:strip(Err, right, $\n)]),
|
||||||
pass
|
pass
|
||||||
end;
|
end;
|
||||||
true ->
|
true ->
|
||||||
?DEBUG("do not call 'convert' for unknown type ~s", [T]),
|
?DEBUG("Won't call 'convert' for unknown type ~s", [T]),
|
||||||
pass
|
pass
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user