types.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /**
  2. * Some interface for clash api
  3. */
  4. export namespace ApiType {
  5. export interface ConfigData {
  6. port: number;
  7. mode: string;
  8. ipv6: boolean;
  9. "socket-port": number;
  10. "allow-lan": boolean;
  11. "log-level": string;
  12. "mixed-port": number;
  13. "redir-port": number;
  14. "socks-port": number;
  15. "tproxy-port": number;
  16. }
  17. export interface RuleItem {
  18. type: string;
  19. payload: string;
  20. proxy: string;
  21. }
  22. export interface ProxyItem {
  23. name: string;
  24. type: string;
  25. udp: boolean;
  26. history: {
  27. time: string;
  28. delay: number;
  29. }[];
  30. all?: string[];
  31. now?: string;
  32. }
  33. export type ProxyGroupItem = Omit<ProxyItem, "all"> & {
  34. all: ProxyItem[];
  35. };
  36. export interface TrafficItem {
  37. up: number;
  38. down: number;
  39. }
  40. export interface LogItem {
  41. type: string;
  42. time?: string;
  43. payload: string;
  44. }
  45. export interface ConnectionsItem {
  46. id: string;
  47. metadata: {
  48. network: string;
  49. type: string;
  50. host: string;
  51. sourceIP: string;
  52. sourcePort: string;
  53. destinationPort: string;
  54. destinationIP?: string;
  55. };
  56. upload: number;
  57. download: number;
  58. start: string;
  59. chains: string[];
  60. rule: string;
  61. rulePayload: string;
  62. curUpload?: number; // calculate
  63. curDownload?: number; // calculate
  64. }
  65. export interface Connections {
  66. downloadTotal: number;
  67. uploadTotal: number;
  68. connections: ConnectionsItem[];
  69. }
  70. }
  71. /**
  72. * Some interface for command
  73. */
  74. export namespace CmdType {
  75. export type ProfileType = "local" | "remote" | "merge" | "script";
  76. export interface ClashInfo {
  77. status: string;
  78. port?: string;
  79. server?: string;
  80. secret?: string;
  81. }
  82. export interface ProfileItem {
  83. uid: string;
  84. type?: ProfileType | string;
  85. name?: string;
  86. desc?: string;
  87. file?: string;
  88. url?: string;
  89. updated?: number;
  90. selected?: {
  91. name?: string;
  92. now?: string;
  93. }[];
  94. extra?: {
  95. upload: number;
  96. download: number;
  97. total: number;
  98. expire: number;
  99. };
  100. option?: ProfileOption;
  101. }
  102. export interface ProfileOption {
  103. user_agent?: string;
  104. with_proxy?: boolean;
  105. }
  106. export interface ProfilesConfig {
  107. current?: string;
  108. chain?: string[];
  109. valid?: string[];
  110. items?: ProfileItem[];
  111. }
  112. export interface VergeConfig {
  113. language?: string;
  114. theme_mode?: "light" | "dark";
  115. theme_blur?: boolean;
  116. traffic_graph?: boolean;
  117. enable_tun_mode?: boolean;
  118. enable_auto_launch?: boolean;
  119. enable_silent_start?: boolean;
  120. enable_system_proxy?: boolean;
  121. enable_proxy_guard?: boolean;
  122. system_proxy_bypass?: string;
  123. theme_setting?: {
  124. primary_color?: string;
  125. secondary_color?: string;
  126. primary_text?: string;
  127. secondary_text?: string;
  128. info_color?: string;
  129. error_color?: string;
  130. warning_color?: string;
  131. success_color?: string;
  132. font_family?: string;
  133. css_injection?: string;
  134. };
  135. }
  136. type ClashConfigValue = any;
  137. export interface ProfileMerge {
  138. // clash config fields (default supports)
  139. rules?: ClashConfigValue;
  140. proxies?: ClashConfigValue;
  141. "proxy-groups"?: ClashConfigValue;
  142. "proxy-providers"?: ClashConfigValue;
  143. "rule-providers"?: ClashConfigValue;
  144. // clash config fields (use flag)
  145. tun?: ClashConfigValue;
  146. dns?: ClashConfigValue;
  147. hosts?: ClashConfigValue;
  148. script?: ClashConfigValue;
  149. profile?: ClashConfigValue;
  150. payload?: ClashConfigValue;
  151. "interface-name"?: ClashConfigValue;
  152. "routing-mark"?: ClashConfigValue;
  153. // functional fields
  154. use?: string[];
  155. "prepend-rules"?: any[];
  156. "append-rules"?: any[];
  157. "prepend-proxies"?: any[];
  158. "append-proxies"?: any[];
  159. "prepend-proxy-groups"?: any[];
  160. "append-proxy-groups"?: any[];
  161. }
  162. // partial of the clash config
  163. export type ProfileData = Partial<{
  164. rules: any[];
  165. proxies: any[];
  166. "proxy-groups": any[];
  167. "proxy-providers": any[];
  168. "rule-providers": any[];
  169. [k: string]: any;
  170. }>;
  171. export interface ChainItem {
  172. item: ProfileItem;
  173. merge?: ProfileMerge;
  174. script?: string;
  175. }
  176. export interface EnhancedPayload {
  177. chain: ChainItem[];
  178. valid: string[];
  179. current: ProfileData;
  180. callback: string;
  181. }
  182. export interface EnhancedResult {
  183. data: ProfileData;
  184. status: string;
  185. error?: string;
  186. }
  187. }