修改内置token获取方式

This commit is contained in:
whyour 2022-08-11 13:13:37 +08:00
parent 53414e5d70
commit a7117e4442
4 changed files with 22 additions and 8 deletions

View File

@ -3,12 +3,30 @@ import _ from 'lodash';
import SystemService from '../services/system'; import SystemService from '../services/system';
import ScheduleService from '../services/schedule'; import ScheduleService from '../services/schedule';
import SubscriptionService from '../services/subscription'; import SubscriptionService from '../services/subscription';
import config from '../config';
import { fileExist } from '../config/util';
export default async () => { export default async () => {
const systemService = Container.get(SystemService); const systemService = Container.get(SystemService);
const scheduleService = Container.get(ScheduleService); const scheduleService = Container.get(ScheduleService);
const subscriptionService = Container.get(SubscriptionService); 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(); const data = await systemService.getLogRemoveFrequency();
if (data && data.info && data.info.frequency) { if (data && data.info && data.info.frequency) {
@ -17,7 +35,7 @@ export default async () => {
name: '删除日志', name: '删除日志',
command: `ql rmlog ${data.info.frequency}`, command: `ql rmlog ${data.info.frequency}`,
}; };
await scheduleService.createIntervalTask(cron, { scheduleService.createIntervalTask(cron, {
days: data.info.frequency, days: data.info.frequency,
runImmediately: true, runImmediately: true,
}); });

View File

@ -169,7 +169,7 @@ export default class ScheduleService {
); );
const job = new LongIntervalJob( const job = new LongIntervalJob(
{ ...schedule, runImmediately: false }, { runImmediately: false, ...schedule },
task, task,
_id, _id,
); );

View File

@ -1,12 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
get_token() { get_token() {
local tokenFile="$dir_static/build/token.js" token=$(cat $file_auth_token | jq -r .value)
if [[ ! -f "$tokenFile" ]]; then
token=$(ts-node-transpile-only "$dir_root/back/token.ts")
else
token=$(node "$tokenFile")
fi
} }
add_cron_api() { add_cron_api() {

View File

@ -24,6 +24,7 @@ file_sharecode=$dir_config/sharecode.sh
file_config_user=$dir_config/config.sh file_config_user=$dir_config/config.sh
file_auth_sample=$dir_sample/auth.sample.json file_auth_sample=$dir_sample/auth.sample.json
file_auth_user=$dir_config/auth.json file_auth_user=$dir_config/auth.json
file_auth_token=$dir_config/token.json
file_extra_shell=$dir_config/extra.sh file_extra_shell=$dir_config/extra.sh
file_task_before=$dir_config/task_before.sh file_task_before=$dir_config/task_before.sh
file_task_after=$dir_config/task_after.sh file_task_after=$dir_config/task_after.sh