From af1d91a200c2ebd329303dbe83e5df4fea31b498 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Wed, 28 Sep 2022 10:56:18 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=97=B6=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/.vscode/launch.json | 2 +- api/app/lib/controllers/alarm/data.js | 10 +++++----- api/app/lib/controllers/alarm/video.js | 6 +++--- api/app/lib/controllers/console/toolLink.js | 2 +- api/app/lib/controllers/project/index.js | 2 +- api/app/lib/middlewares/authenticator.js | 6 +++++- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/api/.vscode/launch.json b/api/.vscode/launch.json index 043f6c7..cab8159 100644 --- a/api/.vscode/launch.json +++ b/api/.vscode/launch.json @@ -51,7 +51,7 @@ // "--clickHouseDataAlarm default", // 测试 - "--clickHouseAnxincloud Anxinyun11", + "--clickHouseAnxincloud Anxinyun12", "--clickHousePepEmis pepca8", "--clickHouseProjectManage peppm8", "--clickHouseVcmp video_access_dev", diff --git a/api/app/lib/controllers/alarm/data.js b/api/app/lib/controllers/alarm/data.js index da8d3a5..8a1742e 100644 --- a/api/app/lib/controllers/alarm/data.js +++ b/api/app/lib/controllers/alarm/data.js @@ -19,7 +19,7 @@ async function groupList (ctx) { ctx.status = 200; ctx.body = groupRes } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: error`); + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { message: typeof error == 'string' ? error : undefined @@ -215,7 +215,7 @@ async function detail (ctx) { ctx.status = 200; ctx.body = detailRes } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: error`); + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { message: typeof error == 'string' ? error : undefined @@ -274,7 +274,7 @@ function confirm (opts) { ctx.status = 204; } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: error`); + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { message: typeof error == 'string' ? error : undefined @@ -304,7 +304,7 @@ async function detailAggregation (ctx) { ctx.status = 200; ctx.body = alarmDetailAggRes } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: error`); + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { message: typeof error == 'string' ? error : undefined @@ -324,7 +324,7 @@ async function alarmCount (ctx) { ctx.status = 200; ctx.body = alarmUnconfirmedAggRes } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: error`); + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { message: typeof error == 'string' ? error : undefined diff --git a/api/app/lib/controllers/alarm/video.js b/api/app/lib/controllers/alarm/video.js index d626c32..167b3ec 100644 --- a/api/app/lib/controllers/alarm/video.js +++ b/api/app/lib/controllers/alarm/video.js @@ -6,7 +6,7 @@ async function deviceType (ctx) { ctx.status = 200; ctx.body = [] } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: error`); + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { message: typeof error == 'string' ? error : undefined @@ -146,7 +146,7 @@ async function alarmList (ctx) { ctx.status = 200; ctx.body = returnD } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: error`); + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { message: typeof error == 'string' ? error : undefined @@ -160,7 +160,7 @@ async function confirm (ctx) { ctx.status = 20; } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: error`); + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { message: typeof error == 'string' ? error : undefined diff --git a/api/app/lib/controllers/console/toolLink.js b/api/app/lib/controllers/console/toolLink.js index 5ce1b45..c5cd9a3 100644 --- a/api/app/lib/controllers/console/toolLink.js +++ b/api/app/lib/controllers/console/toolLink.js @@ -6,7 +6,7 @@ async function add (ctx) { ctx.status = 20; } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: error`); + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { message: typeof error == 'string' ? error : undefined diff --git a/api/app/lib/controllers/project/index.js b/api/app/lib/controllers/project/index.js index fa9c688..1ecccec 100644 --- a/api/app/lib/controllers/project/index.js +++ b/api/app/lib/controllers/project/index.js @@ -96,7 +96,7 @@ async function pomsProject (ctx) { ctx.status = 200; ctx.body = proRes } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: error`); + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { message: typeof error == 'string' ? error : undefined diff --git a/api/app/lib/middlewares/authenticator.js b/api/app/lib/middlewares/authenticator.js index 7d17ddb..1bc7416 100644 --- a/api/app/lib/middlewares/authenticator.js +++ b/api/app/lib/middlewares/authenticator.js @@ -66,14 +66,16 @@ let isPathExcluded = function (opts, path, method) { }; let authorizeToken = async function (ctx, token) { + let startTime = moment() let rslt = null; const tokenFormatRegexp = /^(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$/g; if (token && tokenFormatRegexp.test(token)) { try { - + console.log(`DurationCalc: auth 1 用时 ${moment().diff(startTime, 'milliseconds')}`); const authorizeRes = await ctx.app.fs.emisRequest.get('authorize', { query: { token } }) + console.log(`DurationCalc: auth 2 用时 ${moment().diff(startTime, 'milliseconds')}`); const { userInfo, expired } = authorizeRes; if (expired && moment().valueOf() <= moment(expired).valueOf()) { const pomsUser = await ctx.app.fs.dc.models.User.findOne({ @@ -81,6 +83,7 @@ let authorizeToken = async function (ctx, token) { pepUserId: userInfo.id } }) || {} + console.log(`DurationCalc: auth 3 用时 ${moment().diff(startTime, 'milliseconds')}`); rslt = { 'authorized': userInfo.authorized, 'resources': (userInfo || {}).resources || [], @@ -91,6 +94,7 @@ let authorizeToken = async function (ctx, token) { ctx.fs.api.pepUserInfo = userInfo; ctx.fs.api.token = token; } + console.log(`DurationCalc: auth 4 用时 ${moment().diff(startTime, 'milliseconds')}`); } catch (err) { const { error } = err.response || {}; ctx.fs.logger.log('[anxinyun]', '[AUTH] failed', (error || {}).message || `cannot GET /users/${token}`);