Skip to content

Commit a228758

Browse files
authored
refactor: replace hardcoded skipPreNav with declarative navigateBefore field (#208)
Browser adapters using COOKIE/HEADER strategy need the page on the target domain so credentialed fetch() carries cookies. Previously, execution.ts hardcoded `cmd.site === 'boss'` to skip this pre-navigation for adapters that handle their own goto(). Now each adapter self-declares via `navigateBefore: false` on CliCommand. This is more extensible — new sites that manage their own navigation just add the field instead of editing execution.ts. Changes: - Add `navigateBefore?: boolean | string` to CliCommand interface - Add `resolvePreNav()` helper in execution.ts (replaces hardcoded check) - All 14 boss adapters declare `navigateBefore: false` - Wire through discovery.ts (YAML + manifest) and build-manifest.ts
1 parent ae30763 commit a228758

File tree

18 files changed

+59
-8
lines changed

18 files changed

+59
-8
lines changed

src/build-manifest.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ interface ManifestEntry {
4141
type: 'yaml' | 'ts';
4242
/** Relative path from clis/ dir, e.g. 'bilibili/hot.yaml' or 'bilibili/search.js' */
4343
modulePath?: string;
44+
/** Pre-navigation control — see CliCommand.navigateBefore */
45+
navigateBefore?: boolean | string;
4446
}
4547

4648
function extractBalancedBlock(
@@ -189,6 +191,7 @@ function scanYaml(filePath: string, site: string): ManifestEntry | null {
189191
pipeline: def.pipeline,
190192
timeout: def.timeout,
191193
type: 'yaml',
194+
navigateBefore: def.navigateBefore,
192195
};
193196
} catch (err: any) {
194197
process.stderr.write(`Warning: failed to parse ${filePath}: ${err.message}\n`);
@@ -248,6 +251,10 @@ function scanTs(filePath: string, site: string): ManifestEntry | null {
248251
entry.args = parseTsArgsBlock(argsBlock);
249252
}
250253

254+
// Extract navigateBefore: false
255+
const navMatch = src.match(/navigateBefore\s*:\s*(true|false)/);
256+
if (navMatch) entry.navigateBefore = navMatch[1] === 'true' ? true : false;
257+
251258
return entry;
252259
} catch (err: any) {
253260
// If parsing fails, log a warning (matching scanYaml behaviour) and skip the entry.

src/clis/boss/batchgreet.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ cli({
1313
description: 'BOSS直聘批量向推荐候选人发送招呼',
1414
domain: 'www.zhipin.com',
1515
strategy: Strategy.COOKIE,
16+
navigateBefore: false,
1617
browser: true,
1718
args: [
1819
{ name: 'job-id', default: '', help: 'Filter by encrypted job ID (greet all jobs if empty)' },

src/clis/boss/chatlist.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ cli({
77
description: 'BOSS直聘查看聊天列表(招聘端)',
88
domain: 'www.zhipin.com',
99
strategy: Strategy.COOKIE,
10+
navigateBefore: false,
1011
browser: true,
1112
args: [
1213
{ name: 'page', type: 'int', default: 1, help: 'Page number' },

src/clis/boss/chatmsg.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ cli({
77
description: 'BOSS直聘查看与候选人的聊天消息',
88
domain: 'www.zhipin.com',
99
strategy: Strategy.COOKIE,
10+
navigateBefore: false,
1011
browser: true,
1112
args: [
1213
{ name: 'uid', required: true, help: 'Encrypted UID (from chatlist)' },

src/clis/boss/detail.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ cli({
1010
description: 'BOSS直聘查看职位详情',
1111
domain: 'www.zhipin.com',
1212
strategy: Strategy.COOKIE,
13+
navigateBefore: false,
1314
browser: true,
1415
args: [
1516
{ name: 'security-id', required: true, help: 'Security ID from search results (securityId field)' },

src/clis/boss/exchange.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ cli({
1010
description: 'BOSS直聘交换联系方式(请求手机/微信)',
1111
domain: 'www.zhipin.com',
1212
strategy: Strategy.COOKIE,
13+
navigateBefore: false,
1314
browser: true,
1415
args: [
1516
{ name: 'uid', required: true, help: 'Encrypted UID of the candidate' },

src/clis/boss/greet.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ cli({
1313
description: 'BOSS直聘向新候选人发送招呼(开始聊天)',
1414
domain: 'www.zhipin.com',
1515
strategy: Strategy.COOKIE,
16+
navigateBefore: false,
1617
browser: true,
1718
args: [
1819
{ name: 'uid', required: true, help: 'Encrypted UID of the candidate (from recommend)' },

src/clis/boss/invite.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ cli({
1010
description: 'BOSS直聘发送面试邀请',
1111
domain: 'www.zhipin.com',
1212
strategy: Strategy.COOKIE,
13+
navigateBefore: false,
1314
browser: true,
1415
args: [
1516
{ name: 'uid', required: true, help: 'Encrypted UID of the candidate' },

src/clis/boss/joblist.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ cli({
1010
description: 'BOSS直聘查看我发布的职位列表',
1111
domain: 'www.zhipin.com',
1212
strategy: Strategy.COOKIE,
13+
navigateBefore: false,
1314
browser: true,
1415
args: [],
1516
columns: ['job_name', 'salary', 'city', 'status', 'encrypt_job_id'],

src/clis/boss/mark.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ cli({
1919
description: 'BOSS直聘给候选人添加标签',
2020
domain: 'www.zhipin.com',
2121
strategy: Strategy.COOKIE,
22+
navigateBefore: false,
2223
browser: true,
2324
args: [
2425
{ name: 'uid', required: true, help: 'Encrypted UID of the candidate' },

0 commit comments

Comments
 (0)