mirror of
https://github.com/foxhui/WebAI2API.git
synced 2026-06-16 21:03:59 +08:00
feat: 添加 Cookie 获取功能
This commit is contained in:
@@ -5,6 +5,23 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [2.2.1] - 2025-12-12
|
||||
|
||||
### Added
|
||||
- **Cookie获取**
|
||||
- 增加 Cookie 获取接口,可利用本项目的自动续登功能获取最新的 Cookie 给其他工具使用
|
||||
|
||||
### Changed
|
||||
- **自动续登**
|
||||
- 监听逻辑修改为全局监听,任何时候触发跳转都会执行自动登录(如会话过期自动跳转)
|
||||
|
||||
### Fixed
|
||||
- **修复杂项**
|
||||
- 修复自动登录时可能会出现的问题
|
||||
- 修复启动VNC服务器时端口可能冲突的问题
|
||||
- 修复遗留的浏览器启动参数导致的小问题
|
||||
- 修复 zAI 返回错误时无反馈直到请求超时的问题
|
||||
|
||||
## [2.2.0] - 2025-12-11
|
||||
|
||||
### Added
|
||||
|
||||
@@ -226,7 +226,56 @@ curl -X GET http://127.0.0.1:3000/v1/models \
|
||||
|
||||
</details>
|
||||
|
||||
#### 3. 多模态请求 (图生图/图生文)
|
||||
#### 3. 获取Cookies
|
||||
|
||||
**功能说明**:可利用本项目的自动续登功能获取最新Cookie给其他工具使用。
|
||||
|
||||
**请求端点**
|
||||
```
|
||||
GET http://127.0.0.1:3000/v1/cookies
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>📄 查看API请求示例</summary>
|
||||
|
||||
**请求示例**
|
||||
```bash
|
||||
curl -X GET http://127.0.0.1:3000/v1/cookies \
|
||||
-H "Authorization: Bearer your-secret-key"
|
||||
```
|
||||
|
||||
**响应格式**
|
||||
```json
|
||||
{
|
||||
"cookies": [
|
||||
{
|
||||
"name": "_GRECAPTCHA",
|
||||
"value": "09ADxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
||||
"domain": "www.google.com",
|
||||
"path": "/recaptcha",
|
||||
"expires": 1780000000,
|
||||
"httpOnly": true,
|
||||
"secure": true,
|
||||
"sameSite": "None"
|
||||
},
|
||||
{
|
||||
"name": "OTZ",
|
||||
"value": "8888888_24_24__24_",
|
||||
"domain": "accounts.google.com",
|
||||
"path": "/",
|
||||
"expires": 1760000000,
|
||||
"httpOnly": false,
|
||||
"secure": true,
|
||||
"sameSite": "None"
|
||||
}
|
||||
.......... more
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
#### 4. 多模态请求 (图生图/图生文)
|
||||
|
||||
**功能说明**:支持在消息中附带图片进行对话或生成。
|
||||
|
||||
|
||||
@@ -434,3 +434,14 @@ export function createPageCloseWatcher(page) {
|
||||
|
||||
return { promise, cleanup };
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前页面的所有 Cookies (实时从浏览器获取)
|
||||
* @param {import('playwright-core').Page} page - Playwright 页面实例
|
||||
* @returns {Promise<object[]>} Cookies 数组 (JSON 格式)
|
||||
*/
|
||||
export async function getCookies(page) {
|
||||
const context = page.context();
|
||||
return await context.cookies();
|
||||
}
|
||||
|
||||
|
||||
@@ -414,7 +414,27 @@ async function startServer() {
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 聊天补全接口
|
||||
// 2. 获取 Cookies 接口
|
||||
if (req.method === 'GET' && req.url === '/v1/cookies') {
|
||||
try {
|
||||
if (!browserContext || !browserContext.page) {
|
||||
res.writeHead(503, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({ error: 'Browser not initialized' }));
|
||||
return;
|
||||
}
|
||||
const context = browserContext.page.context();
|
||||
const cookies = await context.cookies();
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({ cookies }));
|
||||
} catch (err) {
|
||||
logger.error('服务器', '获取 Cookies 失败', { id, error: err.message });
|
||||
res.writeHead(500, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({ error: err.message }));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. 聊天补全接口
|
||||
if (req.method === 'POST' && req.url.startsWith('/v1/chat/completions')) {
|
||||
const chunks = [];
|
||||
req.on('data', chunk => chunks.push(chunk));
|
||||
|
||||
Reference in New Issue
Block a user