mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-10-18 11:55:02 +03:00
93eda06878
Persistent client groups
- New ClientGroup model + client_groups table that holds empty
(placeholder) groups so a user can define a label before any client
references it. ListGroups merges these with the distinct group_name
values already stored on clients and reports {name, clientCount}.
- ClientRecord gains group_name column; the model.Client wire shape
gains a matching `group` JSON field that survives the
inbound.settings → SyncInbound round-trip.
- Rename/Delete on a group mutates client_groups (rename row / delete
row) AND propagates to all matching clients in ClientRecord and in
every owning inbound's settings JSON, all in one transaction.
Bulk operations
- AssignGroup(emails, group) updates clients.group_name + patches each
affected inbound's settings JSON in one read-modify-write per inbound.
Empty group clears the label. Auto-creates the client_groups row when
the user assigns to a brand-new name.
- BulkResetTraffic(emails) loops the existing single-reset path so the
caller can zero traffic across a whole selection or a whole group.
- EmailsByGroup(name) returns just the email list (used by the groups
page to fan a single bulk action over every member).
Endpoints (all under /panel/api/clients)
- GET /groups — summaries with counts
- GET /groups/:name/emails — emails in a group
- POST /groups/create — empty placeholder group
- POST /groups/rename — rename (table + clients + JSON)
- POST /groups/delete — drop label everywhere (clients survive)
- POST /bulkAssignGroup — assign N selected clients
- POST /bulkResetTraffic — reset traffic on a list
Clients page UX
- New Group column (Actions → Client → Group → Inbounds → …) with a
click-to-filter chip.
- FilterDrawer gains a multi-select Group filter whose options come
from the new ClientPageResponse.groups field (sourced from ListGroups
so empty/placeholder groups are pickable too).
- Single-client and bulk-add forms gain a Group AutoComplete pre-loaded
with all known group names.
- New toolbar buttons when selection > 0: "Group ({n})" opens
BulkAssignGroupModal, "Sub links ({n})" opens SubLinksModal.
Sub-links export modal (new SubLinksModal.tsx)
- Table of selected clients with their subscription URL (and JSON URL
when subJsonEnable is on), per-row copy, Copy all, and Download as
sub-links-<timestamp>.txt. Warns when subscription is disabled or
none of the selected clients have a subId.
Dedicated Groups page (new pages/groups/GroupsPage.tsx)
- /groups route + sidebar entry (TagsOutlined icon) + page title key.
- Card-based layout matching Clients/Inbounds/Nodes — summary card with
Total/Grouped/Empty stats, main card with Add Group button + table.
- Per-row More dropdown (icon-first column on the left): Sub links,
Adjust (days+traffic), Reset traffic, Rename, Delete clients in
group, Delete group (keep clients). Empty groups disable the
client-targeted actions.
- Reuses SubLinksModal and ClientBulkAdjustModal — emails for the
group are fetched on demand from GET /groups/:name/emails.
Other polish
- /groups + groups-page selectors added to page-shell.css and
page-cards.css so the new page inherits the same background, padding,
card borders, hover shadow, and summary-card padding.
- .card-toolbar gains a small vertical padding so the larger toolbar
buttons (now default size, matching Inbounds) don't crowd the top of
the card-head on Clients and Groups pages.
173 lines
5.4 KiB
TypeScript
173 lines
5.4 KiB
TypeScript
import { z } from 'zod';
|
|
|
|
const nullableStringArray = z.array(z.string()).nullable().transform((v) => v ?? []);
|
|
const nullableNumberArray = z.array(z.number()).nullable().transform((v) => v ?? []);
|
|
|
|
export const ClientTrafficSchema = z.object({
|
|
up: z.number().optional(),
|
|
down: z.number().optional(),
|
|
total: z.number().optional(),
|
|
expiryTime: z.number().optional(),
|
|
enable: z.boolean().optional(),
|
|
lastOnline: z.number().optional(),
|
|
});
|
|
|
|
export const ClientRecordSchema = z.object({
|
|
id: z.number().optional(),
|
|
email: z.string(),
|
|
subId: z.string().optional(),
|
|
uuid: z.string().optional(),
|
|
password: z.string().optional(),
|
|
auth: z.string().optional(),
|
|
flow: z.string().optional(),
|
|
security: z.string().optional(),
|
|
totalGB: z.number().optional(),
|
|
expiryTime: z.number().optional(),
|
|
limitIp: z.number().optional(),
|
|
tgId: z.union([z.number(), z.string()]).optional(),
|
|
group: z.string().optional(),
|
|
comment: z.string().optional(),
|
|
enable: z.boolean().optional(),
|
|
reset: z.number().optional(),
|
|
inboundIds: nullableNumberArray.optional(),
|
|
traffic: ClientTrafficSchema.nullable().optional(),
|
|
reverse: z.object({ tag: z.string().optional() }).loose().nullable().optional(),
|
|
createdAt: z.number().optional(),
|
|
updatedAt: z.number().optional(),
|
|
}).loose();
|
|
|
|
export const InboundOptionSchema = z.object({
|
|
id: z.number(),
|
|
remark: z.string().optional(),
|
|
protocol: z.string().optional(),
|
|
port: z.number().optional(),
|
|
tlsFlowCapable: z.boolean().optional(),
|
|
}).loose();
|
|
|
|
export const InboundOptionsSchema = z.array(InboundOptionSchema);
|
|
|
|
export const ClientsSummarySchema = z.object({
|
|
total: z.number(),
|
|
active: z.number(),
|
|
online: nullableStringArray,
|
|
depleted: nullableStringArray,
|
|
expiring: nullableStringArray,
|
|
deactive: nullableStringArray,
|
|
});
|
|
|
|
const nullableClientArray = z.array(ClientRecordSchema).nullable().transform((v) => v ?? []);
|
|
|
|
export const ClientPageResponseSchema = z.object({
|
|
items: nullableClientArray,
|
|
total: z.number(),
|
|
filtered: z.number(),
|
|
page: z.number(),
|
|
pageSize: z.number(),
|
|
summary: ClientsSummarySchema.nullable().optional(),
|
|
groups: nullableStringArray.optional(),
|
|
});
|
|
|
|
export const ClientHydrateSchema = z.object({
|
|
client: ClientRecordSchema,
|
|
inboundIds: nullableNumberArray,
|
|
});
|
|
|
|
export const BulkAdjustResultSchema = z.object({
|
|
adjusted: z.number(),
|
|
skipped: z
|
|
.array(z.object({ email: z.string(), reason: z.string() }))
|
|
.optional(),
|
|
});
|
|
|
|
export const BulkDeleteResultSchema = z.object({
|
|
deleted: z.number(),
|
|
skipped: z
|
|
.array(z.object({ email: z.string(), reason: z.string() }))
|
|
.optional(),
|
|
});
|
|
|
|
export const BulkCreateResultSchema = z.object({
|
|
created: z.number(),
|
|
skipped: z
|
|
.array(z.object({ email: z.string(), reason: z.string() }))
|
|
.optional(),
|
|
});
|
|
|
|
export const DelDepletedResultSchema = z.object({
|
|
deleted: z.number().optional(),
|
|
});
|
|
|
|
export const OnlinesSchema = nullableStringArray;
|
|
|
|
export const GroupSummarySchema = z.object({
|
|
name: z.string(),
|
|
clientCount: z.number(),
|
|
});
|
|
|
|
export const GroupSummaryListSchema = z.array(GroupSummarySchema).nullable().transform((v) => v ?? []);
|
|
|
|
export const ClientFormSchema = z.object({
|
|
email: z.string().trim().min(1, 'pages.clients.email'),
|
|
subId: z.string(),
|
|
uuid: z.string(),
|
|
password: z.string(),
|
|
auth: z.string(),
|
|
flow: z.string(),
|
|
reverseTag: z.string(),
|
|
totalGB: z.number().min(0),
|
|
delayedStart: z.boolean(),
|
|
delayedDays: z.number().int().min(0),
|
|
reset: z.number().int().min(0),
|
|
limitIp: z.number().int().min(0),
|
|
tgId: z.number().int().min(0),
|
|
group: z.string(),
|
|
comment: z.string(),
|
|
enable: z.boolean(),
|
|
inboundIds: z.array(z.number()),
|
|
});
|
|
|
|
export const ClientCreateFormSchema = ClientFormSchema.extend({
|
|
inboundIds: z.array(z.number()).min(1, 'pages.clients.selectInbound'),
|
|
});
|
|
|
|
export const ClientBulkAdjustFormSchema = z
|
|
.object({
|
|
addDays: z.number().int(),
|
|
addGB: z.number(),
|
|
})
|
|
.refine((v) => v.addDays !== 0 || v.addGB !== 0, {
|
|
message: 'pages.clients.bulkAdjustNothing',
|
|
});
|
|
|
|
export const ClientBulkAddFormSchema = z.object({
|
|
emailMethod: z.number().int().min(0).max(4),
|
|
firstNum: z.number().int().min(1),
|
|
lastNum: z.number().int().min(1),
|
|
emailPrefix: z.string(),
|
|
emailPostfix: z.string(),
|
|
quantity: z.number().int().min(1).max(100),
|
|
subId: z.string(),
|
|
group: z.string(),
|
|
comment: z.string(),
|
|
flow: z.string(),
|
|
limitIp: z.number().int().min(0),
|
|
totalGB: z.number().min(0),
|
|
expiryTime: z.number(),
|
|
reset: z.number().int().min(0),
|
|
inboundIds: z.array(z.number()).min(1, 'pages.clients.selectInbound'),
|
|
});
|
|
|
|
export type ClientRecord = z.infer<typeof ClientRecordSchema>;
|
|
export type ClientTraffic = z.infer<typeof ClientTrafficSchema>;
|
|
export type InboundOption = z.infer<typeof InboundOptionSchema>;
|
|
export type ClientsSummary = z.infer<typeof ClientsSummarySchema>;
|
|
export type ClientPageResponse = z.infer<typeof ClientPageResponseSchema>;
|
|
export type ClientHydrate = z.infer<typeof ClientHydrateSchema>;
|
|
export type BulkAdjustResult = z.infer<typeof BulkAdjustResultSchema>;
|
|
export type BulkDeleteResult = z.infer<typeof BulkDeleteResultSchema>;
|
|
export type BulkCreateResult = z.infer<typeof BulkCreateResultSchema>;
|
|
export type ClientBulkAddFormValues = z.infer<typeof ClientBulkAddFormSchema>;
|
|
export type ClientBulkAdjustFormValues = z.infer<typeof ClientBulkAdjustFormSchema>;
|
|
export type ClientFormValues = z.infer<typeof ClientFormSchema>;
|
|
export type GroupSummary = z.infer<typeof GroupSummarySchema>;
|