Skip to content

Commit d97a629

Browse files
committed
添加更多请求头参数
1 parent eb187ad commit d97a629

4 files changed

Lines changed: 41 additions & 37 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "qwen2api",
3-
"version": "2025.10.01.08.45",
3+
"version": "2025.10.11.15.10",
44
"main": "src/server.js",
55
"scripts": {
66
"start": "node src/start.js",

src/config/index.js

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,38 @@ dotenv.config()
66
* @returns {Object} 包含apiKeys数组和adminKey的对象
77
*/
88
const parseApiKeys = () => {
9-
const apiKeyEnv = process.env.API_KEY
10-
if (!apiKeyEnv) {
11-
return { apiKeys: [], adminKey: null }
12-
}
9+
const apiKeyEnv = process.env.API_KEY
10+
if (!apiKeyEnv) {
11+
return { apiKeys: [], adminKey: null }
12+
}
1313

14-
const keys = apiKeyEnv.split(',').map(key => key.trim()).filter(key => key.length > 0)
15-
return {
16-
apiKeys: keys,
17-
adminKey: keys.length > 0 ? keys[0] : null
18-
}
14+
const keys = apiKeyEnv.split(',').map(key => key.trim()).filter(key => key.length > 0)
15+
return {
16+
apiKeys: keys,
17+
adminKey: keys.length > 0 ? keys[0] : null
18+
}
1919
}
2020

2121
const { apiKeys, adminKey } = parseApiKeys()
2222

2323
const config = {
24-
dataSaveMode: process.env.DATA_SAVE_MODE || "none",
25-
apiKeys: apiKeys,
26-
adminKey: adminKey,
27-
simpleModelMap: process.env.SIMPLE_MODEL_MAP === 'true' ? true : false,
28-
listenAddress: process.env.LISTEN_ADDRESS || null,
29-
listenPort: process.env.SERVICE_PORT || 3000,
30-
searchInfoMode: process.env.SEARCH_INFO_MODE === 'table' ? "table" : "text",
31-
outThink: process.env.OUTPUT_THINK === 'true' ? true : false,
32-
redisURL: process.env.REDIS_URL || null,
33-
autoRefresh: true,
34-
autoRefreshInterval: 6 * 60 * 60,
35-
cacheMode: process.env.CACHE_MODE || "default",
36-
logLevel: process.env.LOG_LEVEL || "INFO",
37-
enableFileLog: process.env.ENABLE_FILE_LOG === 'true',
38-
logDir: process.env.LOG_DIR || "./logs",
39-
maxLogFileSize: parseInt(process.env.MAX_LOG_FILE_SIZE) || 10,
40-
maxLogFiles: parseInt(process.env.MAX_LOG_FILES) || 5,
41-
ssxmodItna: process.env.SSXMOD_ITNA || "mqUxRDBDnD00I4eKYIxAK0QD2W3nDAQDRDl4Bti=GgexFqAPqDHI63vYWtiiY0DjOxqbVji84D/I7eGzDiMPGhDBeEHzKtg5xKFIWrEx4qICCGxK3OGYZeqK0Ge2Nq3vwn0XX3NyzZiPYxGLDY=DCqqqYorbDYAEDBYD74G+DDeDixGmQeDSDxD9DGPdglTi2eDEDYPdxA3Di4D+jebDmd4DGuo4x7QaRmxD0ux58mDz8aF46PmzMeqOVRbDjTPD/R+LO0RC2FkKYa9AV8amGeGyi5GuDPmb=jHORnniHpeY0d0hbGedW4qTBq=DYx+DP24FGDBirCht5B5QYipOYameDD3bWD+GNbADKpt9gtBoNbGGwiDmmIafRPx2Uem2i44Gb1mGz0pNlqV=Gxlqk8xP2DxD"
24+
dataSaveMode: process.env.DATA_SAVE_MODE || "none",
25+
apiKeys: apiKeys,
26+
adminKey: adminKey,
27+
simpleModelMap: process.env.SIMPLE_MODEL_MAP === 'true' ? true : false,
28+
listenAddress: process.env.LISTEN_ADDRESS || null,
29+
listenPort: process.env.SERVICE_PORT || 3000,
30+
searchInfoMode: process.env.SEARCH_INFO_MODE === 'table' ? "table" : "text",
31+
outThink: process.env.OUTPUT_THINK === 'true' ? true : false,
32+
redisURL: process.env.REDIS_URL || null,
33+
autoRefresh: true,
34+
autoRefreshInterval: 6 * 60 * 60,
35+
cacheMode: process.env.CACHE_MODE || "default",
36+
logLevel: process.env.LOG_LEVEL || "INFO",
37+
enableFileLog: process.env.ENABLE_FILE_LOG === 'true',
38+
logDir: process.env.LOG_DIR || "./logs",
39+
maxLogFileSize: parseInt(process.env.MAX_LOG_FILE_SIZE) || 10,
40+
maxLogFiles: parseInt(process.env.MAX_LOG_FILES) || 5,
4241
}
4342

4443
module.exports = config

src/middlewares/chat-middleware.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const processRequestBody = async (req, res, next) => {
1616
"model": "qwen3-235b-a22b",
1717
"messages": [],
1818
"session_id": generateUUID(),
19-
"chat_id": generateUUID(),
2019
"id": generateUUID(),
2120
"sub_chat_type": "t2t",
2221
"chat_mode": "normal"

src/utils/request.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ const sendChatRequest = async (body) => {
2727
// 构建请求配置
2828
const requestConfig = {
2929
headers: {
30-
'Authorization': `Bearer ${currentToken}`,
30+
'authorization': `Bearer ${currentToken}`,
3131
'Content-Type': 'application/json',
32-
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
33-
...(config.ssxmodItna && { 'Cookie': `ssxmod_itna=${config.ssxmodItna}` })
32+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36 Edg/141.0.0.0',
33+
"Connection": "keep-alive",
34+
"Accept": "*/*",
35+
"Accept-Encoding": "gzip, deflate, br",
3436
},
3537
responseType: body.stream ? 'stream' : 'json',
3638
timeout: 60 * 1000,
@@ -39,7 +41,7 @@ const sendChatRequest = async (body) => {
3941
// console.log(body)
4042
// console.log(requestConfig)
4143

42-
const chat_id = await generateChatID(currentToken,body.model)
44+
const chat_id = await generateChatID(currentToken, body.model)
4345

4446
logger.network(`发送聊天请求`, 'REQUEST')
4547
const response = await axios.post("https://chat.qwen.ai/api/v2/chat/completions?chat_id=" + chat_id, {
@@ -49,7 +51,7 @@ const sendChatRequest = async (body) => {
4951

5052
// 请求成功
5153
if (response.status === 200) {
52-
// console.log(JSON.stringify(response.data))
54+
// console.log(response.data)
5355
return {
5456
currentToken: currentToken,
5557
status: true,
@@ -72,7 +74,7 @@ const sendChatRequest = async (body) => {
7274
* @param {*} currentToken
7375
* @returns {Promise<string|null>} 返回生成的chat_id,如果失败则返回null
7476
*/
75-
const generateChatID = async (currentToken,model) => {
77+
const generateChatID = async (currentToken, model) => {
7678
try {
7779
const response_data = await axios.post("https://chat.qwen.ai/api/v2/chats/new", {
7880
"title": "New Chat",
@@ -86,11 +88,15 @@ const generateChatID = async (currentToken,model) => {
8688
headers: {
8789
'Authorization': `Bearer ${currentToken}`,
8890
'Content-Type': 'application/json',
89-
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
90-
...(config.ssxmodItna && { 'Cookie': `ssxmod_itna=${config.ssxmodItna}` })
91+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36 Edg/141.0.0.0',
92+
"Connection": "keep-alive",
93+
"Accept": "*/*",
94+
"Accept-Encoding": "gzip, deflate, br"
9195
}
9296
})
9397

98+
// console.log(response_data.data)
99+
94100
return response_data.data?.data?.id || null
95101

96102
} catch (error) {

0 commit comments

Comments
 (0)