From ad6e08525c409c503b2acb4bdd8cb604870a347c Mon Sep 17 00:00:00 2001 From: whyour Date: Sun, 12 Jan 2025 15:39:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20QLAPI=20=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back.d.ts | 9 +++++++++ back/schedule/api.ts | 9 +++------ back/services/user.ts | 10 +--------- sample/ql_sample.js | 12 ++++++------ sample/ql_sample.py | 6 ++++-- shell/preload/client.js | 1 - tsconfig.back.json | 2 +- 7 files changed, 24 insertions(+), 25 deletions(-) create mode 100644 back.d.ts diff --git a/back.d.ts b/back.d.ts new file mode 100644 index 00000000..8a89e1f6 --- /dev/null +++ b/back.d.ts @@ -0,0 +1,9 @@ +import 'express'; + +declare global { + namespace Express { + interface Request { + platform: string; + } + } +} diff --git a/back/schedule/api.ts b/back/schedule/api.ts index 9402359a..e650cfad 100644 --- a/back/schedule/api.ts +++ b/back/schedule/api.ts @@ -20,8 +20,8 @@ import { UpdateEnvRequest, } from '../protos/api'; import LoggerInstance from '../loaders/logger'; -import NotificationService from '../services/notify'; import pick from 'lodash/pick'; +import SystemService from '../services/system'; Container.set('logger', LoggerInstance); @@ -165,11 +165,8 @@ export const systemNotify = async ( callback: sendUnaryData, ) => { try { - const notifyService = Container.get(NotificationService); - const data = await notifyService.notify( - call.request.title, - call.request.content, - ); + const systemService = Container.get(SystemService); + const data = await systemService.notify(call.request); callback(null, { code: 200, data }); } catch (e: any) { callback(e); diff --git a/back/services/user.ts b/back/services/user.ts index e6a98b19..22a9edff 100644 --- a/back/services/user.ts +++ b/back/services/user.ts @@ -1,15 +1,7 @@ import { Service, Inject } from 'typedi'; import winston from 'winston'; -import { - createFile, - createRandomString, - fileExist, - getNetIp, - getPlatform, - safeJSONParse, -} from '../config/util'; +import { createRandomString, getNetIp } from '../config/util'; import config from '../config'; -import * as fs from 'fs/promises'; import jwt from 'jsonwebtoken'; import { authenticator } from '@otplib/preset-default'; import { diff --git a/sample/ql_sample.js b/sample/ql_sample.js index e9d7e737..4d64568e 100644 --- a/sample/ql_sample.js +++ b/sample/ql_sample.js @@ -6,10 +6,10 @@ */ console.log('test scripts'); QLAPI.notify('test scripts', 'test desc'); -QLAPI.getEnvs({ searchValue: 'dddd' }).then(x => { - console.log(x) -}) -QLAPI.systemNotify({ title: '123', content: '231' }).then(x => { - console.log(x) -}) +QLAPI.getEnvs({ searchValue: 'dddd' }).then((x) => { + console.log('getEnvs', x); +}); +QLAPI.systemNotify({ title: '123', content: '231' }).then((x) => { + console.log('systemNotify', x); +}); console.log('test desc'); diff --git a/sample/ql_sample.py b/sample/ql_sample.py index 1eff36a4..e61700f3 100644 --- a/sample/ql_sample.py +++ b/sample/ql_sample.py @@ -6,7 +6,9 @@ cron: 1 9 * * * """ print("test script") -QLAPI.notify("test script", "test desc") -QLAPI.systemNotify({"title": "test script", "content": "dddd"}) +print(QLAPI.notify("test script", "test desc")) +print("test systemNotify") +print(QLAPI.systemNotify({"title": "test script", "content": "dddd"})) +print("test getEnvs") print(QLAPI.getEnvs("1")) print("test desc") diff --git a/shell/preload/client.js b/shell/preload/client.js index 2f6adcab..9da5c1dd 100644 --- a/shell/preload/client.js +++ b/shell/preload/client.js @@ -1,7 +1,6 @@ const grpc = require('@grpc/grpc-js'); const protoLoader = require('@grpc/proto-loader'); -console.log(process.env.QL_DIR); const PROTO_PATH = `${process.env.QL_DIR}/back/protos/api.proto`; const options = { keepCase: true, diff --git a/tsconfig.back.json b/tsconfig.back.json index 18c7c610..12c22445 100644 --- a/tsconfig.back.json +++ b/tsconfig.back.json @@ -18,7 +18,7 @@ "noEmit": false, "esModuleInterop": true }, - "include": ["./back/**/*"], + "include": ["./back/**/*", "./back.d.ts"], "exclude": ["node_modules"], "files": ["./back/index.d.ts"] }