From 622fe2a8f8060e41b3133161989a527374aef464 Mon Sep 17 00:00:00 2001 From: whyour Date: Tue, 14 Feb 2023 11:07:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AE=A2=E9=98=85=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=A2=9E=E5=8A=A0/=E5=88=A0=E9=99=A4=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E9=BB=98=E8=AE=A4=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/config/subscription.ts | 9 ++++----- back/services/subscription.ts | 2 +- src/pages/subscription/modal.tsx | 13 ++++++++++++- 3 files changed, 17 insertions(+), 7 deletions(-) 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');