mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-11-16 14:54:23 +08:00
feat(cloudflare): 支持分组级自动与手动 TTL 配置 (#62)
This commit is contained in:
@@ -12,7 +12,13 @@ import {
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Field, FieldGroup, FieldLabel } from '@/components/ui/field';
|
||||
import {
|
||||
Field,
|
||||
FieldDescription,
|
||||
FieldError,
|
||||
FieldGroup,
|
||||
FieldLabel,
|
||||
} from '@/components/ui/field';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import {
|
||||
Select,
|
||||
@@ -64,6 +70,12 @@ export function GroupDialog({
|
||||
const [backupNodeID, setBackupNodeID] = useState('none');
|
||||
const [defaultProxied, setDefaultProxied] = useState(true);
|
||||
const [enabled, setEnabled] = useState(true);
|
||||
const [ttlMode, setTtlMode] = useState<'auto' | 'manual'>('auto');
|
||||
const [manualTTL, setManualTTL] = useState('300');
|
||||
const ttl = ttlMode === 'auto' ? 1 : Number(manualTTL);
|
||||
const invalidTTL =
|
||||
ttlMode === 'manual' &&
|
||||
(!manualTTL.trim() || !Number.isInteger(ttl) || ttl < 60 || ttl > 86400);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
@@ -83,6 +95,9 @@ export function GroupDialog({
|
||||
);
|
||||
setDefaultProxied(group?.default_proxied ?? true);
|
||||
setEnabled(group?.enabled ?? true);
|
||||
const groupTTL = group ? (group.ttl ?? 300) : 1;
|
||||
setTtlMode(groupTTL === 1 ? 'auto' : 'manual');
|
||||
setManualTTL(String(groupTTL === 1 ? 300 : groupTTL));
|
||||
}, [group, open]);
|
||||
|
||||
return (
|
||||
@@ -209,6 +224,54 @@ export function GroupDialog({
|
||||
</Field>
|
||||
</>
|
||||
)}
|
||||
<Field>
|
||||
<FieldLabel id='cf-ttl-mode-label'>{t('ttl')}</FieldLabel>
|
||||
<ToggleGroup
|
||||
type='single'
|
||||
variant='outline'
|
||||
value={ttlMode}
|
||||
aria-labelledby='cf-ttl-mode-label'
|
||||
aria-describedby='cf-ttl-hint'
|
||||
className='grid w-full grid-cols-2'
|
||||
onValueChange={(value) => {
|
||||
if (value === 'auto' || value === 'manual') {
|
||||
setTtlMode(value);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<ToggleGroupItem value='auto' className='w-full'>
|
||||
{t('ttlAuto')}
|
||||
</ToggleGroupItem>
|
||||
<ToggleGroupItem value='manual' className='w-full'>
|
||||
{t('ttlManual')}
|
||||
</ToggleGroupItem>
|
||||
</ToggleGroup>
|
||||
<FieldDescription id='cf-ttl-hint'>{t('ttlHint')}</FieldDescription>
|
||||
</Field>
|
||||
{ttlMode === 'manual' && (
|
||||
<Field data-invalid={invalidTTL}>
|
||||
<FieldLabel htmlFor='cf-ttl-seconds'>
|
||||
{t('ttlSeconds')}
|
||||
</FieldLabel>
|
||||
<Input
|
||||
id='cf-ttl-seconds'
|
||||
type='number'
|
||||
min={60}
|
||||
max={86400}
|
||||
step={1}
|
||||
required
|
||||
value={manualTTL}
|
||||
aria-invalid={invalidTTL}
|
||||
aria-describedby={
|
||||
invalidTTL ? 'cf-ttl-hint cf-ttl-error' : 'cf-ttl-hint'
|
||||
}
|
||||
onChange={(event) => setManualTTL(event.target.value)}
|
||||
/>
|
||||
{invalidTTL && (
|
||||
<FieldError id='cf-ttl-error'>{t('ttlError')}</FieldError>
|
||||
)}
|
||||
</Field>
|
||||
)}
|
||||
<Field orientation='horizontal'>
|
||||
<FieldLabel htmlFor='cf-default-proxied'>
|
||||
{t('defaultProxied')}
|
||||
@@ -235,10 +298,12 @@ export function GroupDialog({
|
||||
<Button
|
||||
disabled={
|
||||
pending ||
|
||||
invalidTTL ||
|
||||
!name.trim() ||
|
||||
(targetMode === 'node' ? !primaryNodeID : !recordContent.trim())
|
||||
}
|
||||
onClick={() =>
|
||||
onClick={() => {
|
||||
if (invalidTTL) return;
|
||||
onSubmit({
|
||||
name: name.trim(),
|
||||
target_mode: targetMode,
|
||||
@@ -251,9 +316,10 @@ export function GroupDialog({
|
||||
? Number(backupNodeID)
|
||||
: null,
|
||||
default_proxied: defaultProxied,
|
||||
ttl,
|
||||
enabled,
|
||||
})
|
||||
}
|
||||
});
|
||||
}}
|
||||
>
|
||||
{t('save')}
|
||||
</Button>
|
||||
|
||||
@@ -371,6 +371,11 @@ export function CloudflareGroupDetailPageClient() {
|
||||
: 'nodeTargetMode',
|
||||
)}
|
||||
</Badge>
|
||||
<Badge variant='outline'>
|
||||
{group.ttl === 1
|
||||
? t('ttlAutoSummary')
|
||||
: t('ttlSecondsSummary', { seconds: group.ttl ?? 300 })}
|
||||
</Badge>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user