From 4ae2c5c2f319e15ecba245f8b679dbfcd0242a84 Mon Sep 17 00:00:00 2001 From: Haishan Date: Sat, 1 Aug 2020 20:04:49 +0800 Subject: feat: a simple about page --- src/api/version.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/api/version.ts (limited to 'src/api/version.ts') 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 { + 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; +} -- cgit v1.3.1