feat(baoyu-post-to-wechat): add multi-account support

Support multiple WeChat Official Accounts via EXTEND.md accounts block.
Each account gets isolated Chrome profile, credential resolution chain
(inline → prefixed env → unprefixed env), and --account CLI arg.
This commit is contained in:
Jim Liu 宝玉
2026-03-11 23:24:02 -05:00
parent c0941f8089
commit 5276fae6bd
9 changed files with 531 additions and 55 deletions
@@ -7,9 +7,11 @@ import {
CdpConnection,
findChromeExecutable,
getDefaultProfileDir,
getAccountProfileDir,
launchChrome,
sleep,
} from './cdp.ts';
import { loadWechatExtendConfig, resolveAccount } from './wechat-extend-config.ts';
const WECHAT_URL = 'https://mp.weixin.qq.com/';
@@ -664,6 +666,7 @@ Options:
--image <path> Add image (can be repeated)
--submit Save as draft (default: preview only)
--profile <dir> Chrome profile directory
--account <alias> Select account by alias (for multi-account setups)
--help Show this help
Examples:
@@ -685,6 +688,7 @@ async function main(): Promise<void> {
let content: string | undefined;
let markdownFile: string | undefined;
let imagesDir: string | undefined;
let accountAlias: string | undefined;
for (let i = 0; i < args.length; i++) {
const arg = args[i]!;
@@ -702,9 +706,19 @@ async function main(): Promise<void> {
submit = true;
} else if (arg === '--profile' && args[i + 1]) {
profileDir = args[++i];
} else if (arg === '--account' && args[i + 1]) {
accountAlias = args[++i];
}
}
const extConfig = loadWechatExtendConfig();
const resolved = resolveAccount(extConfig, accountAlias);
if (resolved.name) console.log(`[wechat-browser] Account: ${resolved.name} (${resolved.alias})`);
if (!profileDir && resolved.alias) {
profileDir = resolved.chrome_profile_path || getAccountProfileDir(resolved.alias);
}
if (!markdownFile && !title) {
console.error('Error: --title or --markdown is required');
process.exit(1);