summaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/api')
-rw-r--r--src/api/version.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/api/version.ts b/src/api/version.ts
new file mode 100644
index 0000000..eb8a86c
--- /dev/null
+++ b/src/api/version.ts
@@ -0,0 +1,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 = { rules: [] };
+ 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;
+}