summaryrefslogtreecommitdiff
path: root/src/api/version.ts
blob: 6c291252905585c1974fc05caa6306b211dfcf4b (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
import { getURLAndInit } from '~/misc/request-helper';
import { ClashAPIConfig } from '~/types';

type VersionData = {
  version?: string;
  premium?: boolean;
  meta?: boolean;
};

export async function fetchVersion(
  endpoint: string,
  apiConfig: ClashAPIConfig
): Promise<VersionData> {
  let json = {};
  try {
    const { url, init } = getURLAndInit(apiConfig);
    const res = await fetch(url + endpoint, init);
    if (res.ok) {
      json = await res.json();
    }
  } catch (err) {
    // log and ignore
    // eslint-disable-next-line no-console
    console.log(`failed to fetch ${endpoint}`, err);
  }
  return json;
}