From 3dbc47e2fc2b27a337dd7884ac145d1aeec422e9 Mon Sep 17 00:00:00 2001 From: "U-JOHNLIU\\jonhl" Date: Thu, 24 Aug 2023 21:23:20 +0800 Subject: [PATCH] feat: add upgrade --- apps/dgiot_parse/etc/dgiot_parse.conf | 2 +- .../priv/swagger/swagger_parse.json | 67 ++++++++++++++++++- .../src/handler/dgiot_parse_handler.erl | 7 ++ .../src/handler/dgiot_user_handler.erl | 4 +- 4 files changed, 76 insertions(+), 4 deletions(-) diff --git a/apps/dgiot_parse/etc/dgiot_parse.conf b/apps/dgiot_parse/etc/dgiot_parse.conf index cc0c7eb9..422d76bc 100644 --- a/apps/dgiot_parse/etc/dgiot_parse.conf +++ b/apps/dgiot_parse/etc/dgiot_parse.conf @@ -6,7 +6,7 @@ parse.delete_field = ACL,objectId,updatedAt,createdAt ##-------------------------------------------------------------------- ## parse config ##-------------------------------------------------------------------- -parse.parse_server = http://192.168.1.122:1337 +parse.parse_server = http://127.0.0.1:1337 parse.parse_path = /parse/ parse.parse_appid = 8c7f62065812e504f3e21c9826963d7c parse.parse_master_key = b2bd55d3b36edd652b5b912391ada90c diff --git a/apps/dgiot_parse/priv/swagger/swagger_parse.json b/apps/dgiot_parse/priv/swagger/swagger_parse.json index 1000b0b9..fca08354 100644 --- a/apps/dgiot_parse/priv/swagger/swagger_parse.json +++ b/apps/dgiot_parse/priv/swagger/swagger_parse.json @@ -91,7 +91,7 @@ "post": { "summary": "数据批处理", "description": "为了减少网络往返的时间,可以使用批处理端点在一次调用中创建、更新或删除多达50个对象。", - "position" : 0, + "position": 0, "parameters": [ { "in": "body", @@ -342,6 +342,71 @@ "tags": [ "Basic" ] + }, + "post": { + "summary": "版本升级", + "description": "版本升级", + "parameters": [ + { + "description": "升级类型", + "in": "query", + "name": "type", + "required": true, + "type": "string", + "default": "dgiot", + "enum": [ + "all", + "dgiot", + "amis", + "admin", + "tdengine", + "postgres", + "gofastd", + "parse", + "erlang" + ] + }, + { + "in": "body", + "name": "info", + "description": "版本信息", + "required": true, + "schema": { + "type": "object", + "properties": { + "url": { + "description": "软件名称", + "type": "string", + "example": "dgiot_edge_v10.tar.gz" + }, + "md5": { + "description": "校验码", + "type": "array" + } + } + } + } + ], + "responses": { + "200": { + "description": "Returns success" + }, + "400": { + "description": "Bad Request" + }, + "401": { + "description": "Unauthorized" + }, + "403": { + "description": "Forbidden" + }, + "500": { + "description": "Server Internal error" + } + }, + "tags": [ + "Basic" + ] } } } diff --git a/apps/dgiot_parse/src/handler/dgiot_parse_handler.erl b/apps/dgiot_parse/src/handler/dgiot_parse_handler.erl index 97866aa6..d067a177 100644 --- a/apps/dgiot_parse/src/handler/dgiot_parse_handler.erl +++ b/apps/dgiot_parse/src/handler/dgiot_parse_handler.erl @@ -110,6 +110,13 @@ do_request(get_upgrade, _Body, _Context, Req) -> %% io:format("~s ~p SessionToken = ~p.~n", [?FILE, ?LINE, SessionToken]), dgiot_parse_utils:update(SessionToken); +%%%% 版本升级 +do_request(post_upgrade, _Body, _Context, Req) -> + Cookies = cowboy_req:parse_cookies(Req), + SessionToken = proplists:get_value(<<"departmentToken">>, Cookies), +%% io:format("~s ~p SessionToken = ~p.~n", [?FILE, ?LINE, SessionToken]), + dgiot_parse_utils:update(SessionToken); + %% 服务器不支持的API接口 do_request(_OperationId, _Args, _Context, _Req) -> {error, <<"Not Allowed.">>}. diff --git a/apps/dgiot_parse/src/handler/dgiot_user_handler.erl b/apps/dgiot_parse/src/handler/dgiot_user_handler.erl index 37bceb44..a2f933a3 100644 --- a/apps/dgiot_parse/src/handler/dgiot_user_handler.erl +++ b/apps/dgiot_parse/src/handler/dgiot_user_handler.erl @@ -172,8 +172,8 @@ do_request(put_user, #{<<"username">> := UserName} = Body, #{<<"sessionToken">> do_request(get_users_id, Body, #{<<"sessionToken">> := SessionToken}, _Req) -> case dgiot_parse_auth:get_user(Body, SessionToken) of {ok, Data} -> - dgiot_role:load_user(), - dgiot_parse_auth:load_roleuser(), +%% dgiot_role:load_user(), +%% dgiot_parse_auth:load_roleuser(), {200, Data}; {error, Error} -> {500, Error} end;