summaryrefslogtreecommitdiff
path: root/src/api/configs.js
blob: 42f8ff019cd590c1765494165f94b45091f6e5c1 (plain)
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
import { getURLAndInit } from '../misc/request-helper';

const endpoint = '/configs';

export async function fetchConfigs(apiConfig) {
  const { url, init } = getURLAndInit(apiConfig);
  return await fetch(url + endpoint, init);
}

// TODO support PUT /configs
// 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(configsPatchWorkaround(o))
  });
}