Added support for the *custom* search provider.

This commit is contained in:
Flo2410 2024-01-26 23:16:19 +00:00
parent 2cd55cb2ea
commit 262d9f7d44
No known key found for this signature in database
GPG Key ID: 8ECB00AC5216DC7F
3 changed files with 13 additions and 3 deletions

View File

@ -114,7 +114,7 @@ export default function QuickLaunch({
type: "search",
});
if (!hideSearchSuggestions) {
if (!hideSearchSuggestions && searchProvider.suggestionUrl) {
if (searchString.trim() !== searchSuggestions[0]) {
fetch(`/api/searchSuggestion?query=${encodeURIComponent(searchString)}&providerName=${searchProvider.name}`).then(async (searchSuggestionResult) => {
const newSearchSuggestions = await searchSuggestionResult.json();

View File

@ -1,11 +1,20 @@
import { searchProviders } from "components/widgets/search/search";
import cachedFetch from "utils/proxy/cached-fetch";
import { widgetsFromConfig } from "utils/config/widget-helpers"
export default async function handler(req, res) {
const { query, providerName } = req.query;
const provider = Object.values(searchProviders).find(({ name }) => name === providerName);
if (provider.name === "Custom") {
const widgets = await widgetsFromConfig();
const searchWidget = widgets.find((w) => w.type === "search");
provider.url = searchWidget.options.url ?? "";
provider.suggestionUrl = searchWidget.options.suggestionUrl ?? "";
}
if (!provider.suggestionUrl) {
return res.json([query, []]); // Responde with the same array format but with no suggestions.
}

View File

@ -211,9 +211,10 @@ function Home({ initialSettings }) {
// if search provider is a list, try to retrieve from localstorage, fall back to the first
searchProvider = getStoredProvider() ?? searchProviders[searchWidget.options.provider[0]];
} else if (searchWidget.options?.provider === "custom") {
searchProvider = {
searchProvider = {...searchProviders.custom, ...{
url: searchWidget.options.url,
};
suggestionUrl: searchWidget.options.suggestionUrl,
}};
} else {
searchProvider = searchProviders[searchWidget.options?.provider];
}