mirror of
https://gitee.com/dgiiot/dgiot.git
synced 2024-11-30 11:17:48 +08:00
feat: go-fastdfs Api
This commit is contained in:
parent
b18a4bd015
commit
c4ad4e4ed5
@ -3,6 +3,10 @@
|
||||
{
|
||||
"name": "Evidence",
|
||||
"description": "证据"
|
||||
},
|
||||
{
|
||||
"name": "go-fastdfs",
|
||||
"description": "文件服务器"
|
||||
}
|
||||
],
|
||||
"definitions": {
|
||||
@ -744,19 +748,16 @@
|
||||
"post": {
|
||||
"summary": "配置管理API",
|
||||
"description": "配置管理API",
|
||||
"consumes": [
|
||||
"*"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "action",
|
||||
"in": "query",
|
||||
"name": "action",
|
||||
"required": true,
|
||||
"description": "set(修改参数),get获取参数,reload重新加载参数",
|
||||
"type": "number",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"set",
|
||||
"get",
|
||||
"set",
|
||||
"reload"
|
||||
]
|
||||
},
|
||||
@ -792,9 +793,9 @@
|
||||
},
|
||||
"/file_stat": {
|
||||
"get": {
|
||||
"summary": "文件统计信息",
|
||||
"description": "文件统计信息",
|
||||
"parameters": [
|
||||
],
|
||||
"parameters": [],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Returns operation status"
|
||||
@ -809,7 +810,6 @@
|
||||
"description": "Server Internal error"
|
||||
}
|
||||
},
|
||||
"summary": "文件统计信息",
|
||||
"tags": [
|
||||
"go-fastdfs"
|
||||
]
|
||||
@ -817,8 +817,17 @@
|
||||
},
|
||||
"/list_dir": {
|
||||
"get": {
|
||||
"summary": "获取文件列表",
|
||||
"description": "获取文件列表",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "文件夹路径",
|
||||
"in": "query",
|
||||
"name": "path",
|
||||
"required": true,
|
||||
"default": "dgiot_file/user/profile",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
@ -834,7 +843,6 @@
|
||||
"description": "Server Internal error"
|
||||
}
|
||||
},
|
||||
"summary": "获取文件列表",
|
||||
"tags": [
|
||||
"go-fastdfs"
|
||||
]
|
||||
@ -842,6 +850,7 @@
|
||||
},
|
||||
"/file_info": {
|
||||
"get": {
|
||||
"summary": "获取文件信息",
|
||||
"description": "获取文件信息",
|
||||
"parameters": [
|
||||
{
|
||||
@ -867,7 +876,37 @@
|
||||
"description": "Server Internal error"
|
||||
}
|
||||
},
|
||||
"summary": "获取文件信息",
|
||||
"tags": [
|
||||
"go-fastdfs"
|
||||
]
|
||||
},
|
||||
"delete": {
|
||||
"summary": "删除文件",
|
||||
"description": "删除文件",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "文件路径",
|
||||
"in": "query",
|
||||
"name": "path",
|
||||
"required": true,
|
||||
"default": "files/dgiot_file/user/profile/Klht7ERlYn.jpeg",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Returns operation status"
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad Request"
|
||||
},
|
||||
"403": {
|
||||
"description": "Forbidden"
|
||||
},
|
||||
"500": {
|
||||
"description": "Server Internal error"
|
||||
}
|
||||
},
|
||||
"tags": [
|
||||
"go-fastdfs"
|
||||
]
|
||||
|
@ -33,10 +33,10 @@
|
||||
-export([
|
||||
upload/3,
|
||||
upload/2,
|
||||
delete/2,
|
||||
delete_file/2,
|
||||
file_reload/2,
|
||||
file_stat/0,
|
||||
list_dir/0,
|
||||
list_dir/1,
|
||||
file_info/1,
|
||||
create_report/7,
|
||||
get_capture/1,
|
||||
@ -424,24 +424,48 @@ upload(Path, AppName, SessionToken) ->
|
||||
case jsx:decode(dgiot_utils:to_binary(Json), [{labels, binary}, return_maps]) of
|
||||
#{<<"md5">> := _Md5} = Data ->
|
||||
{ok, Data};
|
||||
Error1 -> Error1
|
||||
Error1 -> {ok, Error1}
|
||||
end;
|
||||
Error -> Error
|
||||
Error -> {error, Error}
|
||||
end;
|
||||
{error, Reason} ->
|
||||
?LOG(info, "Reason ~p ", [Reason]),
|
||||
{error, Reason}
|
||||
end.
|
||||
|
||||
file_reload(Action, Cfg) ->
|
||||
case httpc:request(get, {["http://127.0.0.1:1250/reload?action=" + Action + "&cfg=" + jsx:encode(Cfg)], []}, [], []) of
|
||||
delete_file(Path, SessionToken) ->
|
||||
Url = "http://127.0.0.1:1250/delete?auth_token=" ++ dgiot_utils:to_list(SessionToken) ++ "&path=" ++ dgiot_utils:to_list(Path),
|
||||
case httpc:request(get, {[Url], []}, [], []) of
|
||||
{ok, {{"HTTP/1.1", 200, "OK"}, _, Json}} ->
|
||||
case jsx:decode(dgiot_utils:to_binary(Json), [{labels, binary}, return_maps]) of
|
||||
#{<<"status">> := <<"ok">>} = Data ->
|
||||
{ok, Data};
|
||||
Error1 -> Error1
|
||||
Error1 ->
|
||||
{ok, Error1}
|
||||
end;
|
||||
Error -> Error
|
||||
Error ->
|
||||
{error, Error}
|
||||
end.
|
||||
|
||||
file_reload(Action, Body) ->
|
||||
Url =
|
||||
case Action of
|
||||
<<"set">> ->
|
||||
Cfg = maps:get(<<"cfg">>, Body, #{}),
|
||||
"http://127.0.0.1:1250/reload?action=set&cfg=" ++ jsx:encode(Cfg);
|
||||
<<"reload">> ->
|
||||
"http://127.0.0.1:1250/reload?action=reload";
|
||||
_ ->
|
||||
"http://127.0.0.1:1250/reload?action=get"
|
||||
end,
|
||||
case httpc:request(get, {[Url], []}, [], []) of
|
||||
{ok, {{"HTTP/1.1", 200, "OK"}, _, Json}} ->
|
||||
case jsx:decode(dgiot_utils:to_binary(Json), [{labels, binary}, return_maps]) of
|
||||
#{<<"status">> := <<"ok">>} = Data ->
|
||||
{ok, Data};
|
||||
Error1 -> {ok, Error1}
|
||||
end;
|
||||
Error -> {error, Error}
|
||||
end.
|
||||
|
||||
|
||||
@ -451,51 +475,31 @@ file_stat() ->
|
||||
case jsx:decode(dgiot_utils:to_binary(Json), [{labels, binary}, return_maps]) of
|
||||
#{<<"status">> := <<"ok">>} = Data ->
|
||||
{ok, Data};
|
||||
Error1 -> Error1
|
||||
Error1 -> {ok, Error1}
|
||||
end;
|
||||
Error -> Error
|
||||
Error -> {error, Error}
|
||||
end.
|
||||
|
||||
list_dir() ->
|
||||
case httpc:request(get, {["http://127.0.0.1:1250/list_dir?dir=dgiot_file/user/profile"], []}, [], []) of
|
||||
list_dir(Path) ->
|
||||
case httpc:request(get, {["http://127.0.0.1:1250/list_dir?dir=" ++ dgiot_utils:to_list(Path)], []}, [], []) of
|
||||
{ok, {{"HTTP/1.1", 200, "OK"}, _, Json}} ->
|
||||
case jsx:decode(dgiot_utils:to_binary(Json), [{labels, binary}, return_maps]) of
|
||||
#{<<"status">> := <<"ok">>} = Data ->
|
||||
{ok, Data};
|
||||
Error1 -> Error1
|
||||
Error1 -> {ok, Error1}
|
||||
end;
|
||||
Error -> Error
|
||||
Error -> {error, Error}
|
||||
end.
|
||||
|
||||
file_info(Path) ->
|
||||
case httpc:request(get, {["http://127.0.0.1:1250/get_file_info?path=" + Path], []}, [], []) of
|
||||
case httpc:request(get, {["http://127.0.0.1:1250/get_file_info?path=" ++ dgiot_utils:to_list(Path)], []}, [], []) of
|
||||
{ok, {{"HTTP/1.1", 200, "OK"}, _, Json}} ->
|
||||
case jsx:decode(dgiot_utils:to_binary(Json), [{labels, binary}, return_maps]) of
|
||||
#{<<"status">> := <<"ok">>} = Data ->
|
||||
{ok, Data};
|
||||
Error1 -> Error1
|
||||
Error1 -> {ok, Error1}
|
||||
end;
|
||||
Error -> Error
|
||||
end.
|
||||
|
||||
delete(Path, SessionToken) ->
|
||||
Path = <<"files/dgiot_file/user/profile/Klht7ERlYn.jpeg">>,
|
||||
SessionToken = <<"r:f3a8503a0f265e3fc7bdcb73268d2eab">>,
|
||||
Url = "http://127.0.0.1:1250/delete",
|
||||
|
||||
Body2 = #{<<"auth_token">> => SessionToken, <<"path">> => Path},
|
||||
|
||||
%% Url2 = "http://127.0.0.1/delete/files/dgiot_file/user/profile/Klht7ERlYn.jpeg",
|
||||
%% AuthHeader = [{"auth_token", "r:f3a8503a0f265e3fc7bdcb73268d2eab"}],
|
||||
httpc:request(get, {["http://127.0.0.1:1250/reload?action=get"], []}, [], []),
|
||||
case httpc:request(get, {Url, [], "application/json", jsx:encode(Body2)}, [], []) of
|
||||
{ok, {{"HTTP/1.1", 200, "OK"}, _, Json}} ->
|
||||
case jsx:decode(dgiot_utils:to_binary(Json), [{labels, binary}, return_maps]) of
|
||||
#{<<"md5">> := _Md5} = Data ->
|
||||
{ok, Data};
|
||||
Error1 -> Error1
|
||||
end;
|
||||
Error -> Error
|
||||
Error -> {error, Error}
|
||||
end.
|
||||
|
||||
get_url(AppName) ->
|
||||
|
@ -213,8 +213,8 @@ do_request(get_capture, Args, _Context, _Req) ->
|
||||
%% evidence 概要: 配置管理API 描述:配置管理API
|
||||
%% OperationId:post_reload
|
||||
%% 请求:GET /iotapi/reload
|
||||
do_request(post_file_reload, #{<<"action">> := Action, <<"cfg">> := Cfg} = _Body, _Context, _Req) ->
|
||||
dgiot_evidence:file_reload(Action, Cfg);
|
||||
do_request(post_file_reload, #{<<"action">> := Action} = Body, _Context, _Req) ->
|
||||
dgiot_evidence:file_reload(Action, Body);
|
||||
|
||||
%% evidence 概要: 文件统计信息 描述:文件统计信息
|
||||
%% OperationId:get_list_dir
|
||||
@ -225,8 +225,8 @@ do_request(get_file_stat, _Body, _Context, _Req) ->
|
||||
%% evidence 概要: 获取文件列表 描述:获取文件列表
|
||||
%% OperationId:get_list_dir
|
||||
%% 请求:GET /iotapi/list_dir
|
||||
do_request(get_list_dir, _Body, _Context, _Req) ->
|
||||
dgiot_evidence:list_dir();
|
||||
do_request(get_list_dir, #{<<"path">> := Path} = _Body, _Context, _Req) ->
|
||||
dgiot_evidence:list_dir(Path);
|
||||
|
||||
%% evidence 概要: 获取文件信息 描述:获取文件信息
|
||||
%% OperationId:get_file_info
|
||||
@ -234,6 +234,12 @@ do_request(get_list_dir, _Body, _Context, _Req) ->
|
||||
do_request(get_file_info, #{<<"path">> := Path} = _Body, _Context, _Req) ->
|
||||
dgiot_evidence:file_info(Path);
|
||||
|
||||
%% evidence 概要: 删除文件 描述:删除文件
|
||||
%% OperationId:delete_file
|
||||
%% 请求:GET /iotapi/delete_file
|
||||
do_request(delete_file_info, #{<<"path">> := Path} = _Body, #{<<"sessionToken">> := SessionToken} = _Context, _Req) ->
|
||||
dgiot_evidence:delete_file(Path, SessionToken);
|
||||
|
||||
%% 服务器不支持的API接口
|
||||
do_request(_OperationId, _Args, _Context, _Req) ->
|
||||
{error, <<"Not Allowed.">>}.
|
||||
|
Loading…
Reference in New Issue
Block a user