blob: 78ceb834cfcd706ce2b3eee596691c0147eb3628 (
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
|
import { getURLAndInit } from 'src/misc/request-helper';
import { ClashAPIConfig } from 'src/types';
type VersionData = {
version?: string;
premium?: 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;
}
|