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.
48 lines
1.8 KiB
JavaScript
48 lines
1.8 KiB
JavaScript
import { cli, Strategy } from '@jackwener/opencli/registry';
|
|
import { ensureZsxqAuth, ensureZsxqPage, fetchFirstJson, getTopicText, getTopicAuthor, getTopicUrl, } from './utils.js';
|
|
cli({
|
|
site: 'zsxq',
|
|
name: 'dynamics',
|
|
description: '获取所有星球的最新动态',
|
|
domain: 'wx.zsxq.com',
|
|
strategy: Strategy.COOKIE,
|
|
browser: true,
|
|
args: [
|
|
{ name: 'limit', type: 'int', default: 20, help: 'Number of dynamics to return' },
|
|
],
|
|
columns: ['time', 'group', 'author', 'title', 'comments', 'likes', 'url'],
|
|
func: async (page, kwargs) => {
|
|
await ensureZsxqPage(page);
|
|
await ensureZsxqAuth(page);
|
|
const limit = Math.max(1, Number(kwargs.limit) || 20);
|
|
const { data } = await fetchFirstJson(page, [
|
|
`https://api.zsxq.com/v2/dynamics?scope=general&count=${limit}`,
|
|
]);
|
|
const respData = data?.resp_data || data;
|
|
const dynamics = respData?.dynamics || [];
|
|
return dynamics.slice(0, limit).map((d) => {
|
|
const topic = d.topic;
|
|
if (!topic) {
|
|
return {
|
|
time: d.create_time || '',
|
|
group: '',
|
|
author: '',
|
|
title: `[${d.action || 'unknown'}]`,
|
|
comments: 0,
|
|
likes: 0,
|
|
url: '',
|
|
};
|
|
}
|
|
return {
|
|
time: d.create_time || topic.create_time || '',
|
|
group: topic.group?.name || '',
|
|
author: getTopicAuthor(topic),
|
|
title: getTopicText(topic).slice(0, 120),
|
|
comments: topic.comments_count ?? 0,
|
|
likes: topic.likes_count ?? 0,
|
|
url: getTopicUrl(topic.topic_id),
|
|
};
|
|
});
|
|
},
|
|
});
|