From 42dabbf4c02f4f413c59d28ead881b59932241c5 Mon Sep 17 00:00:00 2001 From: whyour Date: Mon, 18 Jul 2022 15:41:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=86=85=E7=BD=AEtoken?= =?UTF-8?q?=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/app.ts | 12 ------------ back/config/index.ts | 9 +++++++++ back/services/open.ts | 1 + {shell => back}/token.ts | 6 +++--- shell/api.sh | 7 ++++++- 5 files changed, 19 insertions(+), 16 deletions(-) rename {shell => back}/token.ts (90%) diff --git a/back/app.ts b/back/app.ts index f7ebb0ef..daad0526 100644 --- a/back/app.ts +++ b/back/app.ts @@ -27,16 +27,4 @@ async function startServer() { await require('./loaders/server').default({ server }); } -function initEnv() { - process.env.NODE_ENV = process.env.NODE_ENV || 'development'; - // 声明QL_DIR环境变量 - let qlHomePath = path.join(__dirname, '../../'); - // 生产环境 - if (qlHomePath.endsWith('/static/')) { - qlHomePath = path.join(qlHomePath, '../'); - } - process.env.QL_DIR = qlHomePath; -} - -initEnv(); startServer(); diff --git a/back/config/index.ts b/back/config/index.ts index 9f8f8848..b8e2ece1 100644 --- a/back/config/index.ts +++ b/back/config/index.ts @@ -2,6 +2,15 @@ import dotenv from 'dotenv'; import path from 'path'; import { createRandomString } from './util'; +process.env.NODE_ENV = process.env.NODE_ENV || 'development'; +// 声明QL_DIR环境变量 +let qlHomePath = path.join(__dirname, '../../'); +// 生产环境 +if (qlHomePath.endsWith('/static/')) { + qlHomePath = path.join(qlHomePath, '../'); +} +process.env.QL_DIR = qlHomePath; + const lastVersionFile = `http://qn.whyour.cn/version.ts?v=${Date.now()}`; const envFound = dotenv.config(); diff --git a/back/services/open.ts b/back/services/open.ts index 176c9201..fb31e82d 100644 --- a/back/services/open.ts +++ b/back/services/open.ts @@ -170,6 +170,7 @@ export default class OpenService { client_secret: systemApp.client_secret, }); token = authToken.data; + token.value = token.token; } else { token = [...systemApp.tokens].pop(); } diff --git a/shell/token.ts b/back/token.ts similarity index 90% rename from shell/token.ts rename to back/token.ts index bc74a6ab..85c1ab89 100755 --- a/shell/token.ts +++ b/back/token.ts @@ -1,9 +1,9 @@ import 'reflect-metadata'; -import OpenService from '../back/services/open'; +import OpenService from './services/open'; import { Container } from 'typedi'; -import LoggerInstance from '../back/loaders/logger'; +import LoggerInstance from './loaders/logger'; import fs from 'fs'; -import config from '../back/config'; +import config from './config'; import path from 'path'; const tokenFile = path.join(config.configPath, 'token.json'); diff --git a/shell/api.sh b/shell/api.sh index 30f69120..4d4ac5be 100755 --- a/shell/api.sh +++ b/shell/api.sh @@ -1,7 +1,12 @@ #!/usr/bin/env bash get_token() { - token=$(ts-node-transpile-only "$dir_shell/token.ts") + local tokenFile="$dir_static/build/token.js" + if [[ ! -f "$tokenFile" ]]; then + token=$(ts-node-transpile-only "$dir_root/back/token.ts") + else + token=$(node "$tokenFile") + fi } add_cron_api() {