mirror of
https://github.com/jackwener/OpenCLI.git
synced 2026-09-14 18:25:42 +08:00
314bc6f231
1. Remove root-level shim files (errors.ts, logger.ts, registry.ts, types.ts, utils.ts, launcher.ts) — update all ~840 adapter imports to reference src/ directly 2. Consolidate interceptor: reuse shared DISGUISE_FN in tap interceptor instead of reimplementing 3. Unify error classification: single ClassifiedError type with icon/exitCode/hint lookup table, eliminating duplicated pattern matching between resolveExitCode and renderError 4. Simplify cascade probe: replace repetitive switch cases with PROBE_OPTIONS lookup map 12. Clean up synthesize.ts: remove deprecated snake_case field aliases (recommended_args, recommended_columns, recommendedColumnsLegacy) and unnecessary constant aliases Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
76 lines
2.2 KiB
TypeScript
76 lines
2.2 KiB
TypeScript
/**
|
|
* BOSS直聘 stats — job statistics overview.
|
|
*/
|
|
import { cli, Strategy } from '../../src/registry.js';
|
|
import { requirePage, navigateToChat, bossFetch, fetchFriendList, verbose } from './utils.js';
|
|
|
|
cli({
|
|
site: 'boss',
|
|
name: 'stats',
|
|
description: 'BOSS直聘职位数据统计',
|
|
domain: 'www.zhipin.com',
|
|
strategy: Strategy.COOKIE,
|
|
navigateBefore: false,
|
|
browser: true,
|
|
args: [
|
|
{ name: 'job-id', default: '', help: 'Encrypted job ID (show all if empty)' },
|
|
],
|
|
columns: ['job_name', 'salary', 'city', 'status', 'total_chats', 'encrypt_job_id'],
|
|
func: async (page, kwargs) => {
|
|
requirePage(page);
|
|
verbose('Fetching job statistics...');
|
|
|
|
const filterJobId = kwargs['job-id'] || '';
|
|
|
|
await navigateToChat(page);
|
|
|
|
// Get job list
|
|
const jobData = await bossFetch(page, 'https://www.zhipin.com/wapi/zpjob/job/chatted/jobList');
|
|
|
|
// Get total chat stats (non-critical, allow failure)
|
|
const chatStats = await bossFetch(page, 'https://www.zhipin.com/wapi/zpchat/chatHelper/statistics', {
|
|
allowNonZero: true,
|
|
});
|
|
const totalFriends = chatStats.zpData?.totalFriendCount || 0;
|
|
|
|
// Get per-job chat counts from friend list (non-critical)
|
|
let friendList: any[] = [];
|
|
try {
|
|
friendList = await fetchFriendList(page);
|
|
} catch { /* ignore */ }
|
|
|
|
const jobChatCounts: Record<string, number> = {};
|
|
for (const f of friendList) {
|
|
const jobName = f.jobName || 'unknown';
|
|
jobChatCounts[jobName] = (jobChatCounts[jobName] || 0) + 1;
|
|
}
|
|
|
|
let jobs = jobData.zpData || [];
|
|
if (filterJobId) {
|
|
jobs = jobs.filter((j: any) => j.encryptJobId === filterJobId);
|
|
}
|
|
|
|
const results = jobs.map((j: any) => ({
|
|
job_name: j.jobName || '',
|
|
salary: j.salaryDesc || '',
|
|
city: j.address || '',
|
|
status: j.jobOnlineStatus === 1 ? '在线' : '已关闭',
|
|
total_chats: String(jobChatCounts[j.jobName] || 0),
|
|
encrypt_job_id: j.encryptJobId || '',
|
|
}));
|
|
|
|
if (!filterJobId && results.length > 0) {
|
|
results.push({
|
|
job_name: '--- 总计 ---',
|
|
salary: '',
|
|
city: '',
|
|
status: `${jobs.length} 个职位`,
|
|
total_chats: String(totalFriends),
|
|
encrypt_job_id: '',
|
|
});
|
|
}
|
|
|
|
return results;
|
|
},
|
|
});
|