From bedd6ccb1b77461eb2e48714d82de2b222aaa68c Mon Sep 17 00:00:00 2001 From: kyuuseiryuu Date: Thu, 29 Jan 2026 14:21:16 +0900 Subject: [PATCH] refact(global): token to env --- .gitignore | 2 ++ package.json | 2 +- src/config.example.ts | 5 +++++ src/index.tsx | 6 ++++++ src/types/index.ts | 3 +++ src/utils.ts | 7 ++++--- 6 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 src/config.example.ts diff --git a/.gitignore b/.gitignore index a14702c..b5e0470 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,5 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json # Finder (MacOS) folder config .DS_Store + +src/config.ts diff --git a/package.json b/package.json index 0ff5b24..632706e 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "bun-react-template", + "name": "my-kaiqiuwang", "version": "0.1.0", "private": true, "type": "module", diff --git a/src/config.example.ts b/src/config.example.ts new file mode 100644 index 0000000..1b4cc98 --- /dev/null +++ b/src/config.example.ts @@ -0,0 +1,5 @@ +import type { Config } from "./types"; + +export const config: Config = { + KAIQIUCC_TOKEN: '', +}; diff --git a/src/index.tsx b/src/index.tsx index 0dea370..824da7b 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,6 +1,12 @@ import { serve } from "bun"; import index from "./index.html"; import { getAdvProfile, getMatchInfo, getMemberDetail, getPlayerTags, listEvent } from "./utils"; +import { config } from "./config"; + +if (!config.KAIQIUCC_TOKEN) { + console.error('env KAIQIUCC_TOKEN not found'); + process.exit(1); +} const server = serve({ port: process.env.PORT || 3000, diff --git a/src/types/index.ts b/src/types/index.ts index 1175e0e..ed1600a 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,5 +1,8 @@ export * from './profile'; export * from './tag'; +export interface Config { + KAIQIUCC_TOKEN: string; +} export interface IEventInfo { title: string; info: string[]; diff --git a/src/utils.ts b/src/utils.ts index f8a3fba..2d61e5e 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,3 @@ -// import { fetch } from 'bun'; import type { IEventInfo, Player, XCXMember } from "./types"; import * as cheerio from "cheerio"; import fs from 'fs'; @@ -6,12 +5,14 @@ import path from 'path'; import { chunk } from 'lodash'; import type { XCXProfile } from "./types/profile"; import type { XCXTag } from "./types/tag"; +import { config } from './config'; const BASE_URL = `https://kaiqiuwang.cc`; const XCX_BASE_URL = `${BASE_URL}/xcx/public/index.php`; /** - * token: + * +token: XX-Device-Type: wxapp content-type: application/json Accept-Encoding: gzip,compress,br,deflate @@ -19,7 +20,7 @@ User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/6 Referer: https://servicewechat.com/wxff09fb0e92aa456a/464/page-frame.html */ const xcxDefaultHeaders = { - 'token': 'e72b91bb-a690-44fe-9274-6a4a251f611b', + 'token': config.KAIQIUCC_TOKEN, 'XX-Device-Type': 'wxapp', 'content-type': 'application/json', 'Accept-Encoding': 'gzip,compress,br,deflate',