vless.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { useEffect, useState } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { Button, Form, Input, InputNumber, Select, Space, Typography } from 'antd';
  4. import { VLESS_AUTH_LABEL_KEYS, type VlessAuthKind } from '@/lib/xray/vless-encryption';
  5. interface VlessFieldsProps {
  6. saving: boolean;
  7. selectedVlessAuth: string;
  8. vlessAuthKind: VlessAuthKind | null;
  9. network: string;
  10. security: string;
  11. getNewVlessEnc: (kind: VlessAuthKind) => void;
  12. clearVlessEnc: () => void;
  13. }
  14. export default function VlessFields({
  15. saving,
  16. selectedVlessAuth,
  17. vlessAuthKind,
  18. network,
  19. security,
  20. getNewVlessEnc,
  21. clearVlessEnc,
  22. }: VlessFieldsProps) {
  23. const { t } = useTranslation();
  24. const [authKind, setAuthKind] = useState<VlessAuthKind>(vlessAuthKind ?? 'x25519');
  25. useEffect(() => {
  26. setAuthKind(vlessAuthKind ?? 'x25519');
  27. }, [vlessAuthKind]);
  28. const authOptions = (Object.entries(VLESS_AUTH_LABEL_KEYS) as [VlessAuthKind, string][]).map(
  29. ([value, labelKey]) => ({ value, label: t(labelKey) }),
  30. );
  31. return (
  32. <>
  33. <Form.Item name={['settings', 'decryption']} label={t('pages.inbounds.decryption')}>
  34. <Input />
  35. </Form.Item>
  36. <Form.Item name={['settings', 'encryption']} label={t('pages.inbounds.encryption')}>
  37. <Input />
  38. </Form.Item>
  39. <Form.Item label={t('pages.inbounds.vlessAuthGenerate')}>
  40. <Space size={8} wrap>
  41. <Select
  42. value={authKind}
  43. onChange={(v) => setAuthKind(v)}
  44. options={authOptions}
  45. style={{ width: 240 }}
  46. />
  47. <Button type="primary" loading={saving} onClick={() => getNewVlessEnc(authKind)}>
  48. {t('pages.inbounds.vlessAuthGenerateButton')}
  49. </Button>
  50. <Button danger onClick={clearVlessEnc}>{t('clear')}</Button>
  51. </Space>
  52. <Typography.Text type="secondary" className="vless-auth-state">
  53. {t('pages.inbounds.vlessAuthSelected', { auth: selectedVlessAuth })}
  54. </Typography.Text>
  55. </Form.Item>
  56. {network === 'tcp' && (security === 'tls' || security === 'reality') && (
  57. <Form.Item
  58. label={t('pages.inbounds.form.visionTestseed')}
  59. extra="Applies only to clients using the xtls-rprx-vision flow; ignored otherwise."
  60. >
  61. <Space.Compact block>
  62. {[900, 500, 900, 256].map((def, i) => (
  63. <Form.Item key={i} name={['settings', 'testseed', i]} noStyle initialValue={def}>
  64. <InputNumber min={1} style={{ width: '25%' }} />
  65. </Form.Item>
  66. ))}
  67. </Space.Compact>
  68. </Form.Item>
  69. )}
  70. </>
  71. );
  72. }