mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-22 22:36:06 +08:00
修复删除日志命令
This commit is contained in:
parent
4e5ad6d5f3
commit
8b042d90f3
|
@ -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');
|
||||
|
|
|
@ -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<Crontab> = {
|
||||
where: query,
|
||||
order: order,
|
||||
order: order as Order,
|
||||
};
|
||||
if (page && size) {
|
||||
condition.offset = (page - 1) * size;
|
||||
|
|
|
@ -41,8 +41,12 @@ export default class SubscriptionService {
|
|||
private crontabService: CrontabService,
|
||||
) {}
|
||||
|
||||
public async list(searchText?: string): Promise<Subscription[]> {
|
||||
public async list(
|
||||
searchText?: string,
|
||||
ids?: string,
|
||||
): Promise<Subscription[]> {
|
||||
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'],
|
||||
|
|
|
@ -2,13 +2,18 @@
|
|||
|
||||
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
|
||||
log_date=$(stat -f %Sm -t "%Y-%m-%d" "$log")
|
||||
else
|
||||
log_date=$(stat -c %y "$log" | cut -d ' ' -f 1)
|
||||
fi
|
||||
fi
|
||||
if [[ $is_macos -eq 1 ]]; then
|
||||
diff_time=$(($(date +%s) - $(date -j -f "%Y-%m-%d" "$log_date" +%s)))
|
||||
else
|
||||
|
@ -25,11 +30,9 @@ remove_js_log() {
|
|||
echo -e "正在被 $result 使用,跳过~"
|
||||
fi
|
||||
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
|
||||
|
|
|
@ -267,22 +267,7 @@ const Crontab = () => {
|
|||
{
|
||||
title: intl.get('关联订阅'),
|
||||
width: 185,
|
||||
render: (text, record: any) =>
|
||||
record.sub_id ? (
|
||||
<Name
|
||||
service={() =>
|
||||
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],
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue
Block a user