mirror of
https://github.com/jackwener/OpenCLI.git
synced 2026-09-14 18:25:42 +08:00
314bc6f231
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>
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
/**
|
|
* Google Search Suggestions via public JSON API.
|
|
* Uses suggestqueries.google.com with client=firefox for pure JSON (not JSONP).
|
|
*/
|
|
|
|
import { cli, Strategy } from '../../src/registry.js';
|
|
import { CliError } from '../../src/errors.js';
|
|
|
|
cli({
|
|
site: 'google',
|
|
name: 'suggest',
|
|
description: 'Get Google search suggestions',
|
|
strategy: Strategy.PUBLIC,
|
|
browser: false,
|
|
args: [
|
|
{ name: 'keyword', positional: true, required: true, help: 'Search query' },
|
|
{ name: 'lang', default: 'zh-CN', help: 'Language code' },
|
|
],
|
|
columns: ['suggestion'],
|
|
func: async (_page, args) => {
|
|
const keyword = encodeURIComponent(args.keyword);
|
|
const lang = encodeURIComponent(args.lang);
|
|
const url = `https://suggestqueries.google.com/complete/search?client=firefox&q=${keyword}&hl=${lang}`;
|
|
|
|
const resp = await fetch(url);
|
|
if (!resp.ok) {
|
|
throw new CliError('FETCH_ERROR', `HTTP ${resp.status}`, 'Check your network connection');
|
|
}
|
|
|
|
const data = await resp.json();
|
|
// Response format: ["query", ["suggestion1", "suggestion2", ...]]
|
|
const suggestions: string[] = Array.isArray(data) && Array.isArray(data[1]) ? data[1] : [];
|
|
|
|
if (!suggestions.length) {
|
|
throw new CliError('NOT_FOUND', 'No suggestions found', 'Try a different keyword');
|
|
}
|
|
|
|
return suggestions.map(s => ({ suggestion: s }));
|
|
},
|
|
});
|