diff --git a/back/config/subscription.ts b/back/config/subscription.ts index a9d24572..ffd71b2f 100644 --- a/back/config/subscription.ts +++ b/back/config/subscription.ts @@ -1,4 +1,5 @@ import { Subscription } from '../data/subscription'; +import isNil from 'lodash/isNil'; export function formatUrl(doc: Subscription) { let url = doc.url; @@ -33,11 +34,9 @@ export function formatCommand(doc: Subscription, url?: string) { if (type === 'file') { command += `raw "${_url}"`; } else { - command += `repo "${_url}" "${whitelist || ''}" "${blacklist || ''}" "${ - dependences || '' - }" "${branch || ''}" "${extensions || ''}" "${proxy || ''}" "${ - Boolean(autoAddCron) ?? '' - }" "${Boolean(autoDelCron) ?? ''}"`; + command += `repo "${_url}" "${whitelist || ''}" "${blacklist || ''}" "${dependences || '' + }" "${branch || ''}" "${extensions || ''}" "${proxy || ''}" "${isNil(autoAddCron) ? true : Boolean(autoAddCron) + }" "${isNil(autoDelCron) ? true : Boolean(autoDelCron)}"`; } return command; } diff --git a/back/services/subscription.ts b/back/services/subscription.ts index 091fb403..e72a718a 100644 --- a/back/services/subscription.ts +++ b/back/services/subscription.ts @@ -68,7 +68,7 @@ export default class SubscriptionService { ['createdAt', 'DESC'], ], }); - return result as any; + return result; } catch (error) { throw error; } diff --git a/src/pages/subscription/modal.tsx b/src/pages/subscription/modal.tsx index 2750a272..57e43632 100644 --- a/src/pages/subscription/modal.tsx +++ b/src/pages/subscription/modal.tsx @@ -12,6 +12,7 @@ import { import { request } from '@/utils/http'; import config from '@/utils/config'; import cron_parser from 'cron-parser'; +import isNil from 'lodash/isNil'; const { Option } = Select; const repoUrlRegx = /[^\/\:]+\/[^\/]+(?=\.git)/; @@ -243,6 +244,14 @@ const SubscriptionModal = ({ } }, []); + const formatParams = (sub) => { + return { + ...sub, + autoAddCron: isNil(sub.autoAddCron) ? true : Boolean(sub.autoAddCron), + autoDelCron: isNil(sub.autoDelCron) ? true : Boolean(sub.autoDelCron), + }; + }; + useEffect(() => { if (visible) { window.addEventListener('paste', onPaste); @@ -252,7 +261,9 @@ const SubscriptionModal = ({ }, [visible]); useEffect(() => { - form.setFieldsValue(subscription || {}); + form.setFieldsValue( + { ...subscription, ...formatParams(subscription) } || {}, + ); setType((subscription && subscription.type) || 'public-repo'); setScheduleType((subscription && subscription.schedule_type) || 'crontab'); setPullType((subscription && subscription.pull_type) || 'ssh-key');