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.
64 lines
2.4 KiB
JavaScript
64 lines
2.4 KiB
JavaScript
/**
|
|
* Weibo user — get user profile by uid or screen_name.
|
|
*/
|
|
import { cli, Strategy } from '@jackwener/opencli/registry';
|
|
import { CommandExecutionError } from '@jackwener/opencli/errors';
|
|
cli({
|
|
site: 'weibo',
|
|
name: 'user',
|
|
description: 'Get Weibo user profile',
|
|
domain: 'weibo.com',
|
|
strategy: Strategy.COOKIE,
|
|
args: [
|
|
{ name: 'id', required: true, positional: true, help: 'User ID (numeric uid) or screen name' },
|
|
],
|
|
columns: ['screen_name', 'uid', 'followers', 'following', 'statuses', 'verified', 'description', 'location', 'url'],
|
|
func: async (page, kwargs) => {
|
|
await page.goto('https://weibo.com');
|
|
await page.wait(2);
|
|
const id = String(kwargs.id);
|
|
const data = await page.evaluate(`
|
|
(async () => {
|
|
const id = ${JSON.stringify(id)};
|
|
const isUid = /^\\d+$/.test(id);
|
|
const query = isUid ? 'uid=' + id : 'screen_name=' + encodeURIComponent(id);
|
|
|
|
const resp = await fetch('/ajax/profile/info?' + query, {credentials: 'include'});
|
|
if (!resp.ok) return {error: 'HTTP ' + resp.status};
|
|
const data = await resp.json();
|
|
if (!data.ok || !data.data?.user) return {error: 'User not found'};
|
|
|
|
const u = data.data.user;
|
|
|
|
// Fetch detail info
|
|
const detailResp = await fetch('/ajax/profile/detail?uid=' + u.id, {credentials: 'include'});
|
|
const detail = detailResp.ok ? await detailResp.json() : null;
|
|
const d = detail?.data || {};
|
|
|
|
return {
|
|
screen_name: u.screen_name,
|
|
uid: u.id,
|
|
followers: u.followers_count,
|
|
following: u.friends_count,
|
|
statuses: u.statuses_count,
|
|
verified: u.verified || false,
|
|
verified_reason: u.verified_reason || '',
|
|
description: u.description || d.description || '',
|
|
location: u.location || '',
|
|
gender: u.gender === 'm' ? 'male' : u.gender === 'f' ? 'female' : '',
|
|
avatar: u.avatar_hd || u.avatar_large || '',
|
|
url: 'https://weibo.com' + (u.profile_url || '/u/' + u.id),
|
|
birthday: d.birthday || '',
|
|
created_at: d.created_at || '',
|
|
ip_location: d.ip_location || '',
|
|
};
|
|
})()
|
|
`);
|
|
if (!data || typeof data !== 'object')
|
|
throw new CommandExecutionError('Failed to fetch user profile');
|
|
if (data.error)
|
|
throw new CommandExecutionError(String(data.error));
|
|
return data;
|
|
},
|
|
});
|