From 2b5820a56a5069e07eabb29ff18aa3574d9c2824 Mon Sep 17 00:00:00 2001 From: Yonghui Zhang Date: Mon, 24 Dec 2018 23:36:52 +0800 Subject: [PATCH] use new configs PATCH API --- src/api/configs.js | 10 +++++++++- src/components/Config.js | 8 ++++---- src/ducks/configs.js | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/api/configs.js b/src/api/configs.js index 592f9fb..64f6b95 100644 --- a/src/api/configs.js +++ b/src/api/configs.js @@ -11,12 +11,20 @@ export async function fetchConfigs(apiConfig) { // req body // { 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) { const { url, init } = getURLAndInit(apiConfig); return await fetch(url + endpoint, { ...init, method: 'PATCH', // mode: 'cors', - body: JSON.stringify(o) + body: JSON.stringify(configsPatchWorkaround(o)) }); } diff --git a/src/components/Config.js b/src/components/Config.js index e1a7af3..6656ad7 100644 --- a/src/components/Config.js +++ b/src/components/Config.js @@ -99,7 +99,7 @@ function Config({ configs }) { updateConfigs({ [name]: value }); break; case 'redir-port': - case 'socket-port': + case 'socks-port': case 'port': if (target.value !== '') { const num = parseInt(target.value, 10); @@ -117,7 +117,7 @@ function Config({ configs }) { const { name, value } = target; switch (name) { case 'port': - case 'socket-port': + case 'socks-port': case 'redir-port': { const num = parseInt(value, 10); if (num < 0 || num > 65535) return; @@ -144,8 +144,8 @@ function Config({ configs }) {
SOCKS5 Proxy Port
diff --git a/src/ducks/configs.js b/src/ducks/configs.js index a7d4b83..5c035b8 100644 --- a/src/ducks/configs.js +++ b/src/ducks/configs.js @@ -99,7 +99,7 @@ export function updateConfigs(partialConfg) { const initialState = { port: 7890, - 'socket-port': 7891, + 'socks-port': 7891, 'redir-port': 0, 'allow-lan': false, mode: 'Rule',