This commit is contained in:
anlicheng 2026-02-19 00:03:46 +08:00
parent 66935409c9
commit a6d140afaa
3 changed files with 16 additions and 47 deletions

View File

@ -17,27 +17,11 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
handle_request("POST", "/test/auth_token", _, PostParams) ->
logger:debug("[test_handler] get post params: ~p", [PostParams]),
Data = #{
<<"network_id">> => 8,
<<"upgrade_type">> => 0,
<<"upgrade_prompt">> => <<"simple upgrade">>,
<<"upgrade_address">> => <<"upgrade_address">>
},
{ok, 200, sdlan_util:json_data(Data)};
handle_request("POST", "/test/upgrade", _, PostParams) ->
logger:debug("[test_handler] get post params: ~p", [PostParams]),
Data = #{
<<"upgrade_type">> => 1,
<<"upgrade_prompt">> => <<"prompt需要升级"/utf8>>,
<<"upgrade_address">> => <<"macappstore://apps.apple.com/app/id836500024">>
},
{ok, 200, sdlan_util:json_data(Data)};
handle_request("POST", "/test/auth_access_token", _, _PostParams) ->
{ok, 200, sdlan_util:json_data(<<"ok">>)};
handle_request("GET", "/test/get_all_networks", _, _) ->
{ok, 200, sdlan_util:json_data([8, 9, 10])};
{ok, 200, sdlan_util:json_data([8])};
handle_request("GET", "/test/get_network", #{<<"id">> := Id0}, _) ->
Id = binary_to_integer(Id0),
@ -45,23 +29,10 @@ handle_request("GET", "/test/get_network", #{<<"id">> := Id0}, _) ->
8 => #{
<<"id">> => 8,
<<"name">> => <<"test1">>,
<<"domain">> => <<"punchnet.cn">>,
<<"ipaddr">> => <<"10.211.179.0/24">>,
<<"owner_id">> => 1234,
<<"disabled_clients">> => []
},
9 => #{
<<"id">> => 9,
<<"name">> => <<"test2">>,
<<"ipaddr">> => <<"10.211.180.0/24">>,
<<"owner_id">> => 1234,
<<"disabled_clients">> => []
},
10 => #{
<<"id">> => 10,
<<"name">> => <<"test3">>,
<<"ipaddr">> => <<"10.211.181.0/24">>,
<<"owner_id">> => 1234,
<<"disabled_clients">> => []
}
},
Network = maps:get(Id, Networks),

View File

@ -50,18 +50,17 @@ get_network(Id) when is_integer(Id) ->
%% todo
-spec auth_access_token(Params :: map()) -> {ok, Resp :: map()} | {error, Reason :: any()}.
auth_access_token(Params) when is_map(Params) ->
{ok, #{<<"result">> => <<"ok">>}}.
%case catch do_post("auth_token", Params) of
% {ok, Resp} ->
% case catch jiffy:decode(Resp, [return_maps]) of
% Result when is_map(Result) ->
% {ok, Result};
% {error, Reason} ->
% {error, Reason}
% end;
% Error ->
% Error
%end.
case catch do_post("auth_access_token", Params) of
{ok, Resp} ->
case catch jiffy:decode(Resp, [return_maps]) of
Result when is_map(Result) ->
{ok, Result};
{error, Reason} ->
{error, Reason}
end;
Error ->
Error
end.
-spec node_online(ClientId :: binary(), NetworkId :: integer(), IpAddr :: binary()) -> {ok, Resp :: map()} | {error, Reason :: any()}.
node_online(ClientId, NetworkId, IpAddr) when is_binary(ClientId), is_integer(NetworkId), is_binary(IpAddr) ->

View File

@ -41,8 +41,7 @@ start_link() ->
init([]) ->
SupFlags = #{strategy => one_for_one, intensity => 1000, period => 3600},
{ok, NetworkIds} = sdlan_api:get_all_networks(),
Specs = lists:map(fun child_spec/1, []),
Specs = lists:map(fun child_spec/1, NetworkIds),
set_network_bind(length(Specs)),
{ok, {SupFlags, Specs}}.