node.ts 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { z } from 'zod';
  2. export const NodeRecordSchema = z.object({
  3. id: z.number(),
  4. name: z.string().optional(),
  5. remark: z.string().optional(),
  6. scheme: z.string().optional(),
  7. address: z.string().optional(),
  8. port: z.number().optional(),
  9. basePath: z.string().optional(),
  10. apiToken: z.string().optional(),
  11. enable: z.boolean().optional(),
  12. status: z.string().optional(),
  13. latencyMs: z.number().optional(),
  14. cpuPct: z.number().optional(),
  15. memPct: z.number().optional(),
  16. xrayVersion: z.string().optional(),
  17. panelVersion: z.string().optional(),
  18. uptimeSecs: z.number().optional(),
  19. inboundCount: z.number().optional(),
  20. clientCount: z.number().optional(),
  21. onlineCount: z.number().optional(),
  22. depletedCount: z.number().optional(),
  23. lastHeartbeat: z.number().optional(),
  24. lastError: z.string().optional(),
  25. // Xray state captured from the remote node's own /panel/api/server/status.
  26. // Lets the nodes list show a distinct indicator when the panel API is reachable
  27. // (status=online) but the Xray core on that node has failed.
  28. xrayState: z.string().optional(),
  29. xrayError: z.string().optional(),
  30. allowPrivateAddress: z.boolean().optional(),
  31. tlsVerifyMode: z.enum(['verify', 'skip', 'pin']).optional(),
  32. pinnedCertSha256: z.string().optional(),
  33. inboundSyncMode: z.enum(['all', 'selected']).optional(),
  34. // Backend serializes a nil []string as null for nodes saved before #5178.
  35. inboundTags: z.array(z.string()).nullish(),
  36. // Multi-hop node tree (#4983): a node's stable GUID, its parent's GUID, and
  37. // whether it's a read-only transitive sub-node surfaced from a downstream node.
  38. guid: z.string().optional(),
  39. parentGuid: z.string().optional(),
  40. transitive: z.boolean().optional(),
  41. }).loose();
  42. export const NodeListSchema = z.array(NodeRecordSchema);
  43. export const ProbeResultSchema = z.object({
  44. status: z.string(),
  45. latencyMs: z.number().optional(),
  46. xrayVersion: z.string().optional(),
  47. error: z.string().optional(),
  48. // Present on successful probe; used to surface "connected to panel, but xray failed on node".
  49. xrayState: z.string().optional(),
  50. xrayError: z.string().optional(),
  51. }).loose();
  52. export const NodeFormSchema = z.object({
  53. id: z.number().optional(),
  54. name: z.string().trim().min(1, 'pages.nodes.toasts.fillRequired'),
  55. remark: z.string().optional(),
  56. scheme: z.enum(['http', 'https']),
  57. address: z.string().trim().min(1, 'pages.nodes.toasts.fillRequired'),
  58. port: z.number().int().min(1).max(65535),
  59. basePath: z.string(),
  60. apiToken: z.string().trim().min(1, 'pages.nodes.toasts.fillRequired'),
  61. enable: z.boolean(),
  62. allowPrivateAddress: z.boolean(),
  63. tlsVerifyMode: z.enum(['verify', 'skip', 'pin']),
  64. pinnedCertSha256: z.string().optional().default(''),
  65. inboundSyncMode: z.enum(['all', 'selected']).optional().default('all'),
  66. // Unmounted when sync mode is "all" (absent from antd onFinish values) and
  67. // serialized as null by the backend for a nil slice — tolerate both.
  68. inboundTags: z.array(z.string()).nullish().transform((tags) => tags ?? []),
  69. });
  70. export type NodeRecord = z.infer<typeof NodeRecordSchema>;
  71. export type ProbeResult = z.infer<typeof ProbeResultSchema>;
  72. export type NodeFormValues = z.infer<typeof NodeFormSchema>;