diff options
| author | Haishan <[email protected]> | 2019-12-20 17:45:05 +0800 |
|---|---|---|
| committer | Haishan <[email protected]> | 2019-12-20 17:45:05 +0800 |
| commit | d81592ec970d207d4e37beb6c275ad6b77979e39 (patch) | |
| tree | 33aac796297864d95307f21d6a9aa790e3c33c09 /src/api | |
| parent | 040c5de04a75415490f9c478d931b7707bfa2486 (diff) | |
feat: support proxy provider
Diffstat (limited to 'src/api')
| -rw-r--r-- | src/api/proxies.js | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/api/proxies.js b/src/api/proxies.js index caa6da4..3ffb275 100644 --- a/src/api/proxies.js +++ b/src/api/proxies.js @@ -18,13 +18,13 @@ Vary: Origin Date: Tue, 16 Oct 2018 16:38:33 GMT */ -async function fetchProxies(config) { +export async function fetchProxies(config) { const { url, init } = getURLAndInit(config); const res = await fetch(url + endpoint, init); return await res.json(); } -async function requestToSwitchProxy(apiConfig, name1, name2) { +export async function requestToSwitchProxy(apiConfig, name1, name2) { const body = { name: name2 }; const { url, init } = getURLAndInit(apiConfig); const fullURL = `${url}${endpoint}/${name1}`; @@ -35,11 +35,27 @@ async function requestToSwitchProxy(apiConfig, name1, name2) { }); } -async function requestDelayForProxy(apiConfig, name) { +export async function requestDelayForProxy(apiConfig, name) { const { url, init } = getURLAndInit(apiConfig); const qs = 'timeout=5000&url=http://www.google.com/generate_204'; const fullURL = `${url}${endpoint}/${name}/delay?${qs}`; return await fetch(fullURL, init); } -export { fetchProxies, requestToSwitchProxy, requestDelayForProxy }; +export async function fetchProviderProxies(config) { + const { url, init } = getURLAndInit(config); + const res = await fetch(url + '/providers/proxies', init); + if (res.status === 404) { + return { providers: {} }; + } + return await res.json(); +} + +export async function updateProviderByName(config, name) { + const { url, init } = getURLAndInit(config); + const options = { + ...init, + method: 'PUT' + }; + return await fetch(url + '/providers/proxies/' + name, options); +} |
