From b4e8b489ec377494609894c6bb2bd30e7324c574 Mon Sep 17 00:00:00 2001 From: Vinlic Date: Wed, 13 Mar 2024 17:31:46 +0800 Subject: [PATCH] =?UTF-8?q?headers=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/controllers/chat.ts | 9 +++++++++ src/index.ts | 1 - src/lib/util.ts | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/api/controllers/chat.ts b/src/api/controllers/chat.ts index a0435a8..2d16630 100644 --- a/src/api/controllers/chat.ts +++ b/src/api/controllers/chat.ts @@ -16,9 +16,18 @@ const MODEL_NAME = 'kimi'; const ACCESS_TOKEN_EXPIRES = 300; // 伪装headers const FAKE_HEADERS = { + 'Accept': '*/*', + 'Accept-Encoding': 'gzip, deflate, br, zstd', + 'Accept-Language': 'zh-CN,zh;q=0.9', + 'Origin': 'https://kimi.moonshot.cn', + 'Cookie': util.generateCookie(), + 'R-Timezone': 'Asia/Shanghai', 'Sec-Ch-Ua': '"Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122"', 'Sec-Ch-Ua-Mobile': '?0', 'Sec-Ch-Ua-Platform': '"Windows"', + 'Sec-Fetch-Dest': 'empty', + 'Sec-Fetch-Mode': 'cors', + 'Sec-Fetch-Site': 'same-origin', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36' }; // 文件最大大小 diff --git a/src/index.ts b/src/index.ts index b5e960e..93ba327 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,6 @@ import "@/lib/initialize.ts"; import server from "@/lib/server.ts"; import routes from "@/api/routes/index.ts"; import logger from "@/lib/logger.ts"; -import util from "@/lib/util.ts"; const startupTime = performance.now(); diff --git a/src/lib/util.ts b/src/lib/util.ts index c15706c..3c143b2 100644 --- a/src/lib/util.ts +++ b/src/lib/util.ts @@ -47,6 +47,20 @@ const util = { return value.headers ? (value.headers["content-type"] || value.headers["Content-Type"]) : null; }, + generateCookie() { + const timestamp = util.unixTimestamp(); + const items = [ + `Hm_lvt_4532beacc312859e0aa3e4a80566b706=${timestamp - Math.round(Math.random() * 2592000)}`, + `Hm_lvt_358cae4815e85d48f7e8ab7f3680a74b=${timestamp - Math.round(Math.random() * 2592000)}`, + `_ga=GA1.1.${util.generateRandomString({ length: 10, charset: 'numeric' })}.${timestamp - Math.round(Math.random() * 2592000)}`, + `_ga_31QPQG2YYD=GS1.1.${timestamp - Math.round(Math.random() * 2592000)}.17.0.${timestamp - Math.round(Math.random() * 2592000)}.0.0.0`, + `Hm_lpvt_4532beacc312859e0aa3e4a80566b706=${timestamp - Math.round(Math.random() * 2592000)}`, + `Hm_lpvt_358cae4815e85d48f7e8ab7f3680a74b=${timestamp - Math.round(Math.random() * 2592000)}`, + `_ga_YXD8W70SZP=GS1.1.${timestamp - Math.round(Math.random() * 2592000)}.35.1.${timestamp - Math.round(Math.random() * 2592000)}.0.0.0` + ]; + return items.join('; '); + }, + mimeToExtension(value: string) { let extension = mime.getExtension(value); if(extension == "mpga")