revert: 移除ddg配置代理的功能

This commit is contained in:
Hk-Gosuto 2023-09-15 00:01:01 +08:00
parent d41cf84abc
commit 6da890e363
2 changed files with 1 additions and 16 deletions

View File

@ -1,9 +1,6 @@
import { decode } from "html-entities"; import { decode } from "html-entities";
import { convert as htmlToText } from "html-to-text"; import { convert as htmlToText } from "html-to-text";
import { Tool } from "langchain/tools"; import { Tool } from "langchain/tools";
import fetch from "node-fetch";
const DDG_PROXY_URL = process.env.DDG_PROXY_URL;
const SEARCH_REGEX = const SEARCH_REGEX =
/DDG\.pageLayout\.load\('d',(\[.+\])\);DDG\.duckbar\.load\('images'/; /DDG\.pageLayout\.load\('d',(\[.+\])\);DDG\.duckbar\.load\('images'/;
@ -326,15 +323,9 @@ async function search(
// cdrexp: 'b' // cdrexp: 'b'
}), }),
}; };
let proxyAgent;
if (DDG_PROXY_URL) {
const { HttpsProxyAgent } = require("https-proxy-agent");
proxyAgent = new HttpsProxyAgent(DDG_PROXY_URL);
}
const response = await fetch( const response = await fetch(
`https://links.duckduckgo.com/d.js?${queryString(queryObject)}`, `https://links.duckduckgo.com/d.js?${queryString(queryObject)}`,
{ agent: proxyAgent },
); );
const data = await response.text(); const data = await response.text();
@ -464,14 +455,8 @@ function queryString(query: Record<string, string>) {
async function getVQD(query: string, ia = "web") { async function getVQD(query: string, ia = "web") {
try { try {
let proxyAgent;
if (DDG_PROXY_URL) {
const { HttpsProxyAgent } = require("https-proxy-agent");
proxyAgent = new HttpsProxyAgent(DDG_PROXY_URL);
}
const response = await fetch( const response = await fetch(
`https://duckduckgo.com/?${queryString({ q: query, ia })}`, `https://duckduckgo.com/?${queryString({ q: query, ia })}`,
{ agent: proxyAgent },
); );
const data = await response.text(); const data = await response.text();
return VQD_REGEX.exec(data)![1]; return VQD_REGEX.exec(data)![1];

View File

@ -291,4 +291,4 @@ async function handle(req: NextRequest) {
export const GET = handle; export const GET = handle;
export const POST = handle; export const POST = handle;
export const runtime = process.env.DDG_PROXY_URL ? "nodejs" : "edge"; export const runtime = "edge";