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.
41 lines
1.7 KiB
JavaScript
41 lines
1.7 KiB
JavaScript
/**
|
||
* Bilibili comments — fetches top-level replies via the official API with WBI signing.
|
||
* Uses the /x/v2/reply/main endpoint which is stable and doesn't depend on DOM structure.
|
||
*/
|
||
import { cli, Strategy } from '@jackwener/opencli/registry';
|
||
import { apiGet, resolveBvid } from './utils.js';
|
||
cli({
|
||
site: 'bilibili',
|
||
name: 'comments',
|
||
description: '获取 B站视频评论(使用官方 API + WBI 签名)',
|
||
domain: 'www.bilibili.com',
|
||
strategy: Strategy.COOKIE,
|
||
args: [
|
||
{ name: 'bvid', required: true, positional: true, help: 'Video BV ID (e.g. BV1WtAGzYEBm)' },
|
||
{ name: 'limit', type: 'int', default: 20, help: 'Number of comments (max 50)' },
|
||
],
|
||
columns: ['rank', 'author', 'text', 'likes', 'replies', 'time'],
|
||
func: async (page, kwargs) => {
|
||
const bvid = await resolveBvid(kwargs.bvid);
|
||
const limit = Math.min(Number(kwargs.limit) || 20, 50);
|
||
// Resolve bvid → aid (required by reply API)
|
||
const view = await apiGet(page, '/x/web-interface/view', { params: { bvid } });
|
||
const aid = view?.data?.aid;
|
||
if (!aid)
|
||
throw new Error(`Cannot resolve aid for bvid: ${bvid}`);
|
||
const payload = await apiGet(page, '/x/v2/reply/main', {
|
||
params: { oid: aid, type: 1, mode: 3, ps: limit },
|
||
signed: true,
|
||
});
|
||
const replies = payload?.data?.replies ?? [];
|
||
return replies.slice(0, limit).map((r, i) => ({
|
||
rank: i + 1,
|
||
author: r.member?.uname ?? '',
|
||
text: (r.content?.message ?? '').replace(/\n/g, ' ').trim(),
|
||
likes: r.like ?? 0,
|
||
replies: r.rcount ?? 0,
|
||
time: new Date(r.ctime * 1000).toISOString().slice(0, 16).replace('T', ' '),
|
||
}));
|
||
},
|
||
});
|