mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-10-16 19:05:13 +03:00
ca5983595b
xray-core v26.10.10 tunnels a stream through files in shared cloud
storage ("network": "xdrive"): Google Drive, a local folder, or any HTTP
storage API described by a template. The panel could not select it, and
the stream schema rejected a pasted xdrive stream outright.
The inbound and outbound forms now offer XDRIVE with one shared editor:
service, folder, the three Google Drive secrets in the order the core
reads them, a template JSON editor with its {secretN} values, the
optional domain front (the stream-level address/port the storage client
dials), and the core's tuning knobs with their defaults as placeholders.
Switching an inbound to XDRIVE resets security to none, because the
core would otherwise read the inbound's TLS/REALITY as the storage API's
client TLS.
XDRIVE has no share-link format, and a link carrying the storage
secrets would print them into every QR code, so both link generators
emit none for it; the JSON subscription already passes the stream
through intact, and Clash drops the unknown transport.
82 lines
2.5 KiB
TypeScript
82 lines
2.5 KiB
TypeScript
import {
|
|
GrpcStreamSettingsSchema,
|
|
HttpUpgradeStreamSettingsSchema,
|
|
HysteriaStreamSettingsSchema,
|
|
KcpStreamSettingsSchema,
|
|
TcpStreamSettingsSchema,
|
|
WsStreamSettingsSchema,
|
|
XDriveStreamSettingsSchema,
|
|
XHttpStreamSettingsSchema,
|
|
} from '@/schemas/protocols/stream';
|
|
import { RealityStreamSettingsSchema, TlsStreamSettingsSchema } from '@/schemas/protocols/security';
|
|
|
|
const NETWORK_KEY_MAP = {
|
|
tcp: 'tcpSettings',
|
|
kcp: 'kcpSettings',
|
|
ws: 'wsSettings',
|
|
grpc: 'grpcSettings',
|
|
httpupgrade: 'httpupgradeSettings',
|
|
xhttp: 'xhttpSettings',
|
|
hysteria: 'hysteriaSettings',
|
|
xdrive: 'xdriveSettings',
|
|
} as const;
|
|
|
|
type SchemaWithParse = { safeParse: (v: unknown) => { success: boolean; data?: unknown } };
|
|
|
|
function parseOrDefault(schema: SchemaWithParse, value: unknown): unknown {
|
|
const parsed = schema.safeParse(value ?? {});
|
|
if (parsed.success) return parsed.data;
|
|
const fallback = schema.safeParse({});
|
|
return fallback.success ? fallback.data : value;
|
|
}
|
|
|
|
function networkSchemaFor(network: string): SchemaWithParse | null {
|
|
switch (network) {
|
|
case 'tcp':
|
|
return TcpStreamSettingsSchema;
|
|
case 'kcp':
|
|
return KcpStreamSettingsSchema;
|
|
case 'ws':
|
|
return WsStreamSettingsSchema;
|
|
case 'grpc':
|
|
return GrpcStreamSettingsSchema;
|
|
case 'httpupgrade':
|
|
return HttpUpgradeStreamSettingsSchema;
|
|
case 'xhttp':
|
|
return XHttpStreamSettingsSchema;
|
|
case 'hysteria':
|
|
return HysteriaStreamSettingsSchema;
|
|
case 'xdrive':
|
|
return XDriveStreamSettingsSchema;
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function securitySchemaFor(security: string): { key: string; schema: SchemaWithParse } | null {
|
|
switch (security) {
|
|
case 'tls':
|
|
return { key: 'tlsSettings', schema: TlsStreamSettingsSchema };
|
|
case 'reality':
|
|
return { key: 'realitySettings', schema: RealityStreamSettingsSchema };
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export function fillStreamDefaults(stream: Record<string, unknown>): Record<string, unknown> {
|
|
const network = (stream.network as string | undefined) ?? 'tcp';
|
|
const security = (stream.security as string | undefined) ?? 'none';
|
|
const out: Record<string, unknown> = { ...stream, network, security };
|
|
const subKey = NETWORK_KEY_MAP[network as keyof typeof NETWORK_KEY_MAP];
|
|
const netSchema = networkSchemaFor(network);
|
|
if (subKey && netSchema) {
|
|
out[subKey] = parseOrDefault(netSchema, out[subKey]);
|
|
}
|
|
const sec = securitySchemaFor(security);
|
|
if (sec) {
|
|
out[sec.key] = parseOrDefault(sec.schema, out[sec.key]);
|
|
}
|
|
return out;
|
|
}
|