feat: --chatUrl 不加 --prompt 时直接下载已有图片,跳过生成步骤
This commit is contained in:
@@ -80,6 +80,16 @@ $NODE $CLI generate --session <id> --prompt "最终调整" --mode single
|
|||||||
$NODE $CLI generate --chatUrl "https://gemini.google.com/app/xxxx" --prompt "换成水彩风格"
|
$NODE $CLI generate --chatUrl "https://gemini.google.com/app/xxxx" --prompt "换成水彩风格"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 仅下载已有图片(不生成新图)
|
||||||
|
|
||||||
|
打开已有生图对话,直接下载所有已生成的图片,不发送新提示词:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$NODE $CLI generate --chatUrl "https://gemini.google.com/app/xxxx" --mode single
|
||||||
|
```
|
||||||
|
|
||||||
|
不加 `--prompt` 即进入纯下载模式,自动下载对话中所有已生成图片后关闭标签页。
|
||||||
|
|
||||||
### 状态与诊断
|
### 状态与诊断
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
@@ -225,6 +225,9 @@ close 参数:
|
|||||||
# 通过之前的对话链接继续生图
|
# 通过之前的对话链接继续生图
|
||||||
node cli.js generate --chatUrl "https://gemini.google.com/app/4c089f364e1cf745" --prompt "换成晚上场景"
|
node cli.js generate --chatUrl "https://gemini.google.com/app/4c089f364e1cf745" --prompt "换成晚上场景"
|
||||||
|
|
||||||
|
# 仅下载已有图片(chatUrl 不加 --prompt,直接下载)
|
||||||
|
node cli.js generate --chatUrl "https://gemini.google.com/app/4c089f364e1cf745" --mode single
|
||||||
|
|
||||||
环境变量:
|
环境变量:
|
||||||
CDP_URL Chrome DevTools Protocol 连接地址(默认 http://127.0.0.1:9222)
|
CDP_URL Chrome DevTools Protocol 连接地址(默认 http://127.0.0.1:9222)
|
||||||
`.trim();
|
`.trim();
|
||||||
@@ -289,7 +292,12 @@ close 参数:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!prompt) {
|
if (!prompt) {
|
||||||
error('--prompt is required');
|
if (args.chatUrl) {
|
||||||
|
// --chatUrl without --prompt: enter download-only mode
|
||||||
|
isDownloadOnly = true;
|
||||||
|
} else {
|
||||||
|
error('--prompt is required');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Support --images path1,path2,... or --image single
|
// Support --images path1,path2,... or --image single
|
||||||
@@ -351,6 +359,58 @@ close 参数:
|
|||||||
emit('progress', { step: 'login', message: `Logged in as: ${loginStatus.account}` });
|
emit('progress', { step: 'login', message: `Logged in as: ${loginStatus.account}` });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Download-only mode: --chatUrl without --prompt, download existing images directly
|
||||||
|
if (isDownloadOnly) {
|
||||||
|
emit('progress', { step: 'download', message: 'Download-only mode: downloading existing images...' });
|
||||||
|
|
||||||
|
// Wait a moment for the page to fully load embedded images
|
||||||
|
await sleep(3000);
|
||||||
|
|
||||||
|
// Count visible download buttons
|
||||||
|
const btnCount = await page.evaluate(() => {
|
||||||
|
const buttons = document.querySelectorAll('button.generated-image-button');
|
||||||
|
return Array.from(buttons).filter(b => b.offsetParent !== null).length;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (btnCount === 0) {
|
||||||
|
emit('error', {
|
||||||
|
message: 'No existing images found to download on this page.',
|
||||||
|
sessionId: sid,
|
||||||
|
status: 'no_images',
|
||||||
|
});
|
||||||
|
if (mode === 'single') await closeSession(sid);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
emit('progress', { step: 'download', message: `Found ${btnCount} download button(s), downloading all...` });
|
||||||
|
|
||||||
|
try {
|
||||||
|
const downloadTimeout = parseInt(args.downloadTimeout, 10) || 120000;
|
||||||
|
const downloaded = await downloadViaButtons(page, cdp, {
|
||||||
|
existingButtonCount: 0,
|
||||||
|
timeout: downloadTimeout,
|
||||||
|
});
|
||||||
|
|
||||||
|
const chatUrl = await captureChatUrl(sid, page);
|
||||||
|
|
||||||
|
emit('success', {
|
||||||
|
sessionId: sid,
|
||||||
|
chatUrl,
|
||||||
|
mode,
|
||||||
|
images: downloaded.map(i => i.path),
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
emit('error', {
|
||||||
|
message: `Download failed: ${e.message}`,
|
||||||
|
sessionId: sid,
|
||||||
|
status: 'download_failed',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode === 'single') await closeSession(sid);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// generate() handles its own progress events
|
// generate() handles its own progress events
|
||||||
const genStartTime = Date.now();
|
const genStartTime = Date.now();
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "gemini-web-cli",
|
"name": "gemini-web-generate",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "CLI tool for AI image generation and session management via Gemini web interface",
|
"description": "Gemini 网页版 AI 生图 CLI — Puppeteer 驱动的全自动生图脚本",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "cli.js",
|
"main": "cli.js",
|
||||||
"scripts": {
|
|
||||||
"generate": "node cli.js generate",
|
|
||||||
"download": "node cli.js download",
|
|
||||||
"status": "node cli.js status"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"puppeteer-core": "^24.0.0"
|
"puppeteer-core": "^24.0.0"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user