mirror of
https://github.com/whyour/qinglong.git
synced 2025-12-23 15:50:07 +08:00
Fix cron-parser v5 bundling incompatibility causing validation failures (#2877)
* Initial plan
* Fix: Use default import for cron-parser to ensure browser compatibility
Changed from named export `{ CronExpressionParser }` to default export `cronParser` and access `CronExpressionParser` through it. This ensures compatibility with webpack/UmiJS bundling for browser environments while maintaining backend functionality.
Co-authored-by: whyour <22700758+whyour@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: whyour <22700758+whyour@users.noreply.github.com>
This commit is contained in:
parent
fae226745e
commit
3db716763d
|
|
@ -3,7 +3,7 @@ import config from '@/utils/config';
|
||||||
import { request } from '@/utils/http';
|
import { request } from '@/utils/http';
|
||||||
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
|
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
|
||||||
import { Button, Form, Input, Modal, Select, Space, message } from 'antd';
|
import { Button, Form, Input, Modal, Select, Space, message } from 'antd';
|
||||||
import { CronExpressionParser } from 'cron-parser';
|
import cronParser from 'cron-parser';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { getScheduleType, scheduleTypeMap } from './const';
|
import { getScheduleType, scheduleTypeMap } from './const';
|
||||||
|
|
@ -91,10 +91,14 @@ const CronModal = ({
|
||||||
{ required: true },
|
{ required: true },
|
||||||
{
|
{
|
||||||
validator: (_, value) => {
|
validator: (_, value) => {
|
||||||
if (!value || CronExpressionParser.parse(value).hasNext()) {
|
try {
|
||||||
return Promise.resolve();
|
if (!value || cronParser.CronExpressionParser.parse(value).hasNext()) {
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
return Promise.reject(intl.get('Cron表达式格式有误'));
|
||||||
|
} catch (e) {
|
||||||
|
return Promise.reject(intl.get('Cron表达式格式有误'));
|
||||||
}
|
}
|
||||||
return Promise.reject(intl.get('Cron表达式格式有误'));
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import {
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
import { request } from '@/utils/http';
|
import { request } from '@/utils/http';
|
||||||
import config from '@/utils/config';
|
import config from '@/utils/config';
|
||||||
import { CronExpressionParser } from 'cron-parser';
|
import cronParser from 'cron-parser';
|
||||||
import isNil from 'lodash/isNil';
|
import isNil from 'lodash/isNil';
|
||||||
|
|
||||||
const { Option } = Select;
|
const { Option } = Select;
|
||||||
|
|
@ -378,13 +378,17 @@ const SubscriptionModal = ({
|
||||||
{ required: true },
|
{ required: true },
|
||||||
{
|
{
|
||||||
validator: (rule, value) => {
|
validator: (rule, value) => {
|
||||||
if (
|
try {
|
||||||
scheduleType === 'interval' ||
|
if (
|
||||||
!value ||
|
scheduleType === 'interval' ||
|
||||||
CronExpressionParser.parse(value).hasNext()
|
!value ||
|
||||||
) {
|
cronParser.CronExpressionParser.parse(value).hasNext()
|
||||||
return Promise.resolve();
|
) {
|
||||||
} else {
|
return Promise.resolve();
|
||||||
|
} else {
|
||||||
|
return Promise.reject(intl.get('Subscription表达式格式有误'));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
return Promise.reject(intl.get('Subscription表达式格式有误'));
|
return Promise.reject(intl.get('Subscription表达式格式有误'));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { LANG_MAP, LOG_END_SYMBOL } from './const';
|
import { LANG_MAP, LOG_END_SYMBOL } from './const';
|
||||||
import { CronExpressionParser } from 'cron-parser';
|
import cronParser from 'cron-parser';
|
||||||
import { ICrontab } from '@/pages/crontab/type';
|
import { ICrontab } from '@/pages/crontab/type';
|
||||||
|
|
||||||
export default function browserType() {
|
export default function browserType() {
|
||||||
|
|
@ -333,7 +333,7 @@ export function getCommandScript(
|
||||||
|
|
||||||
export function parseCrontab(schedule: string): Date | null {
|
export function parseCrontab(schedule: string): Date | null {
|
||||||
try {
|
try {
|
||||||
const time = CronExpressionParser.parse(schedule);
|
const time = cronParser.CronExpressionParser.parse(schedule);
|
||||||
if (time) {
|
if (time) {
|
||||||
return time.next().toDate();
|
return time.next().toDate();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user