Files
jackwener__opencli/clis/weibo/feed.ts
jackwener 314bc6f231 refactor: simplify core modules — remove root shims, consolidate error classification, streamline cascade/interceptor, clean up synthesize
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>
2026-04-05 03:06:47 +08:00

58 lines
2.2 KiB
TypeScript

/**
* Weibo feed — home timeline from followed users.
*/
import { cli, Strategy } from '../../src/registry.js';
import { getSelfUid } from './utils.js';
cli({
site: 'weibo',
name: 'feed',
description: 'Weibo home timeline (posts from followed users)',
domain: 'weibo.com',
strategy: Strategy.COOKIE,
args: [
{ name: 'limit', type: 'int', default: 15, help: 'Number of posts (max 50)' },
],
columns: ['author', 'text', 'reposts', 'comments', 'likes', 'time', 'url'],
func: async (page, kwargs) => {
const count = Math.min(kwargs.limit || 15, 50);
await page.goto('https://weibo.com');
await page.wait(2);
const uid = await getSelfUid(page);
const data = await page.evaluate(`
(async () => {
const uid = ${JSON.stringify(uid)};
const count = ${count};
const listId = '10001' + uid;
const strip = (html) => (html || '').replace(/<[^>]+>/g, '').replace(/&nbsp;/g, ' ').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&amp;/g, '&').trim();
const resp = await fetch('/ajax/feed/unreadfriendstimeline?list_id=' + listId + '&refresh=4&since_id=0&count=' + count, {credentials: 'include'});
if (!resp.ok) return {error: 'HTTP ' + resp.status};
const data = await resp.json();
if (!data.ok) return {error: 'API error: ' + (data.msg || 'unknown')};
return (data.statuses || []).slice(0, count).map(s => {
const u = s.user || {};
const item = {
author: u.screen_name || '',
text: (s.text_raw || strip(s.text || '')).substring(0, 200),
reposts: s.reposts_count || 0,
comments: s.comments_count || 0,
likes: s.attitudes_count || 0,
time: s.created_at || '',
url: 'https://weibo.com/' + (u.id || '') + '/' + (s.mblogid || ''),
};
if (s.retweeted_status) {
const rt = s.retweeted_status;
item.retweeted = (rt.user?.screen_name || '[deleted]') + ': ' + (rt.text_raw || strip(rt.text || '')).substring(0, 100);
}
return item;
});
})()
`);
if (!Array.isArray(data)) return [];
return data;
},
});