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>
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import type { IPage } from '../../src/types.js';
|
|
|
|
const QUERY_ID_PATTERN = /^[A-Za-z0-9_-]+$/;
|
|
|
|
export function sanitizeQueryId(resolved: unknown, fallbackId: string): string {
|
|
return typeof resolved === 'string' && QUERY_ID_PATTERN.test(resolved) ? resolved : fallbackId;
|
|
}
|
|
|
|
export async function resolveTwitterQueryId(
|
|
page: Pick<IPage, 'evaluate'>,
|
|
operationName: string,
|
|
fallbackId: string,
|
|
): Promise<string> {
|
|
const resolved = await page.evaluate(`async () => {
|
|
const operationName = ${JSON.stringify(operationName)};
|
|
try {
|
|
const ghResp = await fetch('https://raw.githubusercontent.com/fa0311/twitter-openapi/refs/heads/main/src/config/placeholder.json');
|
|
if (ghResp.ok) {
|
|
const data = await ghResp.json();
|
|
const entry = data?.[operationName];
|
|
if (entry && entry.queryId) return entry.queryId;
|
|
}
|
|
} catch {}
|
|
try {
|
|
const scripts = performance.getEntriesByType('resource')
|
|
.filter(r => r.name.includes('client-web') && r.name.endsWith('.js'))
|
|
.map(r => r.name);
|
|
for (const scriptUrl of scripts.slice(0, 15)) {
|
|
try {
|
|
const text = await (await fetch(scriptUrl)).text();
|
|
const re = new RegExp('queryId:"([A-Za-z0-9_-]+)"[^}]{0,200}operationName:"' + operationName + '"');
|
|
const match = text.match(re);
|
|
if (match) return match[1];
|
|
} catch {}
|
|
}
|
|
} catch {}
|
|
return null;
|
|
}`);
|
|
|
|
return sanitizeQueryId(resolved, fallbackId);
|
|
}
|
|
|
|
export const __test__ = {
|
|
sanitizeQueryId,
|
|
};
|