2026-04-30 21:18:31 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* Command: create-account — 一键创建账号
|
|
|
|
|
|
*
|
2026-05-01 00:44:18 +08:00
|
|
|
|
* 创建目录结构 → 复制参考图 → 上传 OSS → 生成 account.json
|
|
|
|
|
|
* prompt 文件通过 Agent Q&A 流程生成(见 account-creation.md)
|
2026-04-30 21:18:31 +08:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
const fs = require('fs')
|
|
|
|
|
|
const path = require('path')
|
|
|
|
|
|
const { ensureDir, log, ACCOUNTS_DIR } = require('./pipeline-utils')
|
|
|
|
|
|
|
|
|
|
|
|
async function createAccount(args) {
|
2026-05-01 00:44:18 +08:00
|
|
|
|
const { id, name, desc, format, imageModel, videoModel, references, ttsVoice, ttsInstruction } = args
|
2026-04-30 21:18:31 +08:00
|
|
|
|
|
|
|
|
|
|
if (!id) { console.error('错误: 必须指定 --id <账号ID>'); process.exit(1) }
|
|
|
|
|
|
if (!name) { console.error('错误: 必须指定 --name <账号名>'); process.exit(1) }
|
|
|
|
|
|
|
|
|
|
|
|
const accountDir = path.join(ACCOUNTS_DIR, id)
|
|
|
|
|
|
if (fs.existsSync(accountDir)) { console.error(`错误: 账号已存在: ${accountDir}`); process.exit(1) }
|
|
|
|
|
|
|
|
|
|
|
|
ensureDir(accountDir)
|
|
|
|
|
|
ensureDir(path.join(accountDir, 'prompts'))
|
|
|
|
|
|
ensureDir(path.join(accountDir, 'references'))
|
|
|
|
|
|
|
|
|
|
|
|
// 复制参考图到 references/ 并上传 OSS
|
|
|
|
|
|
const refs = (references || '').split(',').filter(Boolean)
|
|
|
|
|
|
const uploadedRefs = []
|
|
|
|
|
|
|
|
|
|
|
|
if (refs.length > 0) {
|
|
|
|
|
|
const { uploadFile } = require('../oss-upload')
|
|
|
|
|
|
for (const refPath of refs) {
|
|
|
|
|
|
const absPath = path.resolve(refPath)
|
|
|
|
|
|
if (!fs.existsSync(absPath)) { console.error(`参考图不存在: ${absPath}`); continue }
|
|
|
|
|
|
const fileName = path.basename(absPath)
|
|
|
|
|
|
const destPath = path.join(accountDir, 'references', fileName)
|
|
|
|
|
|
fs.copyFileSync(absPath, destPath)
|
|
|
|
|
|
try {
|
|
|
|
|
|
const { url } = await uploadFile(destPath)
|
|
|
|
|
|
uploadedRefs.push({ file: fileName, url })
|
|
|
|
|
|
log('account', `参考图 ${fileName} → OK`)
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
uploadedRefs.push({ file: fileName })
|
|
|
|
|
|
log('account', `参考图 ${fileName} 上传失败: ${err.message}(仅保存本地)`)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 生成 account.json
|
|
|
|
|
|
const accountConfig = {
|
|
|
|
|
|
id,
|
|
|
|
|
|
name,
|
|
|
|
|
|
description: desc || '',
|
|
|
|
|
|
defaultFormat: format || '9:16',
|
|
|
|
|
|
imageModel: imageModel || 'gemini',
|
|
|
|
|
|
videoModel: videoModel || '',
|
|
|
|
|
|
batchSize: 30,
|
2026-05-01 00:44:18 +08:00
|
|
|
|
ttsVoice: ttsVoice || '',
|
|
|
|
|
|
ttsInstruction: ttsInstruction || '',
|
2026-04-30 21:18:31 +08:00
|
|
|
|
storyboardPrompt: 'prompts/分镜.md',
|
|
|
|
|
|
imageStylePrompt: 'prompts/图片提示词.md',
|
|
|
|
|
|
videoStylePrompt: 'prompts/视频提示词.md',
|
2026-05-01 00:44:18 +08:00
|
|
|
|
references: uploadedRefs,
|
2026-04-30 21:18:31 +08:00
|
|
|
|
capcut: {
|
|
|
|
|
|
effects: [],
|
|
|
|
|
|
filter: '',
|
|
|
|
|
|
subtitleStyle: {
|
|
|
|
|
|
fontSize: 36,
|
|
|
|
|
|
color: '#FFFFFF',
|
|
|
|
|
|
highlightColor: '#FF6B35',
|
|
|
|
|
|
bold: true,
|
|
|
|
|
|
},
|
|
|
|
|
|
defaultBGM: '',
|
|
|
|
|
|
},
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const accountPath = path.join(accountDir, 'account.json')
|
|
|
|
|
|
fs.writeFileSync(accountPath, JSON.stringify(accountConfig, null, 2), 'utf-8')
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`\n账号已创建: ${accountDir}`)
|
|
|
|
|
|
console.log(` ID: ${id}`)
|
|
|
|
|
|
console.log(` 名称: ${name}`)
|
|
|
|
|
|
console.log(` 模型: ${accountConfig.imageModel} + ${accountConfig.videoModel || '(未指定)'}`)
|
|
|
|
|
|
console.log(` 参考图: ${uploadedRefs.length} 张(${uploadedRefs.filter(r => r.url).length} 已上传)`)
|
2026-05-01 00:44:18 +08:00
|
|
|
|
console.log(`\n下一步: 通过 Agent Q&A 流程生成 prompts/*.md(或手动创建)\n`)
|
2026-04-30 21:18:31 +08:00
|
|
|
|
|
|
|
|
|
|
return accountPath
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = { createAccount }
|