mirror of
https://github.com/LLM-Red-Team/step-free-api.git
synced 2025-10-14 15:11:45 +00:00
增加refresh_token存活检测
This commit is contained in:
31
README.md
31
README.md
@@ -33,6 +33,7 @@ ZhipuAI (智谱清言) 接口转API [glm-free-api](https://github.com/LLM-Red-Te
|
|||||||
* [对话补全](#对话补全)
|
* [对话补全](#对话补全)
|
||||||
* [文档解读](#文档解读)
|
* [文档解读](#文档解读)
|
||||||
* [图像解析](#图像解析)
|
* [图像解析](#图像解析)
|
||||||
|
* [refresh_token存活检测](#refresh_token存活检测)
|
||||||
* [注意事项](#注意事项)
|
* [注意事项](#注意事项)
|
||||||
* [Nginx反代优化](#Nginx反代优化)
|
* [Nginx反代优化](#Nginx反代优化)
|
||||||
|
|
||||||
@@ -52,23 +53,23 @@ https://udify.app/chat/RGqDVPHspgQgGSgf
|
|||||||
|
|
||||||
## 效果示例
|
## 效果示例
|
||||||
|
|
||||||
### 验明正身
|
### 验明正身Demo
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### 多轮对话
|
### 多轮对话Demo
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### 联网搜索
|
### 联网搜索Demo
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### 长文档解读
|
### 长文档解读Demo
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### 图像解析
|
### 图像解析Demo
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@@ -363,6 +364,26 @@ Authorization: Bearer [refresh_token]
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### refresh_token存活检测
|
||||||
|
|
||||||
|
检测refresh_token是否存活,如果存活live未true,否则为false,请不要频繁(小于10分钟)调用此接口。
|
||||||
|
|
||||||
|
**POST /token/check**
|
||||||
|
|
||||||
|
请求数据:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"token": "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9..."
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
响应数据:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"live": true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## 注意事项
|
## 注意事项
|
||||||
|
|
||||||
### Nginx反代优化
|
### Nginx反代优化
|
||||||
|
@@ -838,9 +838,39 @@ function tokenSplit(authorization: string) {
|
|||||||
return authorization.replace("Bearer ", "").split(",");
|
return authorization.replace("Bearer ", "").split(",");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取Token存活状态
|
||||||
|
*/
|
||||||
|
async function getTokenLiveStatus(refreshToken: string) {
|
||||||
|
const result = await axios.post(
|
||||||
|
"https://stepchat.cn/passport/proto.api.passport.v1.PassportService/RegisterDevice",
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Cookie: `Oasis-Token=${refreshToken}`,
|
||||||
|
Referer: "https://stepchat.cn/chats/new",
|
||||||
|
...FAKE_HEADERS,
|
||||||
|
},
|
||||||
|
timeout: 15000,
|
||||||
|
validateStatus: () => true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
try {
|
||||||
|
const {
|
||||||
|
accessToken: { raw: accessTokenRaw },
|
||||||
|
refreshToken: { raw: refreshTokenRaw }
|
||||||
|
} = checkResult(result, refreshToken);
|
||||||
|
return !!(accessTokenRaw && refreshTokenRaw)
|
||||||
|
}
|
||||||
|
catch(err) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
createConversation,
|
createConversation,
|
||||||
createCompletion,
|
createCompletion,
|
||||||
createCompletionStream,
|
createCompletionStream,
|
||||||
|
getTokenLiveStatus,
|
||||||
tokenSplit,
|
tokenSplit,
|
||||||
};
|
};
|
||||||
|
@@ -3,6 +3,7 @@ import fs from 'fs-extra';
|
|||||||
import Response from '@/lib/response/Response.ts';
|
import Response from '@/lib/response/Response.ts';
|
||||||
import chat from "./chat.ts";
|
import chat from "./chat.ts";
|
||||||
import ping from "./ping.ts";
|
import ping from "./ping.ts";
|
||||||
|
import token from './token.ts';
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
{
|
{
|
||||||
@@ -19,5 +20,6 @@ export default [
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
chat,
|
chat,
|
||||||
ping
|
ping,
|
||||||
|
token
|
||||||
];
|
];
|
25
src/api/routes/token.ts
Normal file
25
src/api/routes/token.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
import Request from '@/lib/request/Request.ts';
|
||||||
|
import Response from '@/lib/response/Response.ts';
|
||||||
|
import chat from '@/api/controllers/chat.ts';
|
||||||
|
import logger from '@/lib/logger.ts';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
|
||||||
|
prefix: '/token',
|
||||||
|
|
||||||
|
post: {
|
||||||
|
|
||||||
|
'/check': async (request: Request) => {
|
||||||
|
request
|
||||||
|
.validate('body.token', _.isString)
|
||||||
|
const live = await chat.getTokenLiveStatus(request.body.token);
|
||||||
|
return {
|
||||||
|
live
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user