/ clis / nowcoder / referral.js
referral.js
 1  import { cli } from '@jackwener/opencli/registry';
 2  
 3  cli({
 4      site: 'nowcoder',
 5      name: 'referral',
 6      description: 'Internal referral posts',
 7      domain: 'www.nowcoder.com',
 8      args: [
 9          { name: 'page', type: 'int', default: 1, help: 'Page number' },
10          { name: 'limit', type: 'int', default: 15, help: 'Number of items' },
11      ],
12      columns: ['rank', 'title', 'author', 'school', 'likes', 'comments', 'views', 'id'],
13      pipeline: [
14          { navigate: 'https://www.nowcoder.com' },
15          { evaluate: `(async () => {
16    const page = \${{ args.page }};
17    const limit = \${{ args.limit }};
18    const r = await fetch('https://gw-c.nowcoder.com/api/sparta/home/tab/content?tabId=861&categoryType=1&pageNo=' + page + '&pageSize=' + limit, {credentials: 'include'});
19    const d = await r.json();
20    if (!d.success) throw new Error(d.msg || 'API failed');
21    return (d.data?.records || []).map((item, i) => {
22      const content = item.contentData || item.momentData || {};
23      return {
24        rank: i + 1,
25        title: content.title || '',
26        author: item.userBrief?.nickname || '',
27        school: item.userBrief?.educationInfo || '',
28        likes: item.frequencyData?.likeCnt || 0,
29        comments: item.frequencyData?.commentCnt || 0,
30        views: item.frequencyData?.viewCnt || 0,
31        id: item.momentData?.uuid || item.contentData?.uuid || item.contentId || '',
32      };
33    });
34  })()
35  ` },
36          { filter: 'item.title' },
37          { limit: '${{ args.limit }}' },
38      ],
39  });