summaryrefslogtreecommitdiff
path: root/src/api/version.ts
diff options
context:
space:
mode:
authorHaishan <[email protected]>2020-08-01 20:04:49 +0800
committerHaishan <[email protected]>2020-08-01 20:41:55 +0800
commit4ae2c5c2f319e15ecba245f8b679dbfcd0242a84 (patch)
treed269f9511ba922800c0308b04cf7d0386588270a /src/api/version.ts
parent437733f4afe1eae86f946a8aa3336f58d9980d8c (diff)
feat: a simple about page
Diffstat (limited to 'src/api/version.ts')
-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;
+}