From 4194f1964da6a4aceb4b15dc0b90c7d7c333194a Mon Sep 17 00:00:00 2001 From: whyour Date: Thu, 20 Oct 2022 15:16:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=A5=E5=BF=97=E7=BB=93?= =?UTF-8?q?=E6=9D=9F=E7=AC=A6=E5=88=A4=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/config/const.ts | 1 + back/services/cron.ts | 3 ++- back/services/script.ts | 3 ++- back/services/subscription.ts | 5 +++-- shell/task.sh | 1 + shell/update.sh | 15 ++++++++------- src/pages/crontab/logModal.tsx | 5 +++-- src/pages/script/editModal.tsx | 3 ++- src/pages/subscription/logModal.tsx | 5 +++-- src/utils/const.ts | 1 + src/utils/index.ts | 7 +++++++ tsconfig.back.json | 3 +++ 12 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 back/config/const.ts create mode 100644 src/utils/const.ts diff --git a/back/config/const.ts b/back/config/const.ts new file mode 100644 index 00000000..7bddf45c --- /dev/null +++ b/back/config/const.ts @@ -0,0 +1 @@ +export const LOG_END_SYMBOL = '\n          '; \ No newline at end of file diff --git a/back/services/cron.ts b/back/services/cron.ts index 8471df21..bbf6fa2e 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -11,6 +11,7 @@ import { promisify } from 'util'; import { Op } from 'sequelize'; import path from 'path'; import dayjs from 'dayjs'; +import { LOG_END_SYMBOL } from '../config/const'; @Service() export default class CronService { @@ -335,7 +336,7 @@ export default class CronService { `${absolutePath}`, `${str}\n## 执行结束... ${endTime.format( 'YYYY-MM-DD HH:mm:ss', - )}${diffTimeStr}`, + )}${diffTimeStr}${LOG_END_SYMBOL}`, ); } } diff --git a/back/services/script.ts b/back/services/script.ts index 9cadd6fb..74178a4e 100644 --- a/back/services/script.ts +++ b/back/services/script.ts @@ -6,6 +6,7 @@ import SockService from './sock'; import CronService from './cron'; import ScheduleService, { TaskCallbacks } from './schedule'; import config from '../config'; +import { LOG_END_SYMBOL } from '../config/const'; @Service() export default class ScriptService { @@ -55,7 +56,7 @@ export default class ScriptService { type: 'manuallyRunScript', message: `${str}\n## 执行结束... ${new Date() .toLocaleString('zh', { hour12: false }) - .replace(' 24:', ' 00:')} `, + .replace(' 24:', ' 00:')}${LOG_END_SYMBOL}`, }); return { code: 200 }; diff --git a/back/services/subscription.ts b/back/services/subscription.ts index 205567a5..6cb3cc3b 100644 --- a/back/services/subscription.ts +++ b/back/services/subscription.ts @@ -29,6 +29,7 @@ import { SimpleIntervalSchedule } from 'toad-scheduler'; import SockService from './sock'; import SshKeyService from './sshKey'; import dayjs from 'dayjs'; +import { LOG_END_SYMBOL } from '../config/const'; @Service() export default class SubscriptionService { @@ -232,7 +233,7 @@ export default class SubscriptionService { absolutePath, `\n## 执行结束... ${endTime.format( 'YYYY-MM-DD HH:mm:ss', - )} 耗时 ${diff} 秒`, + )} 耗时 ${diff} 秒${LOG_END_SYMBOL}`, ); await SubscriptionModel.update( @@ -353,7 +354,7 @@ export default class SubscriptionService { fs.appendFileSync( `${absolutePath}`, - `${str}\n## 执行结束... ${dayjs().format('YYYY-MM-DD HH:mm:ss')} `, + `${str}\n## 执行结束... ${dayjs().format('YYYY-MM-DD HH:mm:ss')}${LOG_END_SYMBOL}`, ); } diff --git a/shell/task.sh b/shell/task.sh index 9e523980..3306d60d 100755 --- a/shell/task.sh +++ b/shell/task.sh @@ -157,6 +157,7 @@ handle_task_after() { local diff_time=$(($end_timestamp - $begin_timestamp)) [[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time" eval echo -e "\\\n\\\n\#\# 执行结束... $end_time 耗时 $diff_time 秒" $cmd + eval echo -e "\\\n     " $cmd } ## 正常运行单个脚本,$1:传入参数 diff --git a/shell/update.sh b/shell/update.sh index 5291b34c..53f579fd 100755 --- a/shell/update.sh +++ b/shell/update.sh @@ -464,8 +464,8 @@ main() { if [[ -n $p2 ]]; then update_repo "$p2" "$p3" "$p4" "$p5" "$p6" "$p7" else - echo -e "命令输入错误...\n" - usage + eval echo -e "命令输入错误...\\\n" + eval usage $cmd fi ;; raw) @@ -473,8 +473,8 @@ main() { if [[ -n $p2 ]]; then update_raw "$p2" else - echo -e "命令输入错误...\n" - usage + eval echo -e "命令输入错误...\\\n" + eval usage $cmd fi ;; rmlog) @@ -497,16 +497,17 @@ main() { echo "$auth_value" >$file_auth_user ;; *) - echo -e "命令输入错误...\n" - usage + eval echo -e "命令输入错误...\\\n" $cmd + eval usage $cmd ;; esac if [[ -f $file_path ]]; then - cat $file_path local end_timestamp=$(date "+%s") local diff_time=$(($end_timestamp - $begin_timestamp)) [[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time" + eval echo -e "\\\n          " $cmd + cat $file_path fi } diff --git a/src/pages/crontab/logModal.tsx b/src/pages/crontab/logModal.tsx index a80214f0..ce43f985 100644 --- a/src/pages/crontab/logModal.tsx +++ b/src/pages/crontab/logModal.tsx @@ -7,6 +7,7 @@ import { CheckCircleOutlined, } from '@ant-design/icons'; import { PageLoading } from '@ant-design/pro-layout'; +import { logEnded } from '@/utils'; enum CrontabStatus { 'running', @@ -49,9 +50,9 @@ const CronLogModal = ({ const log = data as string; setValue(log || '暂无日志'); setExecuting( - log && !log.includes('执行结束') && !log.includes('重启面板'), + log && !logEnded(log) && !log.includes('重启面板'), ); - if (log && !log.includes('执行结束') && !log.includes('重启面板')) { + if (log && !logEnded(log) && !log.includes('重启面板')) { setTimeout(() => { getCronLog(); }, 2000); diff --git a/src/pages/script/editModal.tsx b/src/pages/script/editModal.tsx index b79264d2..7f0c63af 100644 --- a/src/pages/script/editModal.tsx +++ b/src/pages/script/editModal.tsx @@ -7,6 +7,7 @@ import Editor from '@monaco-editor/react'; import SaveModal from './saveModal'; import SettingModal from './setting'; import { useTheme } from '@/utils/hooks'; +import { logEnded } from '@/utils'; const { Option } = Select; const LangMap: any = { @@ -128,7 +129,7 @@ const EditModal = ({ return; } - if (_message.includes('执行结束')) { + if (logEnded(_message)) { setTimeout(() => { setIsRunning(false); }, 300); diff --git a/src/pages/subscription/logModal.tsx b/src/pages/subscription/logModal.tsx index 58dc2775..f450b36b 100644 --- a/src/pages/subscription/logModal.tsx +++ b/src/pages/subscription/logModal.tsx @@ -7,6 +7,7 @@ import { CheckCircleOutlined, } from '@ant-design/icons'; import { PageLoading } from '@ant-design/pro-layout'; +import { logEnded } from '@/utils'; const SubscriptionLogModal = ({ subscription, @@ -43,8 +44,8 @@ const SubscriptionLogModal = ({ ) { const log = data as string; setValue(log || '暂无日志'); - setExecuting(log && !log.includes('执行结束')); - if (log && !log.includes('执行结束')) { + setExecuting(log && !logEnded(log)); + if (log && !logEnded(log)) { setTimeout(() => { getCronLog(); }, 2000); diff --git a/src/utils/const.ts b/src/utils/const.ts new file mode 100644 index 00000000..7bddf45c --- /dev/null +++ b/src/utils/const.ts @@ -0,0 +1 @@ +export const LOG_END_SYMBOL = '\n          '; \ No newline at end of file diff --git a/src/utils/index.ts b/src/utils/index.ts index e7f73fdb..c3ab2435 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,3 +1,5 @@ +import { LOG_END_SYMBOL } from "./const"; + export default function browserType() { // 权重:系统 + 系统版本 > 平台 > 内核 + 载体 + 内核版本 + 载体版本 > 外壳 + 外壳版本 const ua = navigator.userAgent.toLowerCase(); @@ -273,3 +275,8 @@ export function depthFirstSearch< return c; } + +export function logEnded(log: string): boolean { + const endTips = [LOG_END_SYMBOL, '执行结束']; + return endTips.some(x => !log.includes(x)); +} \ No newline at end of file diff --git a/tsconfig.back.json b/tsconfig.back.json index 40011037..bbe47867 100644 --- a/tsconfig.back.json +++ b/tsconfig.back.json @@ -7,6 +7,9 @@ "./src/types", "./node_modules/celebrate/lib/index.d.ts" ], + "paths": { + "@/*": ["back/*"], + }, "allowSyntheticDefaultImports": true, "experimentalDecorators": true, "emitDecoratorMetadata": true,