diff --git a/back/api/subscription.ts b/back/api/subscription.ts index a03ee895..85587a16 100644 --- a/back/api/subscription.ts +++ b/back/api/subscription.ts @@ -15,6 +15,7 @@ export default (app: Router) => { const subscriptionService = Container.get(SubscriptionService); const data = await subscriptionService.list( req.query.searchValue as string, + req.query.ids as string, ); return res.send({ code: 200, data }); } catch (e) { @@ -212,8 +213,8 @@ export default (app: Router) => { body: Joi.array().items(Joi.number().required()), query: Joi.object({ force: Joi.boolean().optional(), - t: Joi.number() - }) + t: Joi.number(), + }), }), async (req: Request, res: Response, next: NextFunction) => { const logger: Logger = Container.get('logger'); diff --git a/back/services/cron.ts b/back/services/cron.ts index ac941c57..c9130e9b 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -12,7 +12,7 @@ import { getUniqPath, safeJSONParse, } from '../config/util'; -import { Op, where, col as colFn, FindOptions, fn } from 'sequelize'; +import { Op, where, col as colFn, FindOptions, fn, Order } from 'sequelize'; import path from 'path'; import { TASK_PREFIX, QL_PREFIX } from '../config/const'; import cronClient from '../schedule/client'; @@ -362,9 +362,9 @@ export default class CronService { order.unshift([field, type]); } } - let condition: any = { + let condition: FindOptions = { where: query, - order: order, + order: order as Order, }; if (page && size) { condition.offset = (page - 1) * size; diff --git a/back/services/subscription.ts b/back/services/subscription.ts index 974b6b70..5286648d 100644 --- a/back/services/subscription.ts +++ b/back/services/subscription.ts @@ -41,8 +41,12 @@ export default class SubscriptionService { private crontabService: CrontabService, ) {} - public async list(searchText?: string): Promise { + public async list( + searchText?: string, + ids?: string, + ): Promise { let query = {}; + const subIds = JSON.parse(ids || '[]'); if (searchText) { const reg = { [Op.or]: [ @@ -63,7 +67,7 @@ export default class SubscriptionService { } try { const result = await SubscriptionModel.findAll({ - where: query, + where: { ...query, ...(ids ? { id: subIds } : undefined) }, order: [ ['is_disabled', 'ASC'], ['createdAt', 'DESC'], diff --git a/shell/rmlog.sh b/shell/rmlog.sh index 7d183014..9e67f3a2 100755 --- a/shell/rmlog.sh +++ b/shell/rmlog.sh @@ -2,34 +2,37 @@ days=$1 -## 删除运行脚本的旧日志 remove_js_log() { - local log_full_path_list=$(find $dir_log/ -name "*.log") + local log_full_path_list=$(find $dir_log -name "*.log") local diff_time for log in $log_full_path_list; do - local log_date=$(echo $log | awk -F "/" '{print $NF}' | cut -c1-10) #文件名比文件属性获得的日期要可靠 - if [[ $(date +%s -d $log_date 2>/dev/null) ]]; then + local log_date=$(echo $log | awk -F "/" '{print $NF}' | cut -c1-10) + if ! [[ $log_date =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then if [[ $is_macos -eq 1 ]]; then - diff_time=$(($(date +%s) - $(date -j -f "%Y-%m-%d" "$log_date" +%s))) + log_date=$(stat -f %Sm -t "%Y-%m-%d" "$log") else - diff_time=$(($(date +%s) - $(date +%s -d "$log_date"))) + log_date=$(stat -c %y "$log" | cut -d ' ' -f 1) fi - if [[ $diff_time -gt $((${days} * 86400)) ]]; then - local log_path=$(echo "$log" | sed "s,${dir_log}/,,g") - local result=$(find_cron_api "log_path=$log_path") - echo -e "查询文件 $log_path" - if [[ -z $result ]]; then - echo -e "删除中~" - rm -vf $log - else - echo -e "正在被 $result 使用,跳过~" - fi + fi + if [[ $is_macos -eq 1 ]]; then + diff_time=$(($(date +%s) - $(date -j -f "%Y-%m-%d" "$log_date" +%s))) + else + diff_time=$(($(date +%s) - $(date +%s -d "$log_date"))) + fi + if [[ $diff_time -gt $((${days} * 86400)) ]]; then + local log_path=$(echo "$log" | sed "s,${dir_log}/,,g") + local result=$(find_cron_api "log_path=$log_path") + echo -e "查询文件 $log_path" + if [[ -z $result ]]; then + echo -e "删除中~" + rm -vf $log + else + echo -e "正在被 $result 使用,跳过~" fi fi done } -## 删除空文件夹 remove_empty_dir() { cd $dir_log for dir in $(ls); do @@ -39,7 +42,6 @@ remove_empty_dir() { done } -## 运行 if [[ ${days} ]]; then echo -e "查找旧日志文件中...\n" remove_js_log diff --git a/src/pages/crontab/index.tsx b/src/pages/crontab/index.tsx index c83ff1a2..2e1848fd 100644 --- a/src/pages/crontab/index.tsx +++ b/src/pages/crontab/index.tsx @@ -267,22 +267,7 @@ const Crontab = () => { { title: intl.get('关联订阅'), width: 185, - render: (text, record: any) => - record.sub_id ? ( - - request.get(`${config.apiPrefix}subscriptions/${record.sub_id}`, { - onError: noop, - }) - } - options={{ - ready: record?.sub_id, - cacheKey: record.sub_id, - }} - /> - ) : ( - '-' - ), + render: (text, record: any) => record?.subscription?.name || '-', }, { title: intl.get('操作'), @@ -392,14 +377,27 @@ const Crontab = () => { } request .get(url) - .then(({ code, data: _data }) => { + .then(async ({ code, data: _data }) => { if (code === 200) { const { data, total } = _data; + const subscriptions = await request.get( + `${config.apiPrefix}subscriptions?ids=${JSON.stringify([ + ...new Set(data.map((x) => x.sub_id).filter(Boolean)), + ])}`, + { + onError: noop, + }, + ); + const subscriptionMap = Object.fromEntries( + subscriptions?.data?.map((x) => [x.id, x]), + ); + setValue( data.map((x) => { return { ...x, nextRunTime: getCrontabsNextDate(x.schedule, x.extra_schedules), + subscription: subscriptionMap?.[x.sub_id], }; }), );