mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-05-26 07:08:01 +00:00
Bulk extend client expiry / traffic + clients page polish (#4499)
* chore(sub): drop unused getFallbackMaster projectThroughFallbackMaster fully supersedes it for both panel-tracked and legacy unix-socket fallbacks. * feat(clients): bulk extend expiry / traffic for selected clients Adds POST /panel/api/clients/bulkAdjust which shifts ExpiryTime by addDays and TotalGB by addBytes for every email in one request. The endpoint is wired into the clients page through a new ClientBulkAdjustModal that opens from the existing multi-select toolbar. Clients with unlimited expiry (expiryTime=0) or unlimited traffic (totalGB=0) are skipped for the corresponding field so bulk extend never accidentally converts an unlimited client to a limited one. Negative values are allowed for refunds / corrections. Translations added for all 13 locales. * fix(db): silence GORM record-not-found spam in debug mode getSetting handles ErrRecordNotFound via database.IsNotFound and falls back to defaults, but GORM's Default logger still logs each miss as an error. With periodic jobs reading unset keys (xrayTemplateConfig, externalTrafficInformEnable) the panel log flooded thousands of times. Switch to a logger.New with IgnoreRecordNotFoundError=true so legitimate slow-query and SQL traces still surface in debug mode. * fix(clients): include inboundsById in columns memo deps Without it, the table's first paint captured an empty inboundsById and rendered each attached inbound as #<id>. Once a sort/filter forced the memo to rebuild it self-corrected, hence the visible flicker on reload. * fix(clients): handle delayed-start expiry in bulk adjust Negative ExpiryTime encodes a delay duration (magnitude = ms until the trial begins on first use). Adding positive addDays was simply arithmetically added, so e.g. a -7d delay + 30d turned into +23d since epoch (1970), making the client instantly expired. Branch on sign now: positive ExpiryTime extends additively, negative extends by subtracting so the value stays negative (more delay). Cross-sign reductions are skipped with an explicit reason instead of silently corrupting the field. * fix(clients): step traffic input by 1 GB instead of 0.1 The +/- buttons on the Total Sent/Received field nudged in 0.1 GB increments which is too granular for typical use. Set step=1 so each press moves a whole GB; users can still type decimal values directly. * fix(inbounds): step Total Flow input by 1 GB instead of 0.1 Matches the same nudge fix applied to the client form's Total Sent/Received field.
This commit is contained in:
@@ -146,6 +146,17 @@ export function useClients() {
|
||||
return results;
|
||||
}, [refresh]);
|
||||
|
||||
const bulkAdjust = useCallback(async (emails: string[], addDays: number, addBytes: number) => {
|
||||
if (!Array.isArray(emails) || emails.length === 0) return null;
|
||||
const msg = await HttpUtil.post(
|
||||
'/panel/api/clients/bulkAdjust',
|
||||
{ emails, addDays, addBytes },
|
||||
JSON_HEADERS,
|
||||
) as ApiMsg<{ adjusted: number; skipped?: { email: string; reason: string }[] }>;
|
||||
if (msg?.success) await refresh();
|
||||
return msg;
|
||||
}, [refresh]);
|
||||
|
||||
const attach = useCallback(async (email: string, inboundIds: number[]) => {
|
||||
if (!email) return null;
|
||||
const encoded = encodeURIComponent(email);
|
||||
@@ -269,6 +280,7 @@ export function useClients() {
|
||||
update,
|
||||
remove,
|
||||
removeMany,
|
||||
bulkAdjust,
|
||||
attach,
|
||||
detach,
|
||||
resetTraffic,
|
||||
|
||||
@@ -461,6 +461,13 @@ export const sections = [
|
||||
summary: 'Delete every client whose traffic quota is exhausted (used >= total, when reset is disabled) or whose expiry has passed. Returns the deleted count and triggers an Xray restart when any client was on a running inbound.',
|
||||
response: '{\n "success": true,\n "obj": {\n "deleted": 0\n }\n}',
|
||||
},
|
||||
{
|
||||
method: 'POST',
|
||||
path: '/panel/api/clients/bulkAdjust',
|
||||
summary: 'Shift expiry and/or traffic quota for many clients in one call. addDays/addBytes may be negative. Clients with unlimited expiry (expiryTime=0) or unlimited traffic (totalGB=0) are skipped for the corresponding field — bulk extend never converts unlimited to limited. Returns the adjusted count and per-email skip reasons.',
|
||||
body: '{\n "emails": ["alice", "bob"],\n "addDays": 30,\n "addBytes": 53687091200\n}',
|
||||
response: '{\n "success": true,\n "obj": {\n "adjusted": 2,\n "skipped": [\n { "email": "carol", "reason": "unlimited expiry" }\n ]\n }\n}',
|
||||
},
|
||||
{
|
||||
method: 'POST',
|
||||
path: '/panel/api/clients/resetTraffic/:email',
|
||||
|
||||
@@ -308,7 +308,7 @@ export default function ClientBulkAddModal({
|
||||
)}
|
||||
|
||||
<Form.Item label={t('pages.clients.totalGB')}>
|
||||
<InputNumber value={form.totalGB} min={0} step={0.1} onChange={(v) => update('totalGB', Number(v) || 0)} />
|
||||
<InputNumber value={form.totalGB} min={0} step={1} onChange={(v) => update('totalGB', Number(v) || 0)} />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label={t('pages.clients.delayedStart')}>
|
||||
|
||||
97
frontend/src/pages/clients/ClientBulkAdjustModal.tsx
Normal file
97
frontend/src/pages/clients/ClientBulkAdjustModal.tsx
Normal file
@@ -0,0 +1,97 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Alert, Form, InputNumber, Modal, message } from 'antd';
|
||||
|
||||
const GB = 1024 * 1024 * 1024;
|
||||
|
||||
interface ClientBulkAdjustModalProps {
|
||||
open: boolean;
|
||||
count: number;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
onSubmit: (addDays: number, addBytes: number) => 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 [submitting, setSubmitting] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
setAddDays(0);
|
||||
setAddGB(0);
|
||||
}
|
||||
}, [open]);
|
||||
|
||||
async function handleOk() {
|
||||
const days = Math.trunc(Number(addDays) || 0);
|
||||
const gb = Number(addGB) || 0;
|
||||
if (days === 0 && gb === 0) {
|
||||
messageApi.warning(t('pages.clients.bulkAdjustNothing'));
|
||||
return;
|
||||
}
|
||||
setSubmitting(true);
|
||||
try {
|
||||
const bytes = Math.trunc(gb * GB);
|
||||
const result = await onSubmit(days, bytes);
|
||||
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 }}
|
||||
message={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>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -393,7 +393,7 @@ export default function ClientFormModal({
|
||||
</Col>
|
||||
<Col xs={24} md={ipLimitEnable ? 8 : 12}>
|
||||
<Form.Item label={t('pages.clients.totalGB')}>
|
||||
<InputNumber value={form.totalGB} min={0} step={0.1} style={{ width: '100%' }}
|
||||
<InputNumber value={form.totalGB} min={0} step={1} style={{ width: '100%' }}
|
||||
onChange={(v) => update('totalGB', Number(v) || 0)} />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
} from 'antd';
|
||||
import type { ColumnsType, TableProps } from 'antd/es/table';
|
||||
import {
|
||||
ClockCircleOutlined,
|
||||
DeleteOutlined,
|
||||
EditOutlined,
|
||||
FilterOutlined,
|
||||
@@ -54,6 +55,7 @@ import ClientFormModal from './ClientFormModal';
|
||||
import ClientInfoModal from './ClientInfoModal';
|
||||
import ClientQrModal from './ClientQrModal';
|
||||
import ClientBulkAddModal from './ClientBulkAddModal';
|
||||
import ClientBulkAdjustModal from './ClientBulkAdjustModal';
|
||||
import '@/styles/page-cards.css';
|
||||
import './ClientsPage.css';
|
||||
|
||||
@@ -96,7 +98,7 @@ export default function ClientsPage() {
|
||||
const {
|
||||
clients, inbounds, onlines, loading, fetched, subSettings,
|
||||
ipLimitEnable, tgBotEnable, expireDiff, trafficDiff, pageSize,
|
||||
create, update, remove, removeMany, attach, detach,
|
||||
create, update, remove, removeMany, bulkAdjust, attach, detach,
|
||||
resetTraffic, resetAllTraffics, delDepleted, setEnable,
|
||||
applyTrafficEvent, applyClientStatsEvent, applyInvalidate,
|
||||
} = useClients();
|
||||
@@ -117,6 +119,7 @@ export default function ClientsPage() {
|
||||
const [qrOpen, setQrOpen] = useState(false);
|
||||
const [qrClient, setQrClient] = useState<ClientRecord | null>(null);
|
||||
const [bulkAddOpen, setBulkAddOpen] = useState(false);
|
||||
const [bulkAdjustOpen, setBulkAdjustOpen] = useState(false);
|
||||
const [selectedRowKeys, setSelectedRowKeys] = useState<string[]>([]);
|
||||
|
||||
const initial = readFilterState();
|
||||
@@ -587,7 +590,7 @@ export default function ClientsPage() {
|
||||
}, 'expiryTime'),
|
||||
];
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [t, togglingEmail, sortColumn, sortOrder, clientBucket, isOnline]);
|
||||
}, [t, togglingEmail, sortColumn, sortOrder, clientBucket, isOnline, inboundsById]);
|
||||
|
||||
const tablePagination = {
|
||||
current: currentPage,
|
||||
@@ -700,9 +703,14 @@ export default function ClientsPage() {
|
||||
{!isMobile && t('pages.clients.bulk')}
|
||||
</Button>
|
||||
{selectedRowKeys.length > 0 && (
|
||||
<Button danger size="small" icon={<DeleteOutlined />} onClick={onBulkDelete}>
|
||||
{t('pages.clients.deleteSelected', { count: selectedRowKeys.length })}
|
||||
</Button>
|
||||
<>
|
||||
<Button size="small" icon={<ClockCircleOutlined />} onClick={() => setBulkAdjustOpen(true)}>
|
||||
{t('pages.clients.adjustSelected', { count: selectedRowKeys.length })}
|
||||
</Button>
|
||||
<Button danger size="small" icon={<DeleteOutlined />} onClick={onBulkDelete}>
|
||||
{t('pages.clients.deleteSelected', { count: selectedRowKeys.length })}
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
<Button size="small" icon={<RetweetOutlined />} onClick={onResetAllTraffics}>
|
||||
{!isMobile && t('pages.clients.resetAllTraffics')}
|
||||
@@ -902,6 +910,19 @@ export default function ClientsPage() {
|
||||
onOpenChange={setBulkAddOpen}
|
||||
onSaved={() => setBulkAddOpen(false)}
|
||||
/>
|
||||
<ClientBulkAdjustModal
|
||||
open={bulkAdjustOpen}
|
||||
count={selectedRowKeys.length}
|
||||
onOpenChange={setBulkAdjustOpen}
|
||||
onSubmit={async (addDays, addBytes) => {
|
||||
const msg = await bulkAdjust([...selectedRowKeys], addDays, addBytes);
|
||||
if (msg?.success) {
|
||||
setSelectedRowKeys([]);
|
||||
return msg.obj ?? { adjusted: 0 };
|
||||
}
|
||||
return null;
|
||||
}}
|
||||
/>
|
||||
</Layout>
|
||||
</ConfigProvider>
|
||||
);
|
||||
|
||||
@@ -966,7 +966,7 @@ export default function InboundFormModal({
|
||||
<InputNumber
|
||||
value={totalGB}
|
||||
min={0}
|
||||
step={0.1}
|
||||
step={1}
|
||||
onChange={(v) => {
|
||||
form.total = NumberFormatter.toFixed((Number(v) || 0) * SizeFormatter.ONE_GB, 0);
|
||||
refresh();
|
||||
|
||||
Reference in New Issue
Block a user