diff --git a/back/loaders/initTask.ts b/back/loaders/initTask.ts index 98feb965..987c129a 100644 --- a/back/loaders/initTask.ts +++ b/back/loaders/initTask.ts @@ -3,12 +3,30 @@ import _ from 'lodash'; import SystemService from '../services/system'; import ScheduleService from '../services/schedule'; import SubscriptionService from '../services/subscription'; +import config from '../config'; +import { fileExist } from '../config/util'; export default async () => { const systemService = Container.get(SystemService); const scheduleService = Container.get(ScheduleService); const subscriptionService = Container.get(SubscriptionService); + // 生成内置token + let tokenCommand = `ts-node-transpile-only ${config.rootPath}/back/token.ts`; + const tokenFile = `${config.rootPath}/static/build/token.js`; + if (await fileExist(tokenFile)) { + tokenCommand = `node ${tokenFile}`; + } + const cron = { + id: 'token', + name: '生成token', + command: tokenCommand, + }; + scheduleService.createIntervalTask(cron as any, { + days: 28, + runImmediately: true, + }); + // 运行删除日志任务 const data = await systemService.getLogRemoveFrequency(); if (data && data.info && data.info.frequency) { @@ -17,7 +35,7 @@ export default async () => { name: '删除日志', command: `ql rmlog ${data.info.frequency}`, }; - await scheduleService.createIntervalTask(cron, { + scheduleService.createIntervalTask(cron, { days: data.info.frequency, runImmediately: true, }); diff --git a/back/services/schedule.ts b/back/services/schedule.ts index b11a2b28..acfb9530 100644 --- a/back/services/schedule.ts +++ b/back/services/schedule.ts @@ -169,7 +169,7 @@ export default class ScheduleService { ); const job = new LongIntervalJob( - { ...schedule, runImmediately: false }, + { runImmediately: false, ...schedule }, task, _id, ); diff --git a/shell/api.sh b/shell/api.sh index 4d4ac5be..557ad8f1 100755 --- a/shell/api.sh +++ b/shell/api.sh @@ -1,12 +1,7 @@ #!/usr/bin/env bash get_token() { - 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 + token=$(cat $file_auth_token | jq -r .value) } add_cron_api() { diff --git a/shell/share.sh b/shell/share.sh index d9e34776..4b6147d1 100755 --- a/shell/share.sh +++ b/shell/share.sh @@ -24,6 +24,7 @@ file_sharecode=$dir_config/sharecode.sh file_config_user=$dir_config/config.sh file_auth_sample=$dir_sample/auth.sample.json file_auth_user=$dir_config/auth.json +file_auth_token=$dir_config/token.json file_extra_shell=$dir_config/extra.sh file_task_before=$dir_config/task_before.sh file_task_after=$dir_config/task_after.sh