Files
clash-proxy/src/services/types.ts

206 lines
4.2 KiB
TypeScript
Raw Normal View History

2021-12-25 22:33:29 +08:00
/**
* Some interface for clash api
*/
export namespace ApiType {
export interface ConfigData {
port: number;
mode: string;
ipv6: boolean;
"socket-port": number;
"allow-lan": boolean;
"log-level": string;
"mixed-port": number;
"redir-port": number;
"socks-port": number;
"tproxy-port": number;
}
export interface RuleItem {
type: string;
payload: string;
proxy: string;
}
export interface ProxyItem {
name: string;
type: string;
udp: boolean;
history: {
time: string;
delay: number;
}[];
all?: string[];
now?: string;
}
export type ProxyGroupItem = Omit<ProxyItem, "all"> & {
all: ProxyItem[];
};
export interface TrafficItem {
up: number;
down: number;
}
export interface LogItem {
type: string;
time?: string;
payload: string;
}
export interface ConnectionsItem {
id: string;
metadata: {
network: string;
type: string;
host: string;
sourceIP: string;
sourcePort: string;
destinationPort: string;
destinationIP?: string;
};
upload: number;
download: number;
start: string;
chains: string[];
rule: string;
rulePayload: string;
}
export interface Connections {
downloadTotal: number;
uploadTotal: number;
connections: ConnectionsItem[];
}
}
/**
* Some interface for command
*/
export namespace CmdType {
2022-03-05 19:04:20 +08:00
export type ProfileType = "local" | "remote" | "merge" | "script";
2021-12-25 22:33:29 +08:00
export interface ClashInfo {
status: string;
2022-01-07 23:29:20 +08:00
port?: string;
server?: string;
secret?: string;
2021-12-25 22:33:29 +08:00
}
export interface ProfileItem {
2022-03-01 08:58:47 +08:00
uid: string;
2022-03-05 19:04:20 +08:00
type?: ProfileType | string;
2021-12-25 22:33:29 +08:00
name?: string;
2022-02-09 02:08:27 +08:00
desc?: string;
2021-12-25 22:33:29 +08:00
file?: string;
url?: string;
updated?: number;
selected?: {
name?: string;
now?: string;
}[];
extra?: {
upload: number;
download: number;
total: number;
expire: number;
};
option?: ProfileOption;
}
export interface ProfileOption {
user_agent?: string;
with_proxy?: boolean;
2021-12-25 22:33:29 +08:00
}
export interface ProfilesConfig {
2022-03-01 08:58:47 +08:00
current?: string;
chain?: string[];
valid?: string[];
2021-12-25 22:33:29 +08:00
items?: ProfileItem[];
}
export interface VergeConfig {
2022-03-12 23:07:45 +08:00
language?: string;
2021-12-25 22:33:29 +08:00
theme_mode?: "light" | "dark";
2022-01-12 02:27:29 +08:00
theme_blur?: boolean;
traffic_graph?: boolean;
2022-02-25 02:09:39 +08:00
enable_tun_mode?: boolean;
2022-01-15 21:58:13 +08:00
enable_auto_launch?: boolean;
2022-03-26 18:56:16 +08:00
enable_silent_start?: boolean;
2021-12-25 22:33:29 +08:00
enable_system_proxy?: boolean;
2022-02-20 18:53:21 +08:00
enable_proxy_guard?: boolean;
2022-02-14 01:26:24 +08:00
system_proxy_bypass?: string;
2022-03-31 23:38:00 +08:00
theme_setting?: {
primary_color?: string;
secondary_color?: string;
primary_text?: string;
secondary_text?: string;
info_color?: string;
error_color?: string;
warning_color?: string;
success_color?: string;
font_family?: string;
2022-04-01 02:08:42 +08:00
css_injection?: string;
2022-03-31 23:38:00 +08:00
};
2021-12-25 22:33:29 +08:00
}
2022-03-03 01:58:05 +08:00
type ClashConfigValue = any;
export interface ProfileMerge {
// clash config fields (default supports)
rules?: ClashConfigValue;
proxies?: ClashConfigValue;
"proxy-groups"?: ClashConfigValue;
"proxy-providers"?: ClashConfigValue;
"rule-providers"?: ClashConfigValue;
// clash config fields (use flag)
tun?: ClashConfigValue;
dns?: ClashConfigValue;
hosts?: ClashConfigValue;
script?: ClashConfigValue;
profile?: ClashConfigValue;
payload?: ClashConfigValue;
"interface-name"?: ClashConfigValue;
"routing-mark"?: ClashConfigValue;
// functional fields
use?: string[];
"prepend-rules"?: any[];
"append-rules"?: any[];
"prepend-proxies"?: any[];
"append-proxies"?: any[];
"prepend-proxy-groups"?: any[];
"append-proxy-groups"?: any[];
}
2022-03-06 14:59:25 +08:00
// partial of the clash config
export type ProfileData = Partial<{
rules: any[];
proxies: any[];
"proxy-groups": any[];
"proxy-providers": any[];
"rule-providers": any[];
[k: string]: any;
2022-03-06 14:59:25 +08:00
}>;
2022-03-03 01:58:05 +08:00
export interface ChainItem {
item: ProfileItem;
2022-03-06 14:59:25 +08:00
merge?: ProfileMerge;
2022-03-03 01:58:05 +08:00
script?: string;
}
export interface EnhancedPayload {
chain: ChainItem[];
valid: string[];
2022-03-06 14:59:25 +08:00
current: ProfileData;
callback: string;
}
export interface EnhancedResult {
data: ProfileData;
status: string;
error?: string;
2022-03-03 01:58:05 +08:00
}
2021-12-25 22:33:29 +08:00
}