vless.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { z } from 'zod';
  2. import { FlowSchema, SniffingSchema } from '@/schemas/primitives';
  3. export const VlessFallbackSchema = z.object({
  4. name: z.string().default(''),
  5. alpn: z.string().default(''),
  6. path: z.string().default(''),
  7. dest: z.union([z.string(), z.number()]).default(''),
  8. xver: z.number().int().min(0).default(0),
  9. });
  10. export type VlessFallback = z.infer<typeof VlessFallbackSchema>;
  11. export const VlessClientSchema = z.object({
  12. id: z.uuid(),
  13. email: z.string().min(1),
  14. flow: FlowSchema.default(''),
  15. limitIp: z.number().int().min(0).default(0),
  16. totalGB: z.number().int().min(0).default(0),
  17. expiryTime: z.number().int().default(0),
  18. enable: z.boolean().default(true),
  19. tgId: z.number().int().default(0),
  20. subId: z.string().default(''),
  21. comment: z.string().default(''),
  22. reset: z.number().int().min(0).default(0),
  23. // VLESS simple reverse-proxy: which reverse tag this client routes to,
  24. // plus an optional sniffing override for that path. Distinct from the
  25. // inbound-level `fallbacks` feature.
  26. reverse: z
  27. .object({
  28. tag: z.string(),
  29. sniffing: SniffingSchema.optional(),
  30. })
  31. .optional(),
  32. created_at: z.number().int().optional(),
  33. updated_at: z.number().int().optional(),
  34. });
  35. export type VlessClient = z.infer<typeof VlessClientSchema>;
  36. export const VlessInboundSettingsSchema = z.object({
  37. clients: z.array(VlessClientSchema).default([]),
  38. decryption: z.literal('none').default('none'),
  39. encryption: z.literal('none').default('none'),
  40. fallbacks: z.array(VlessFallbackSchema).default([]),
  41. // TODO: narrow to flow === 'xtls-rprx-vision' once a per-flow discriminator
  42. // exists. 4-positive-int padding seed for xtls-rprx-vision; backend uses
  43. // safe defaults when omitted.
  44. testseed: z.array(z.number().int().positive()).length(4).optional(),
  45. });
  46. export type VlessInboundSettings = z.infer<typeof VlessInboundSettingsSchema>;