Files
wehub-resource-sync 9b395f5cc3
Build Chrome Extension / build (push) Waiting to run
Trigger Website Rebuild (Docs Updated) / dispatch (push) Waiting to run
E2E Headed Chrome / e2e-headed (macos-15) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (ubuntu-latest) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (windows-latest) (push) Has been cancelled
CI / build (macos-latest) (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled
CI / build (windows-latest) (push) Has been cancelled
CI / unit-test (push) Has been cancelled
CI / bun-test (push) Has been cancelled
CI / adapter-test (push) Has been cancelled
CI / smoke-test (macos-latest) (push) Has been cancelled
CI / smoke-test (ubuntu-latest) (push) Has been cancelled
Security Audit / audit (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:39:48 +08:00

42 lines
1.6 KiB
JavaScript

/**
* 携程旅行 destination suggest — public city/landmark/scenic-spot lookup.
*/
import { ArgumentError, EmptyResultError } from '@jackwener/opencli/errors';
import { cli, Strategy } from '@jackwener/opencli/registry';
import { fetchSuggest, mapSuggestRow, parseLimit } from './utils.js';
cli({
site: 'ctrip',
name: 'search',
access: 'read',
description: '搜索携程目的地、景区、火车站和地标联想结果',
strategy: Strategy.PUBLIC,
browser: false,
args: [
{ name: 'query', required: true, positional: true, help: 'Search keyword (city, scenic spot, landmark)' },
{ name: 'limit', type: 'int', default: 15, help: 'Number of results (1-50)' },
],
columns: [
'rank', 'id', 'type', 'displayType', 'name', 'eName',
'cityId', 'cityName', 'provinceName', 'countryName',
'lat', 'lon', 'score', 'url',
],
func: async (kwargs) => {
const query = String(kwargs.query || '').trim();
if (!query) {
throw new ArgumentError('Search keyword cannot be empty');
}
const limit = parseLimit(kwargs.limit);
const raw = await fetchSuggest(query, 'D');
const rows = raw
.filter((item) => !!item && typeof item === 'object')
.slice(0, limit)
.map(mapSuggestRow)
.filter((row) => row.name);
if (!rows.length) {
throw new EmptyResultError('ctrip search', 'Try a destination, scenic spot, or landmark keyword such as "苏州" or "故宫"');
}
return rows;
},
});