fix http api
This commit is contained in:
parent
96b76f2b09
commit
55982e831c
@ -89,7 +89,12 @@ parse_body(Req0) ->
|
||||
case ContentType of
|
||||
<<"application/json", _/binary>> ->
|
||||
{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">> ->
|
||||
{ok, PostParams0, Req1} = cowboy_req:read_urlencoded_body(Req0),
|
||||
PostParams = maps:from_list(PostParams0),
|
||||
|
||||
@ -89,7 +89,20 @@ get_config(ServiceId) when is_binary(ServiceId) ->
|
||||
|
||||
-spec delete(ServiceId :: binary()) -> ok | {error, Reason :: any()}.
|
||||
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} ->
|
||||
ok;
|
||||
{'aborted', Reason} ->
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
-sname iot
|
||||
-name iot
|
||||
|
||||
-setcookie iot_cookie
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user