Files
mirror-3x-ui/frontend/src/schemas/subBalancer.ts
T
amirim e071f220e9 feat(sub): report why a subscription balancer emits nothing (#7209)
A subscription balancer whose inbounds were deleted, disabled, changed to a protocol with no JSON outbound, left without clients or closed by their hosts simply vanished from the JSON subscription, and nothing in the panel or the log said why.

GET /panel/api/sub-balancers now returns a problems[] array per balancer with stable codes: unknown_inbound, disabled_inbound, json_incapable_protocol, inbound_without_clients, hosts_excluded_from_json and no_members. Settings -> Sub Balancers shows a warning tag whose tooltip names each cause and the affected inbounds, and the log records a balancer's problems when they change instead of on every listing.

The advisories are read from the stored rows and never change what a subscription emits: a balancer with no usable member is still omitted. The list of JSON-incapable protocols is pinned to the renderer, the subscription allowlist and the form by tests.
2026-11-28 09:53:14 +03:30

66 lines
2.3 KiB
TypeScript

import { z } from 'zod';
export const SubBalancerStrategySchema = z.enum(['leastLoad', 'leastPing', 'random', 'roundRobin']);
export type SubBalancerStrategy = z.infer<typeof SubBalancerStrategySchema>;
export const SubBalancerProblemCodeSchema = z.enum([
'unknown_inbound',
'disabled_inbound',
'json_incapable_protocol',
'inbound_without_clients',
'hosts_excluded_from_json',
'no_members',
]);
export type SubBalancerProblemCode = z.infer<typeof SubBalancerProblemCodeSchema>;
export const SubBalancerProblemSchema = z.object({
code: SubBalancerProblemCodeSchema,
inboundIds: z.array(z.number()).optional(),
detail: z.string().optional(),
});
export type SubBalancerProblem = z.infer<typeof SubBalancerProblemSchema>;
export const SubBalancerSchema = z.object({
id: z.number(),
remark: z.string(),
strategy: SubBalancerStrategySchema,
inboundIds: z.array(z.number()),
memberWeights: z.record(z.string(), z.number()).nullish(),
sortOrder: z.number(),
enabled: z.boolean(),
// Advisories from the list API; create/update responses omit them.
problems: z.array(SubBalancerProblemSchema).optional(),
createdAt: z.number().optional(),
updatedAt: z.number().optional(),
});
export type SubBalancer = z.infer<typeof SubBalancerSchema>;
export const SubBalancerListSchema = z.array(SubBalancerSchema);
export const SubBalancerFormSchema = z.object({
remark: z
.string()
.trim()
.min(1, 'pages.settings.subBalancers.errRemarkRequired')
.max(256, 'pages.settings.subBalancers.errRemarkRequired'),
strategy: SubBalancerStrategySchema,
inboundIds: z
.array(z.number().int().positive())
.min(1, 'pages.settings.subBalancers.errInboundsRequired'),
// inboundId (stringified) -> leastLoad weight; absent members weigh 1.0.
memberWeights: z
.record(
z.string(),
z
.number({ error: 'pages.settings.subBalancers.errWeightPositive' })
.positive('pages.settings.subBalancers.errWeightPositive'),
)
.optional(),
sortOrder: z
.number({ error: 'pages.settings.subBalancers.errSortOrder' })
.int('pages.settings.subBalancers.errSortOrder')
.min(1, 'pages.settings.subBalancers.errSortOrder'),
enabled: z.boolean(),
});
export type SubBalancerFormValues = z.infer<typeof SubBalancerFormSchema>;