mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-10-22 13:55:01 +03:00
14de0557f9
* feat(clients): bulk-set XTLS flow from the Adjust dialog Add a "Set flow" dropdown to the bulk Adjust dialog so an admin can set or clear the XTLS flow on all selected clients at once, alongside the existing days/traffic bumps. Empty by default (no effect on save); "Disable" clears flow, and the two vision values mirror the per-client credential tab. Flow rides the existing inbound-JSON -> SyncInbound path (ClientRecord.Flow + client_inbounds.flow_override), so no new endpoint, DB column, or migration. Setting a vision flow is gated by inboundCanEnableTlsFlow: ineligible inbounds are left untouched and reported as skipped; clearing is always allowed. A real flow change requests an xray restart (local) or a node reconcile (remote). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(clients): keep days/traffic write when bulk flow is ineligible Address review on the bulk-flow-adjust PR: - Blocking: a client adjusted with both a days/traffic delta and a flow directive on a flow-ineligible inbound had the flow-ineligibility recorded into the same skip set that gates the ClientTraffic write, so the inbound JSON / ClientRecord advanced but ClientTraffic did not — divergent stores, and the client misreported as skipped. Track flow ineligibility in its own map (bulkInboundAdjustResult.flowIneligible) so it only feeds the final Skipped report and never suppresses the expiry/total persistence. - Drop the broad delete(skippedReasons, email): flow reasons no longer enter skippedReasons, so honoring a flow can no longer erase an unrelated skip reason (unlimited expiry, a real persistence error on another inbound). - Drop the inline comment block from ClientBulkAdjustModal.tsx (file had none); move the whitelist-sync note next to bulkFlowAllowed, the source of truth. - Document the optional flow field in the bulkAdjust API-docs example (endpoints.ts) and regenerate openapi.json. - Add a regression test covering days+flow on an ineligible inbound. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
121 lines
3.9 KiB
TypeScript
121 lines
3.9 KiB
TypeScript
import { useEffect, useState } from 'react';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { Alert, Form, InputNumber, Modal, Select, message } from 'antd';
|
|
|
|
import { ClientBulkAdjustFormSchema } from '@/schemas/client';
|
|
import { TLS_FLOW_CONTROL } from '@/schemas/primitives/flow';
|
|
|
|
const GB = 1024 * 1024 * 1024;
|
|
|
|
const FLOW_CLEAR = 'none';
|
|
|
|
interface ClientBulkAdjustModalProps {
|
|
open: boolean;
|
|
count: number;
|
|
onOpenChange: (open: boolean) => void;
|
|
onSubmit: (addDays: number, addBytes: number, flow: string) => Promise<{ adjusted: number; skipped?: { email: string; reason: string }[] } | null>;
|
|
}
|
|
|
|
export default function ClientBulkAdjustModal({ open, count, onOpenChange, onSubmit }: ClientBulkAdjustModalProps) {
|
|
const { t } = useTranslation();
|
|
const [messageApi, messageContextHolder] = message.useMessage();
|
|
const [addDays, setAddDays] = useState<number>(0);
|
|
const [addGB, setAddGB] = useState<number>(0);
|
|
const [flow, setFlow] = useState<string>('');
|
|
const [submitting, setSubmitting] = useState(false);
|
|
|
|
useEffect(() => {
|
|
if (open) {
|
|
setAddDays(0);
|
|
setAddGB(0);
|
|
setFlow('');
|
|
}
|
|
}, [open]);
|
|
|
|
async function handleOk() {
|
|
const validated = ClientBulkAdjustFormSchema.safeParse({
|
|
addDays: Math.trunc(Number(addDays) || 0),
|
|
addGB: Number(addGB) || 0,
|
|
flow,
|
|
});
|
|
if (!validated.success) {
|
|
messageApi.warning(t(validated.error.issues[0]?.message ?? 'somethingWentWrong'));
|
|
return;
|
|
}
|
|
const { addDays: days, addGB: gb, flow: flowValue } = validated.data;
|
|
setSubmitting(true);
|
|
try {
|
|
const bytes = Math.trunc(gb * GB);
|
|
const result = await onSubmit(days, bytes, flowValue);
|
|
if (!result) return;
|
|
const ok = result.adjusted ?? 0;
|
|
const skipped = result.skipped?.length ?? 0;
|
|
if (skipped === 0) {
|
|
messageApi.success(t('pages.clients.toasts.bulkAdjusted', { count: ok }));
|
|
} else {
|
|
const firstReason = result.skipped?.[0]?.reason ?? '';
|
|
messageApi.warning(firstReason
|
|
? `${t('pages.clients.toasts.bulkAdjustedMixed', { ok, skipped })} — ${firstReason}`
|
|
: t('pages.clients.toasts.bulkAdjustedMixed', { ok, skipped }));
|
|
}
|
|
onOpenChange(false);
|
|
} finally {
|
|
setSubmitting(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<>
|
|
{messageContextHolder}
|
|
<Modal
|
|
open={open}
|
|
title={t('pages.clients.bulkAdjustTitle', { count })}
|
|
okText={t('apply')}
|
|
cancelText={t('cancel')}
|
|
confirmLoading={submitting}
|
|
onOk={handleOk}
|
|
onCancel={() => onOpenChange(false)}
|
|
destroyOnHidden
|
|
>
|
|
<Alert
|
|
type="info"
|
|
showIcon
|
|
style={{ marginBottom: 16 }}
|
|
title={t('pages.clients.bulkAdjustHint')}
|
|
/>
|
|
<Form layout="vertical">
|
|
<Form.Item label={t('pages.clients.addDays')}>
|
|
<InputNumber
|
|
value={addDays}
|
|
onChange={(v) => setAddDays(Number(v) || 0)}
|
|
style={{ width: '100%' }}
|
|
step={1}
|
|
precision={0}
|
|
/>
|
|
</Form.Item>
|
|
<Form.Item label={t('pages.clients.addTrafficGB')}>
|
|
<InputNumber
|
|
value={addGB}
|
|
onChange={(v) => setAddGB(Number(v) || 0)}
|
|
style={{ width: '100%' }}
|
|
step={1}
|
|
/>
|
|
</Form.Item>
|
|
<Form.Item label={t('pages.clients.bulkFlow')}>
|
|
<Select
|
|
value={flow}
|
|
onChange={setFlow}
|
|
style={{ width: '100%' }}
|
|
options={[
|
|
{ value: '', label: t('pages.clients.bulkFlowNoChange') },
|
|
{ value: FLOW_CLEAR, label: t('pages.clients.bulkFlowDisable') },
|
|
...Object.values(TLS_FLOW_CONTROL).map((k) => ({ value: k, label: k })),
|
|
]}
|
|
/>
|
|
</Form.Item>
|
|
</Form>
|
|
</Modal>
|
|
</>
|
|
);
|
|
}
|