use new configs PATCH API

This commit is contained in:
Yonghui Zhang 2018-12-24 23:36:52 +08:00
parent 38e5b480c0
commit 2b5820a56a
3 changed files with 14 additions and 6 deletions

View file

@ -11,12 +11,20 @@ export async function fetchConfigs(apiConfig) {
// req body // req body
// { Path: string } // { Path: string }
function configsPatchWorkaround(o) {
// backward compatibility for older clash using `socket-port`
if ('socks-port' in o) {
o['socket-port'] = o['socks-port'];
}
return o;
}
export async function updateConfigs(apiConfig, o) { export async function updateConfigs(apiConfig, o) {
const { url, init } = getURLAndInit(apiConfig); const { url, init } = getURLAndInit(apiConfig);
return await fetch(url + endpoint, { return await fetch(url + endpoint, {
...init, ...init,
method: 'PATCH', method: 'PATCH',
// mode: 'cors', // mode: 'cors',
body: JSON.stringify(o) body: JSON.stringify(configsPatchWorkaround(o))
}); });
} }

View file

@ -99,7 +99,7 @@ function Config({ configs }) {
updateConfigs({ [name]: value }); updateConfigs({ [name]: value });
break; break;
case 'redir-port': case 'redir-port':
case 'socket-port': case 'socks-port':
case 'port': case 'port':
if (target.value !== '') { if (target.value !== '') {
const num = parseInt(target.value, 10); const num = parseInt(target.value, 10);
@ -117,7 +117,7 @@ function Config({ configs }) {
const { name, value } = target; const { name, value } = target;
switch (name) { switch (name) {
case 'port': case 'port':
case 'socket-port': case 'socks-port':
case 'redir-port': { case 'redir-port': {
const num = parseInt(value, 10); const num = parseInt(value, 10);
if (num < 0 || num > 65535) return; if (num < 0 || num > 65535) return;
@ -144,8 +144,8 @@ function Config({ configs }) {
<div> <div>
<div className={s0.label}>SOCKS5 Proxy Port</div> <div className={s0.label}>SOCKS5 Proxy Port</div>
<Input <Input
name="socket-port" name="socks-port"
value={configState['socket-port']} value={configState['socks-port']}
onChange={handleInputOnChange} onChange={handleInputOnChange}
onBlur={handleInputOnBlur} onBlur={handleInputOnBlur}
/> />

View file

@ -99,7 +99,7 @@ export function updateConfigs(partialConfg) {
const initialState = { const initialState = {
port: 7890, port: 7890,
'socket-port': 7891, 'socks-port': 7891,
'redir-port': 0, 'redir-port': 0,
'allow-lan': false, 'allow-lan': false,
mode: 'Rule', mode: 'Rule',