mirror of
https://github.com/whyour/qinglong.git
synced 2026-08-10 03:16:48 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d0c7ec39bf | |||
| a05d5df470 | |||
| ef98aa22d2 | |||
| e3fe662485 |
@@ -3,7 +3,7 @@ import { Container } from 'typedi';
|
||||
import { Logger } from 'winston';
|
||||
import SubscriptionService from '../services/subscription';
|
||||
import { celebrate, Joi } from 'celebrate';
|
||||
import { parseExpression } from 'cron-parser';
|
||||
import cron_parser from 'cron-parser';
|
||||
const route = Router();
|
||||
|
||||
export default (app: Router) => {
|
||||
@@ -60,7 +60,7 @@ export default (app: Router) => {
|
||||
try {
|
||||
if (
|
||||
!req.body.schedule ||
|
||||
parseExpression(req.body.schedule).hasNext()
|
||||
cron_parser.parseExpression(req.body.schedule).hasNext()
|
||||
) {
|
||||
const subscriptionService = Container.get(SubscriptionService);
|
||||
const data = await subscriptionService.create(req.body);
|
||||
@@ -193,7 +193,7 @@ export default (app: Router) => {
|
||||
if (
|
||||
!req.body.schedule ||
|
||||
typeof req.body.schedule === 'object' ||
|
||||
parseExpression(req.body.schedule).hasNext()
|
||||
cron_parser.parseExpression(req.body.schedule).hasNext()
|
||||
) {
|
||||
const subscriptionService = Container.get(SubscriptionService);
|
||||
const data = await subscriptionService.update(req.body);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import path from 'path';
|
||||
import fs from 'fs/promises';
|
||||
import chokidar, { FSWatcher } from 'chokidar';
|
||||
import chokidar from 'chokidar';
|
||||
import config from '../config/index';
|
||||
import { fileExist, promiseExec, rmPath } from '../config/util';
|
||||
|
||||
@@ -55,9 +55,9 @@ export default async (src: string = 'deps') => {
|
||||
const watcher = chokidar.watch(source, {
|
||||
ignored: /(^|[\/\\])\../, // ignore dotfiles
|
||||
persistent: true,
|
||||
}) as any;
|
||||
});
|
||||
|
||||
watcher
|
||||
.on('add', (_path: string) => linkToNodeModule(src))
|
||||
.on('change', (_path: string) => linkToNodeModule(src));
|
||||
.on('add', (path) => linkToNodeModule(src))
|
||||
.on('change', (path) => linkToNodeModule(src));
|
||||
};
|
||||
|
||||
@@ -4,7 +4,7 @@ import config from '../config';
|
||||
import { Crontab, CrontabModel, CrontabStatus } from '../data/cron';
|
||||
import { exec, execSync } from 'child_process';
|
||||
import fs from 'fs/promises';
|
||||
import { parseExpression } from 'cron-parser';
|
||||
import cron_parser from 'cron-parser';
|
||||
import {
|
||||
getFileContentByName,
|
||||
fileExist,
|
||||
@@ -670,7 +670,7 @@ export default class CronService {
|
||||
if (
|
||||
command &&
|
||||
schedule &&
|
||||
parseExpression(schedule).hasNext()
|
||||
cron_parser.parseExpression(schedule).hasNext()
|
||||
) {
|
||||
const name = namePrefix + '_' + index;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Joi } from 'celebrate';
|
||||
import { parseExpression } from 'cron-parser';
|
||||
import cron_parser from 'cron-parser';
|
||||
import { ScheduleType } from '../interface/schedule';
|
||||
|
||||
const validateSchedule = (value: string, helpers: any) => {
|
||||
@@ -11,7 +11,7 @@ const validateSchedule = (value: string, helpers: any) => {
|
||||
}
|
||||
|
||||
try {
|
||||
if (parseExpression(value).hasNext()) {
|
||||
if (cron_parser.parseExpression(value).hasNext()) {
|
||||
return value;
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
Generated
+13112
-9992
File diff suppressed because it is too large
Load Diff
+54
-31
@@ -66,6 +66,40 @@ const SHOW_TAB_COUNT = 10;
|
||||
|
||||
const Crontab = () => {
|
||||
const { headerStyle, isPhone, theme } = useOutletContext<SharedContext>();
|
||||
|
||||
// State declarations
|
||||
const [value, setValue] = useState<any[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [isModalVisible, setIsModalVisible] = useState(false);
|
||||
const [isLabelModalVisible, setIsLabelModalVisible] = useState(false);
|
||||
const [editedCron, setEditedCron] = useState();
|
||||
const [searchText, setSearchText] = useState('');
|
||||
const [isLogModalVisible, setIsLogModalVisible] = useState(false);
|
||||
const [logCron, setLogCron] = useState<any>();
|
||||
const [selectedRowIds, setSelectedRowIds] = useState<string[]>([]);
|
||||
const [pageConf, setPageConf] = useState<{
|
||||
page: number;
|
||||
size: number;
|
||||
sorter: any;
|
||||
filters: any;
|
||||
}>({} as any);
|
||||
const [viewConf, setViewConf] = useState<any>();
|
||||
const [isDetailModalVisible, setIsDetailModalVisible] = useState(false);
|
||||
const [detailCron, setDetailCron] = useState<any>();
|
||||
const [searchValue, setSearchValue] = useState('');
|
||||
const [total, setTotal] = useState<number>();
|
||||
const [isCreateViewModalVisible, setIsCreateViewModalVisible] =
|
||||
useState(false);
|
||||
const [isViewManageModalVisible, setIsViewManageModalVisible] =
|
||||
useState(false);
|
||||
const [cronViews, setCronViews] = useState<any[]>([]);
|
||||
const [enabledCronViews, setEnabledCronViews] = useState<any[]>([]);
|
||||
const [moreMenuActive, setMoreMenuActive] = useState(false);
|
||||
const tableRef = useRef<HTMLDivElement>(null);
|
||||
const tableScrollHeight = useTableScrollHeight(tableRef);
|
||||
const [activeKey, setActiveKey] = useState('');
|
||||
const [allSubscriptions, setAllSubscriptions] = useState<any[]>([]);
|
||||
|
||||
const columns: ColumnProps<ICrontab>[] = [
|
||||
{
|
||||
title: intl.get('名称'),
|
||||
@@ -270,7 +304,13 @@ const Crontab = () => {
|
||||
},
|
||||
{
|
||||
title: intl.get('关联订阅'),
|
||||
key: 'sub_id',
|
||||
dataIndex: 'sub_id',
|
||||
width: 185,
|
||||
filters: allSubscriptions.map((sub) => ({
|
||||
text: sub.name || sub.alias,
|
||||
value: sub.id,
|
||||
})),
|
||||
render: (text, record: any) => record?.subscription?.name || '-',
|
||||
},
|
||||
{
|
||||
@@ -317,37 +357,6 @@ const Crontab = () => {
|
||||
},
|
||||
];
|
||||
|
||||
const [value, setValue] = useState<any[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [isModalVisible, setIsModalVisible] = useState(false);
|
||||
const [isLabelModalVisible, setIsLabelModalVisible] = useState(false);
|
||||
const [editedCron, setEditedCron] = useState();
|
||||
const [searchText, setSearchText] = useState('');
|
||||
const [isLogModalVisible, setIsLogModalVisible] = useState(false);
|
||||
const [logCron, setLogCron] = useState<any>();
|
||||
const [selectedRowIds, setSelectedRowIds] = useState<string[]>([]);
|
||||
const [pageConf, setPageConf] = useState<{
|
||||
page: number;
|
||||
size: number;
|
||||
sorter: any;
|
||||
filters: any;
|
||||
}>({} as any);
|
||||
const [viewConf, setViewConf] = useState<any>();
|
||||
const [isDetailModalVisible, setIsDetailModalVisible] = useState(false);
|
||||
const [detailCron, setDetailCron] = useState<any>();
|
||||
const [searchValue, setSearchValue] = useState('');
|
||||
const [total, setTotal] = useState<number>();
|
||||
const [isCreateViewModalVisible, setIsCreateViewModalVisible] =
|
||||
useState(false);
|
||||
const [isViewManageModalVisible, setIsViewManageModalVisible] =
|
||||
useState(false);
|
||||
const [cronViews, setCronViews] = useState<any[]>([]);
|
||||
const [enabledCronViews, setEnabledCronViews] = useState<any[]>([]);
|
||||
const [moreMenuActive, setMoreMenuActive] = useState(false);
|
||||
const tableRef = useRef<HTMLDivElement>(null);
|
||||
const tableScrollHeight = useTableScrollHeight(tableRef);
|
||||
const [activeKey, setActiveKey] = useState('');
|
||||
|
||||
const goToScriptManager = (record: any) => {
|
||||
const result = getCommandScript(record.command);
|
||||
if (Array.isArray(result)) {
|
||||
@@ -801,6 +810,7 @@ const Crontab = () => {
|
||||
|
||||
useEffect(() => {
|
||||
getCronViews();
|
||||
getAllSubscriptions();
|
||||
}, []);
|
||||
|
||||
const viewAction = (key: string) => {
|
||||
@@ -886,6 +896,19 @@ const Crontab = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const getAllSubscriptions = () => {
|
||||
request
|
||||
.get(`${config.apiPrefix}subscriptions`)
|
||||
.then(({ code, data }) => {
|
||||
if (code === 200) {
|
||||
setAllSubscriptions(data || []);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
// Silently fail if subscriptions can't be loaded
|
||||
});
|
||||
};
|
||||
|
||||
const tabClick = (key: string) => {
|
||||
const view = enabledCronViews.find((x) => x.id == key);
|
||||
setSelectedRowIds([]);
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
} from 'antd';
|
||||
import { request } from '@/utils/http';
|
||||
import config from '@/utils/config';
|
||||
import { parseExpression } from 'cron-parser';
|
||||
import cron_parser from 'cron-parser';
|
||||
import isNil from 'lodash/isNil';
|
||||
|
||||
const { Option } = Select;
|
||||
@@ -381,7 +381,7 @@ const SubscriptionModal = ({
|
||||
if (
|
||||
scheduleType === 'interval' ||
|
||||
!value ||
|
||||
parseExpression(value).hasNext()
|
||||
cron_parser.parseExpression(value).hasNext()
|
||||
) {
|
||||
return Promise.resolve();
|
||||
} else {
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
import intl from 'react-intl-universal';
|
||||
import { LANG_MAP, LOG_END_SYMBOL } from './const';
|
||||
import { parseExpression } from 'cron-parser';
|
||||
import cron_parser from 'cron-parser';
|
||||
import { ICrontab } from '@/pages/crontab/type';
|
||||
|
||||
export default function browserType() {
|
||||
@@ -333,7 +333,7 @@ export function getCommandScript(
|
||||
|
||||
export function parseCrontab(schedule: string): Date | null {
|
||||
try {
|
||||
const time = parseExpression(schedule);
|
||||
const time = cron_parser.parseExpression(schedule);
|
||||
if (time) {
|
||||
return time.next().toDate();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user