gitscope
← marzneshin / v0.6.4 / dashboard/src/modules/hosts/dialogs/mutation/profiles/general/schema.ts
https://dev.kronoz.win/r/marzneshin.git
dashboard/src/modules/hosts/dialogs/mutation/profiles/general/schema.ts · TypeScript
Blame Raw
 1import { z } from "zod";
 2import { HostSchema, TlsSchema } from "@marzneshin/modules/hosts";
 3import i18n from "i18next";
 4
 5const numberInterval = (v: string | null | undefined) => {
 6    return v ? /^[\d-]{1,32}$/.test(v) : false;
 7};
 8
 9const packetsInterval = (v: string | null | undefined) => {
10    return v ? /^(:?tlshello|[\d-]{1,32})$/.test(v) : false;
11};
12
13export const alpnOptions = [
14    "none",
15    "h2",
16    "h3",
17    "h3,h2",
18    "http/1.1",
19    "h2,http/1.1",
20    "h3,h2,http/1.1"
21]
22
23export const GeneralSchema = HostSchema.merge(TlsSchema).extend({
24    path: z.string().nullable().optional(),
25    host: z.string().nullable().optional(),
26    mux: z.boolean().nullable().optional(),
27    fragment: z
28        .object({
29            interval: z
30                .string()
31                .refine(
32                    (v) => numberInterval(v),
33                    i18n.t("page.hosts.fragment.interval-error"),
34                ),
35            length: z
36                .string()
37                .refine(
38                    (v) => numberInterval(v),
39                    i18n.t("page.hosts.fragment.length-error"),
40                ),
41            packets: z
42                .string()
43                .refine(
44                    (v) => packetsInterval(v),
45                    i18n.t("page.hosts.fragment.packets-error"),
46                ),
47        })
48        .nullable()
49        .optional(),
50    security: z
51        .enum(["inbound_default", "none", "tls"])
52        .default("inbound_default"),
53    fingerprint: z
54        .enum([
55            "",
56            "none",
57            "chrome",
58            "firefox",
59            "safari",
60            "ios",
61            "android",
62            "edge",
63            "360",
64            "qq",
65            "random",
66            "randomized",
67        ])
68        .optional()
69        .default("none"),
70});
71
72
73export type GeneralSchemaType = z.infer<typeof GeneralSchema>;