mirror of
https://github.com/remnawave/node.git
synced 2026-10-22 02:41:19 +00:00
81 lines
2 KiB
TypeScript
81 lines
2 KiB
TypeScript
import { z } from 'zod';
|
|
|
|
import { REST_API } from '../../api';
|
|
|
|
export enum CipherType {
|
|
AES_128_GCM = 5,
|
|
AES_256_GCM = 6,
|
|
CHACHA20_POLY1305 = 7,
|
|
UNKNOWN = 0,
|
|
UNRECOGNIZED = -1,
|
|
XCHACHA20_POLY1305 = 8,
|
|
}
|
|
|
|
export namespace AddUserCommand {
|
|
export const url = REST_API.HANDLER.ADD_USER;
|
|
|
|
const BaseTrojanUser = z.object({
|
|
type: z.literal('trojan'),
|
|
tag: z.string(),
|
|
username: z.string(),
|
|
password: z.string(),
|
|
});
|
|
|
|
const BaseVlessUser = z.object({
|
|
type: z.literal('vless'),
|
|
tag: z.string(),
|
|
username: z.string(),
|
|
uuid: z.string(),
|
|
flow: z.enum(['xtls-rprx-vision', '']),
|
|
});
|
|
|
|
const BaseShadowsocksUser = z.object({
|
|
type: z.literal('shadowsocks'),
|
|
tag: z.string(),
|
|
username: z.string(),
|
|
password: z.string(),
|
|
cipherType: z.enum(CipherType),
|
|
ivCheck: z.boolean(),
|
|
});
|
|
|
|
const BaseShadowsocks22User = z.object({
|
|
type: z.literal('shadowsocks22'),
|
|
tag: z.string(),
|
|
username: z.string(),
|
|
password: z.string(),
|
|
});
|
|
|
|
const BaseHysteriaUser = z.object({
|
|
type: z.literal('hysteria'),
|
|
tag: z.string(),
|
|
username: z.string(),
|
|
password: z.string(),
|
|
});
|
|
|
|
export const RequestSchema = z.object({
|
|
data: z.array(
|
|
z.discriminatedUnion('type', [
|
|
BaseTrojanUser,
|
|
BaseVlessUser,
|
|
BaseShadowsocksUser,
|
|
BaseShadowsocks22User,
|
|
BaseHysteriaUser,
|
|
]),
|
|
),
|
|
hashData: z.object({
|
|
vlessUuid: z.uuid(),
|
|
prevVlessUuid: z.optional(z.uuid()),
|
|
}),
|
|
});
|
|
|
|
export type Request = z.infer<typeof RequestSchema>;
|
|
|
|
export const ResponseSchema = z.object({
|
|
response: z.object({
|
|
success: z.boolean(),
|
|
error: z.string().nullable(),
|
|
}),
|
|
});
|
|
|
|
export type Response = z.infer<typeof ResponseSchema>;
|
|
}
|