-
Notifications
You must be signed in to change notification settings - Fork 279
/
sample-configuration-api.js
153 lines (134 loc) · 3.81 KB
/
sample-configuration-api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/**
* @fileoverview Example to deal with current configuration through API $configuration.sendMessage.
*
*
* Action: url_latency_benchmark
* Do the URL Latency Benchmark for the input servers (actually server tags),
* So you can customize (combined with task) your static policy to a url-latency-benchmark like policy.
* For more features maybe added in the future, you may have more control over the policy.
* Returns a JSON like {"ret" : {"Node-001" : [31, 126], "Node-002" : [23, -1]}}
*
*
* Action: get_server_description (only available for event-interaction script and v1.0.30-build691 iOS 13.0 +)
* Returns a JSON like {"ret" : {"TheTag" : "socks5=example.com:80,fast-open=false, udp-relay=false, tag=TheTag"}}
* If no such server with the tag, then returns a JSON {"ret" : {"TheTag" : ""}}
* This action does not support empty or array content input, since getting all servers is inappropriate.
*
*
* Action: get_customized_policy
* Returns a JSON
*
*
* Action: get_policy_state
* Returns a JSON like {"ret" : {"policy1" : ["policy1", "thePolicyThatPolicy1Selected", ... , "theLeaf1"],
* "policy2" : ["policy2", "thePolicyThatPolicy2Selected", ... ,"theLeaf2"]}}
*
*
* Action: set_policy_state
* This only works for the static type policy and the built-in policy named "proxy".
* Related active connections will be closed if the "Moderated Policy Mechanism" is turned off,
* the returned JSON from set_policy_state will resolve (promise) only when all the related connections
* are closed.
* If this API is called in a response type script, even all the related active connections
* (including the connection that called this API) will be closed, but actually the reponse of this connection
* has already been completely received.
* Returns an updated policy state in JSON like {"ret" : {"policy1" : ["policy1", "thePolicyThatPolicy1Selected", ... ,
* "theLeaf1"], "policy2" : ["policy2", "thePolicyThatPolicy2Selected", ... , "theLeaf2"]}}
*
*
* @supported Quantumult X (v1.0.22-build545) iOS 13.0 +
*/
/*
const dict = {"proxy": "Node-002", "cPolicy": "Node-007"};
const message = {
action: "set_policy_state",
content: dict
};
*/
/*
const array = ["Node-001","Node-002","Node-003","Node-004"];
const message = {
action: "url_latency_benchmark",
content: array
};
*/
/*
const data = "TheTag";
const message = {
action: "get_server_description",
content: data
};
*/
/*
const message = {
action: "get_customized_policy"
};
*/
/*
const data = "PolicyName";
const message = {
action: "get_customized_policy",
content: data
};
*/
/*
const data = ["PolicyName1","PolicyName2"];
const message = {
action: "get_customized_policy",
content: data
};
*/
/*
const message = {
action: "get_running_mode"
};
$configuration.sendMessage(message).then(resolve => {
if (resolve.error) {
console.log(resolve.error);
}
if (resolve.ret) {
let output=JSON.stringify(resolve.ret);
console.log(output);
}
$done();
}, reject => {
// Normally will never happen.
$done();
});
*/
/* all_proxy, all_direct, filter
const dict = { "running_mode": "all_proxy" };
const message = {
action: "set_running_mode",
content: dict
};
$configuration.sendMessage(message).then(resolve => {
if (resolve.error) {
console.log(resolve.error);
}
if (resolve.ret) {
let output=JSON.stringify(resolve.ret);
console.log(output);
}
$done();
}, reject => {
// Normally will never happen.
$done();
});
*/
const message = {
action: "get_policy_state"
};
$configuration.sendMessage(message).then(resolve => {
if (resolve.error) {
console.log(resolve.error);
}
if (resolve.ret) {
let output=JSON.stringify(resolve.ret);
console.log(output);
}
$done();
}, reject => {
// Normally will never happen.
$done();
});