mirror of
https://github.com/foxhui/WebAI2API.git
synced 2026-06-16 21:03:59 +08:00
fix: 修复 Gemini 图片无法上传问题
This commit is contained in:
@@ -2,7 +2,7 @@ import { initBrowserBase } from '../../browser/launcher.js';
|
||||
import {
|
||||
sleep,
|
||||
safeClick,
|
||||
pasteImages
|
||||
uploadFilesViaChooser
|
||||
} from '../../browser/utils.js';
|
||||
import {
|
||||
fillPrompt,
|
||||
@@ -58,23 +58,22 @@ async function generateImage(context, prompt, imgPaths, modelId, meta = {}) {
|
||||
await inputLocator.waitFor({ timeout: 30000 });
|
||||
await sleep(1500, 2500);
|
||||
|
||||
// 2. 上传图片
|
||||
// 2. 上传图片 (使用 filechooser 事件,因为 Firefox 不会创建 DOM input 元素)
|
||||
if (imgPaths && imgPaths.length > 0) {
|
||||
const expectedUploads = imgPaths.length;
|
||||
let uploadedCount = 0;
|
||||
// 点击加号按钮打开菜单
|
||||
logger.debug('适配器', '点击加号按钮...', meta);
|
||||
const uploadMenuBtn = page.getByRole('button', { name: 'Open upload file menu' });
|
||||
await safeClick(page, uploadMenuBtn, { bias: 'button' });
|
||||
await sleep(500, 1000);
|
||||
|
||||
await pasteImages(page, inputLocator, imgPaths, {
|
||||
// 使用公共函数上传文件
|
||||
const uploadFilesBtn = page.getByRole('button', { name: /Upload files/ });
|
||||
await uploadFilesViaChooser(page, uploadFilesBtn, imgPaths, {
|
||||
uploadValidator: (response) => {
|
||||
const url = response.url();
|
||||
// 检测上传成功:google.com/upload/?upload_id= 的 POST 请求
|
||||
if (response.status() === 200 &&
|
||||
return response.status() === 200 &&
|
||||
url.includes('google.com/upload/') &&
|
||||
url.includes('upload_id=')) {
|
||||
uploadedCount++;
|
||||
logger.info('适配器', `图片上传进度: ${uploadedCount}/${expectedUploads}`, meta);
|
||||
return uploadedCount >= expectedUploads;
|
||||
}
|
||||
return false;
|
||||
url.includes('upload_id=');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user