← marzneshin
/
dashboard/src/modules/hosts/dialogs/mutation/profiles/use-profile-strategy.ts
/
blame
https://dev.kronoz.win/r/marzneshin.git
| 1 | d636f3f | Dawsh | 2y ago | import { ProtocolType } from "@marzneshin/modules/inbounds"; |
| 2 | d636f3f | Dawsh | 2y ago | import { FC } from "react"; |
| 3 | d636f3f | Dawsh | 2y ago | import { GeneralSchema, GeneralProfileFields, generalProfileDefaultValue } from "./general"; |
| 4 | d636f3f | Dawsh | 2y ago | import { WireguardSchema, WireguardProfileFields, wireguardProfileDefaultValue } from "./wireguard"; |
| 5 | d636f3f | Dawsh | 2y ago | import { Hysteria2Schema, Hysteria2ProfileFields, hysteria2ProfileDefaultValue } from "./hysteria2"; |
| 6 | 70b35e2 | Dawsh | 1y ago | import { ShadowTlsSchema, ShadowTlsProfileFields, shadowTlsProfileDefaultValue } from "./shadowtls"; |
| 7 | d636f3f | Dawsh | 2y ago | import { TuicSchema, TuicProfileFields, tuicProfileDefaultValue } from "./tuic"; |
| 8 | d636f3f | Dawsh | 2y ago | |
| 9 | d636f3f | Dawsh | 2y ago | type ProfileSchema = typeof GeneralSchema | typeof WireguardSchema | typeof Hysteria2Schema | typeof TuicSchema; |
| 10 | d636f3f | Dawsh | 2y ago | type ProfileFields = FC; |
| 11 | d636f3f | Dawsh | 2y ago | |
| 12 | d636f3f | Dawsh | 2y ago | /** |
| 13 | d636f3f | Dawsh | 2y ago | * @param protocol - Inbound protocol of host |
| 14 | d636f3f | Dawsh | 2y ago | * @returns [schema, fields, default values] - An array of schema, profile fields, and their default |
| 15 | d636f3f | Dawsh | 2y ago | */ |
| 16 | d636f3f | Dawsh | 2y ago | export const useProfileStrategy = ( |
| 17 | d636f3f | Dawsh | 2y ago | protocol?: ProtocolType |
| 18 | d636f3f | Dawsh | 2y ago | ): [ProfileSchema, ProfileFields, object] => { |
| 19 | d636f3f | Dawsh | 2y ago | if (!protocol) |
| 20 | d636f3f | Dawsh | 2y ago | return [GeneralSchema, GeneralProfileFields, generalProfileDefaultValue] |
| 21 | d636f3f | Dawsh | 2y ago | |
| 22 | d636f3f | Dawsh | 2y ago | const profileMap: { [key in ProtocolType]: [ProfileSchema, ProfileFields, object] } = { |
| 23 | d636f3f | Dawsh | 2y ago | vless: [GeneralSchema, GeneralProfileFields, generalProfileDefaultValue], |
| 24 | d636f3f | Dawsh | 2y ago | vmess: [GeneralSchema, GeneralProfileFields, generalProfileDefaultValue], |
| 25 | d636f3f | Dawsh | 2y ago | trojan: [GeneralSchema, GeneralProfileFields, generalProfileDefaultValue], |
| 26 | d636f3f | Dawsh | 2y ago | shadowsocks: [GeneralSchema, GeneralProfileFields, generalProfileDefaultValue], |
| 27 | d636f3f | Dawsh | 2y ago | shadowsocks2022: [GeneralSchema, GeneralProfileFields, generalProfileDefaultValue], |
| 28 | d636f3f | Dawsh | 2y ago | wireguard: [WireguardSchema, WireguardProfileFields, wireguardProfileDefaultValue], |
| 29 | d636f3f | Dawsh | 2y ago | hysteria2: [Hysteria2Schema, Hysteria2ProfileFields, hysteria2ProfileDefaultValue], |
| 30 | 70b35e2 | Dawsh | 1y ago | shadowtls: [ShadowTlsSchema, ShadowTlsProfileFields, shadowTlsProfileDefaultValue], |
| 31 | d636f3f | Dawsh | 2y ago | tuic: [TuicSchema, TuicProfileFields, tuicProfileDefaultValue], |
| 32 | d636f3f | Dawsh | 2y ago | }; |
| 33 | d636f3f | Dawsh | 2y ago | |
| 34 | d636f3f | Dawsh | 2y ago | const [Schema, Fields, defaultValues] = profileMap[protocol] || [GeneralSchema, GeneralProfileFields, generalProfileDefaultValue]; |
| 35 | d636f3f | Dawsh | 2y ago | return [Schema, Fields, defaultValues]; |
| 36 | d636f3f | Dawsh | 2y ago | }; |