fix http api

This commit is contained in:
anlicheng 2025-05-20 18:44:50 +08:00
parent 96b76f2b09
commit 55982e831c
3 changed files with 21 additions and 3 deletions

View File

@ -89,7 +89,12 @@ parse_body(Req0) ->
case ContentType of case ContentType of
<<"application/json", _/binary>> -> <<"application/json", _/binary>> ->
{ok, Body, Req1} = read_body(Req0), {ok, Body, Req1} = read_body(Req0),
{ok, catch jiffy:decode(Body, [return_maps]), Req1}; case Body =/= <<"">> of
true ->
{ok, catch jiffy:decode(Body, [return_maps]), Req1};
false ->
{ok, #{}, Req1}
end;
<<"application/x-www-form-urlencoded">> -> <<"application/x-www-form-urlencoded">> ->
{ok, PostParams0, Req1} = cowboy_req:read_urlencoded_body(Req0), {ok, PostParams0, Req1} = cowboy_req:read_urlencoded_body(Req0),
PostParams = maps:from_list(PostParams0), PostParams = maps:from_list(PostParams0),

View File

@ -89,7 +89,20 @@ get_config(ServiceId) when is_binary(ServiceId) ->
-spec delete(ServiceId :: binary()) -> ok | {error, Reason :: any()}. -spec delete(ServiceId :: binary()) -> ok | {error, Reason :: any()}.
delete(ServiceId) when is_binary(ServiceId) -> delete(ServiceId) when is_binary(ServiceId) ->
case mnesia:transaction(fun() -> mnesia:delete(?TAB, ServiceId, write) end) of Fun = fun() ->
case mnesia:read(?TAB, ServiceId, write) of
[] ->
ok;
[ServiceConfig0 = #service_config{config_json = OldConfigJson}] ->
NServiceConfig = ServiceConfig0#service_config{
config_json = <<"">>,
last_config_json = OldConfigJson,
update_ts = iot_util:current_time()
},
mnesia:write(?TAB, NServiceConfig, write)
end
end,
case mnesia:transaction(Fun) of
{'atomic', ok} -> {'atomic', ok} ->
ok; ok;
{'aborted', Reason} -> {'aborted', Reason} ->

View File

@ -1,4 +1,4 @@
-sname iot -name iot
-setcookie iot_cookie -setcookie iot_cookie