Commit 31be2438 authored by 郭阔's avatar 郭阔

feat: site-level login recipes shared across channels

- login-tools: loadRecipe falls back to site recipe (logins/<site>.json);
  discover writes site-level recipe so nikkei-* channels share one recipe
- rename recipes to site names: nikkei.json, digitimes.json (ft.json already)
parent c5612a4c
{
"checkUrl": "https://www.ft.com/news-feed",
"loggedOutText": "Sign In",
"steps": [
{
"click": {
"text": "Sign In"
}
},
{
"fill": {
"#enter-email": "$USER"
},
"submit": "button[type=submit], form input[type=submit]"
},
{
"fill": {
"input[type=password]": "$PASS"
},
"submit": "button[type=submit], form input[type=submit]",
"waitMs": 8000
}
]
}
...@@ -50,10 +50,18 @@ function cdpPort() { ...@@ -50,10 +50,18 @@ function cdpPort() {
return 9222; return 9222;
} }
function siteOf(source) {
// 站点 = 源名第一段:nikkei-world/markets/tech → nikkei;单段源(wsj/ft)即自身
return String(source).split('-')[0];
}
function loadRecipe(source) { function loadRecipe(source) {
const p = path.join(ROOT, 'logins', `${source}.json`); // 先源级配方,再站点级(logins/nikkei.json 对全部 nikkei-* 频道生效)
if (!fs.existsSync(p)) return null; for (const name of [source, siteOf(source)]) {
return JSON.parse(fs.readFileSync(p, 'utf8')); const p = path.join(ROOT, 'logins', `${name}.json`);
if (fs.existsSync(p)) return JSON.parse(fs.readFileSync(p, 'utf8'));
}
return null;
} }
const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
...@@ -264,8 +272,9 @@ async function discover(source, doLogin) { ...@@ -264,8 +272,9 @@ async function discover(source, doLogin) {
steps, steps,
}; };
fs.mkdirSync(path.join(ROOT, 'logins'), { recursive: true }); fs.mkdirSync(path.join(ROOT, 'logins'), { recursive: true });
fs.writeFileSync(path.join(ROOT, 'logins', `${source}.json`), JSON.stringify(recipe, null, 2) + '\n'); // 配方写站点级(nikkei.json),同站全部频道共享;源级文件仍可手工覆盖
console.log(`⑥ 配方已写入 logins/${source}.json`); fs.writeFileSync(path.join(ROOT, 'logins', `${siteOf(source)}.json`), JSON.stringify(recipe, null, 2) + '\n');
console.log(`⑥ 配方已写入 logins/${siteOf(source)}.json(站点级,覆盖 ${siteOf(source)}-* 全部频道)`);
if (!doLogin) { console.log('⑦ --no-login:跳过实登验证'); process.exit(0); } if (!doLogin) { console.log('⑦ --no-login:跳过实登验证'); process.exit(0); }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment