mirror of
https://github.com/jackwener/OpenCLI.git
synced 2026-09-14 18:25:42 +08:00
d2974a9ff6
* refactor(adapters): convert adapter layer from TypeScript to JavaScript Core framework stays TypeScript; adapter layer moves to JS-first. Adapters are essentially "executable config + browser scripts" that barely use TS features — this simplifies the build/distribution pipeline by removing the dist/clis/ intermediate compilation step. Changes: - Convert all 753 adapter files in clis/ from .ts to .js - Update tsconfig to exclude clis/ from compilation - Simplify build-manifest to scan clis/*.js directly (no dist/clis/) - Update discovery, main, fetch-adapters to load JS adapters from clis/ - Update generate-verified to output .js artifacts - Update package.json files field: dist/clis/ → clis/ - Fix all test files for the .ts → .js transition * fix(main): use findPackageRoot for BUILTIN_CLIS path The previous relative path (../../clis from __dirname) only worked for dist/src/main.js but broke dev mode (tsx src/main.ts) where __dirname is <repo>/src — resolving to /clis instead of <repo>/clis. Use findPackageRoot() which works for both dev and prod paths.
66 lines
2.4 KiB
JavaScript
66 lines
2.4 KiB
JavaScript
/**
|
|
* BOSS直聘 stats — job statistics overview.
|
|
*/
|
|
import { cli, Strategy } from '@jackwener/opencli/registry';
|
|
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 = [];
|
|
try {
|
|
friendList = await fetchFriendList(page);
|
|
}
|
|
catch { /* ignore */ }
|
|
const jobChatCounts = {};
|
|
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) => j.encryptJobId === filterJobId);
|
|
}
|
|
const results = jobs.map((j) => ({
|
|
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;
|
|
},
|
|
});
|