新增了Bing Customer Search api的調用支持
This commit is contained in:
parent
3dec01c6d5
commit
3336f1e954
|
@ -172,13 +172,18 @@ abstract class BaseBrowser {
|
||||||
logger.debug(`Searching for: ${query}`);
|
logger.debug(`Searching for: ${query}`);
|
||||||
const search = new URLSearchParams({ q: query });
|
const search = new URLSearchParams({ q: query });
|
||||||
recency_days > 0 && search.append('recency_days', recency_days.toString());
|
recency_days > 0 && search.append('recency_days', recency_days.toString());
|
||||||
|
search.append('customconfig', config.CUSTOM_CONFIG_ID);
|
||||||
|
const url = `${config.BING_SEARCH_API_URL}/search?${search.toString()}`;
|
||||||
|
console.log('Full URL:', url); // 输出完整的 URL查看是否正确
|
||||||
|
|
||||||
return withTimeout(
|
return withTimeout(
|
||||||
config.BROWSER_TIMEOUT,
|
config.BROWSER_TIMEOUT,
|
||||||
fetch(`${config.BING_SEARCH_API_URL}/search?${search.toString()}`, {
|
fetch(url, {
|
||||||
headers: {
|
headers: {
|
||||||
'Ocp-Apim-Subscription-Key': config.BING_SEARCH_API_KEY,
|
'Ocp-Apim-Subscription-Key': config.BING_SEARCH_API_KEY,
|
||||||
}
|
}
|
||||||
}).then(
|
})
|
||||||
|
.then(
|
||||||
res =>
|
res =>
|
||||||
res.json() as Promise<{
|
res.json() as Promise<{
|
||||||
queryContext: {
|
queryContext: {
|
||||||
|
@ -255,11 +260,11 @@ abstract class BaseBrowser {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
logger.error(err.message);
|
logger.error(`搜索请求失败:${query},错误信息:${err.message}`);
|
||||||
if (err.code === 'ECONNABORTED') {
|
if (err.code === 'ECONNABORTED') {
|
||||||
throw new Error(`Timeout while executing search for: ${query}`);
|
throw new Error(`Timeout while executing search for: ${query}`);
|
||||||
}
|
}
|
||||||
throw new Error(`Network or server error occurred`);
|
throw new Error(`网络或服务器发生错误,请检查URL: ${url}`);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
open_url: (url: string) => {
|
open_url: (url: string) => {
|
||||||
|
|
|
@ -2,9 +2,9 @@ export default {
|
||||||
LOG_LEVEL: 'debug',
|
LOG_LEVEL: 'debug',
|
||||||
|
|
||||||
BROWSER_TIMEOUT: 10000,
|
BROWSER_TIMEOUT: 10000,
|
||||||
BING_SEARCH_API_URL: 'https://api.bing.microsoft.com/',
|
BING_SEARCH_API_URL: 'https://api.bing.microsoft.com/v7.0/custom/',
|
||||||
BING_SEARCH_API_KEY: '',
|
BING_SEARCH_API_KEY: 'YOUR_BING_SEARCH_API_KEY',
|
||||||
|
CUSTOM_CONFIG_ID : 'YOUR_CUSTOM_CONFIG_ID', //将你的Custom Configuration ID放在此处
|
||||||
HOST: 'localhost',
|
HOST: 'localhost',
|
||||||
PORT: 3000,
|
PORT: 3000,
|
||||||
};
|
};
|
Loading…
Reference in New Issue