mirror of
https://github.com/Yanyutin753/ChatGPT-Next-Web-LangChain-Gpt-4-All.git
synced 2025-10-15 23:52:59 +00:00
revert: 移除ddg配置代理的功能
This commit is contained in:
@@ -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];
|
||||||
|
@@ -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";
|
||||||
|
Reference in New Issue
Block a user