feat: Add support for custom Google domain in search settings
This commit is contained in:
parent
772000bff4
commit
15fb80d75d
@ -74,6 +74,9 @@
|
||||
"braveApi": {
|
||||
"label": "Brave API Key",
|
||||
"placeholder": "Enter your Brave API key"
|
||||
},
|
||||
"googleDomain": {
|
||||
"label": "Google Domain"
|
||||
}
|
||||
},
|
||||
"system": {
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { SaveButton } from "@/components/Common/SaveButton"
|
||||
import { getSearchSettings, setSearchSettings } from "@/services/search"
|
||||
import { ALL_GOOGLE_DOMAINS } from "@/utils/google-domains"
|
||||
import { SUPPORTED_SERACH_PROVIDERS } from "@/utils/search-provider"
|
||||
import { useForm } from "@mantine/form"
|
||||
import { useQuery } from "@tanstack/react-query"
|
||||
@ -18,6 +19,7 @@ export const SearchModeSettings = () => {
|
||||
searxngURL: "",
|
||||
searxngJSONMode: false,
|
||||
braveApiKey: "",
|
||||
googleDomain: ""
|
||||
}
|
||||
})
|
||||
|
||||
@ -82,6 +84,32 @@ export const SearchModeSettings = () => {
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{form.values.searchProvider === "google" && (
|
||||
<>
|
||||
<div className="flex sm:flex-row flex-col space-y-4 sm:space-y-0 sm:justify-between">
|
||||
<span className="text-gray-700 dark:text-neutral-50">
|
||||
{t("generalSettings.webSearch.googleDomain.label")}
|
||||
</span>
|
||||
<div>
|
||||
<Select
|
||||
showSearch
|
||||
className="w-full mt-4 sm:mt-0 sm:w-[200px]"
|
||||
options={ALL_GOOGLE_DOMAINS.map((e) => ({
|
||||
label: e,
|
||||
value: e
|
||||
}))}
|
||||
filterOption={(input, option) =>
|
||||
option!.label.toLowerCase().indexOf(input.toLowerCase()) >=
|
||||
0 ||
|
||||
option!.value.toLowerCase().indexOf(input.toLowerCase()) >=
|
||||
0
|
||||
}
|
||||
{...form.getInputProps("googleDomain")}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{form.values.searchProvider === "brave-api" && (
|
||||
<>
|
||||
<div className="flex sm:flex-row flex-col space-y-4 sm:space-y-0 sm:justify-between">
|
||||
|
@ -92,11 +92,21 @@ export const setBraveApiKey = async (braveApiKey: string) => {
|
||||
await storage2.set("braveApiKey", braveApiKey)
|
||||
}
|
||||
|
||||
export const getGoogleDomain = async () => {
|
||||
const domain = await storage2.get("searchGoogleDomain")
|
||||
return domain || "google.com"
|
||||
}
|
||||
|
||||
export const setGoogleDomain = async (domain: string) => {
|
||||
await storage2.set("searchGoogleDomain", domain)
|
||||
}
|
||||
|
||||
export const getSearchSettings = async () => {
|
||||
const [isSimpleInternetSearch, searchProvider, totalSearchResult, visitSpecificWebsite,
|
||||
searxngURL,
|
||||
searxngJSONMode,
|
||||
braveApiKey
|
||||
braveApiKey,
|
||||
googleDomain
|
||||
] =
|
||||
await Promise.all([
|
||||
getIsSimpleInternetSearch(),
|
||||
@ -105,7 +115,8 @@ export const getSearchSettings = async () => {
|
||||
getIsVisitSpecificWebsite(),
|
||||
getSearxngURL(),
|
||||
isSearxngJSONMode(),
|
||||
getBraveApiKey()
|
||||
getBraveApiKey(),
|
||||
getGoogleDomain()
|
||||
])
|
||||
|
||||
return {
|
||||
@ -115,7 +126,8 @@ export const getSearchSettings = async () => {
|
||||
visitSpecificWebsite,
|
||||
searxngURL,
|
||||
searxngJSONMode,
|
||||
braveApiKey
|
||||
braveApiKey,
|
||||
googleDomain
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,7 +138,8 @@ export const setSearchSettings = async ({
|
||||
visitSpecificWebsite,
|
||||
searxngJSONMode,
|
||||
searxngURL,
|
||||
braveApiKey
|
||||
braveApiKey,
|
||||
googleDomain
|
||||
}: {
|
||||
isSimpleInternetSearch: boolean
|
||||
searchProvider: string
|
||||
@ -134,7 +147,8 @@ export const setSearchSettings = async ({
|
||||
visitSpecificWebsite: boolean
|
||||
searxngURL: string
|
||||
searxngJSONMode: boolean,
|
||||
braveApiKey: string
|
||||
braveApiKey: string,
|
||||
googleDomain: string
|
||||
}) => {
|
||||
await Promise.all([
|
||||
setIsSimpleInternetSearch(isSimpleInternetSearch),
|
||||
@ -143,6 +157,7 @@ export const setSearchSettings = async ({
|
||||
setIsVisitSpecificWebsite(visitSpecificWebsite),
|
||||
setSearxngJSONMode(searxngJSONMode),
|
||||
setSearxngURL(searxngURL),
|
||||
setBraveApiKey(braveApiKey)
|
||||
setBraveApiKey(braveApiKey),
|
||||
setGoogleDomain(googleDomain)
|
||||
])
|
||||
}
|
||||
|
188
src/utils/google-domains.ts
Normal file
188
src/utils/google-domains.ts
Normal file
@ -0,0 +1,188 @@
|
||||
export const ALL_GOOGLE_DOMAINS = [
|
||||
"google.ad",
|
||||
"google.ae",
|
||||
"google.al",
|
||||
"google.am",
|
||||
"google.as",
|
||||
"google.at",
|
||||
"google.az",
|
||||
"google.ba",
|
||||
"google.be",
|
||||
"google.bf",
|
||||
"google.bg",
|
||||
"google.bi",
|
||||
"google.bj",
|
||||
"google.bs",
|
||||
"google.bt",
|
||||
"google.by",
|
||||
"google.ca",
|
||||
"google.cd",
|
||||
"google.cf",
|
||||
"google.cg",
|
||||
"google.ch",
|
||||
"google.ci",
|
||||
"google.cl",
|
||||
"google.cm",
|
||||
"google.co.ao",
|
||||
"google.co.bw",
|
||||
"google.co.ck",
|
||||
"google.co.cr",
|
||||
"google.co.id",
|
||||
"google.co.il",
|
||||
"google.co.in",
|
||||
"google.co.jp",
|
||||
"google.co.ke",
|
||||
"google.co.kr",
|
||||
"google.co.ls",
|
||||
"google.co.ma",
|
||||
"google.co.mz",
|
||||
"google.co.nz",
|
||||
"google.co.th",
|
||||
"google.co.tz",
|
||||
"google.co.ug",
|
||||
"google.co.uk",
|
||||
"google.co.uz",
|
||||
"google.co.ve",
|
||||
"google.co.vi",
|
||||
"google.co.za",
|
||||
"google.co.zm",
|
||||
"google.co.zw",
|
||||
"google.com",
|
||||
"google.com.af",
|
||||
"google.com.ag",
|
||||
"google.com.ai",
|
||||
"google.com.ar",
|
||||
"google.com.au",
|
||||
"google.com.bd",
|
||||
"google.com.bh",
|
||||
"google.com.bn",
|
||||
"google.com.bo",
|
||||
"google.com.br",
|
||||
"google.com.bz",
|
||||
"google.com.co",
|
||||
"google.com.cu",
|
||||
"google.com.cy",
|
||||
"google.com.do",
|
||||
"google.com.ec",
|
||||
"google.com.eg",
|
||||
"google.com.et",
|
||||
"google.com.fj",
|
||||
"google.com.gh",
|
||||
"google.com.gi",
|
||||
"google.com.gt",
|
||||
"google.com.hk",
|
||||
"google.com.jm",
|
||||
"google.com.kh",
|
||||
"google.com.kw",
|
||||
"google.com.lb",
|
||||
"google.com.ly",
|
||||
"google.com.mm",
|
||||
"google.com.mt",
|
||||
"google.com.mx",
|
||||
"google.com.my",
|
||||
"google.com.na",
|
||||
"google.com.ng",
|
||||
"google.com.ni",
|
||||
"google.com.np",
|
||||
"google.com.om",
|
||||
"google.com.pa",
|
||||
"google.com.pe",
|
||||
"google.com.pg",
|
||||
"google.com.ph",
|
||||
"google.com.pk",
|
||||
"google.com.pr",
|
||||
"google.com.py",
|
||||
"google.com.qa",
|
||||
"google.com.sa",
|
||||
"google.com.sb",
|
||||
"google.com.sg",
|
||||
"google.com.sl",
|
||||
"google.com.sv",
|
||||
"google.com.tj",
|
||||
"google.com.tr",
|
||||
"google.com.tr",
|
||||
"google.com.tw",
|
||||
"google.com.ua",
|
||||
"google.com.uy",
|
||||
"google.com.vc",
|
||||
"google.com.vn",
|
||||
"google.cv",
|
||||
"google.cz",
|
||||
"google.de",
|
||||
"google.dj",
|
||||
"google.dk",
|
||||
"google.dm",
|
||||
"google.dz",
|
||||
"google.ee",
|
||||
"google.es",
|
||||
"google.fi",
|
||||
"google.fm",
|
||||
"google.fr",
|
||||
"google.ga",
|
||||
"google.ge",
|
||||
"google.gl",
|
||||
"google.gm",
|
||||
"google.gp",
|
||||
"google.gr",
|
||||
"google.gy",
|
||||
"google.hn",
|
||||
"google.hr",
|
||||
"google.ht",
|
||||
"google.hu",
|
||||
"google.ie",
|
||||
"google.iq",
|
||||
"google.is",
|
||||
"google.it",
|
||||
"google.je",
|
||||
"google.jo",
|
||||
"google.kg",
|
||||
"google.ki",
|
||||
"google.kz",
|
||||
"google.la",
|
||||
"google.li",
|
||||
"google.lk",
|
||||
"google.lt",
|
||||
"google.lu",
|
||||
"google.lv",
|
||||
"google.md",
|
||||
"google.mg",
|
||||
"google.mk",
|
||||
"google.ml",
|
||||
"google.mn",
|
||||
"google.ms",
|
||||
"google.mu",
|
||||
"google.mv",
|
||||
"google.mw",
|
||||
"google.ne",
|
||||
"google.nl",
|
||||
"google.no",
|
||||
"google.nr",
|
||||
"google.nu",
|
||||
"google.pl",
|
||||
"google.ps",
|
||||
"google.pt",
|
||||
"google.ro",
|
||||
"google.rs",
|
||||
"google.ru",
|
||||
"google.rw",
|
||||
"google.sc",
|
||||
"google.se",
|
||||
"google.sh",
|
||||
"google.si",
|
||||
"google.sk",
|
||||
"google.sm",
|
||||
"google.sn",
|
||||
"google.so",
|
||||
"google.sr",
|
||||
"google.td",
|
||||
"google.tg",
|
||||
"google.tk",
|
||||
"google.tl",
|
||||
"google.tm",
|
||||
"google.tn",
|
||||
"google.to",
|
||||
"google.tt",
|
||||
"google.vg",
|
||||
"google.vu",
|
||||
"google.ws"
|
||||
]
|
@ -1,5 +1,6 @@
|
||||
import { pageAssistEmbeddingModel } from "@/models/embedding"
|
||||
import {
|
||||
getGoogleDomain,
|
||||
getIsSimpleInternetSearch,
|
||||
totalSearchResults
|
||||
} from "@/services/search"
|
||||
@ -18,15 +19,16 @@ import {
|
||||
|
||||
|
||||
export const localGoogleSearch = async (query: string) => {
|
||||
const baseGoogleDomain = await getGoogleDomain()
|
||||
await urlRewriteRuntime(
|
||||
cleanUrl("https://www.google.com/search?hl=en&q=" + query),
|
||||
cleanUrl(`https://www.${baseGoogleDomain}/search?hl=en&q=` + query),
|
||||
"google"
|
||||
)
|
||||
const abortController = new AbortController()
|
||||
setTimeout(() => abortController.abort(), 10000)
|
||||
|
||||
const htmlString = await fetch(
|
||||
"https://www.google.com/search?hl=en&q=" + query,
|
||||
`https://www.${baseGoogleDomain}/search?hl=en&q=` + query,
|
||||
{
|
||||
signal: abortController.signal
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user