Added support for the *custom* search provider.
This commit is contained in:
parent
2cd55cb2ea
commit
262d9f7d44
@ -114,7 +114,7 @@ export default function QuickLaunch({
|
|||||||
type: "search",
|
type: "search",
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!hideSearchSuggestions) {
|
if (!hideSearchSuggestions && searchProvider.suggestionUrl) {
|
||||||
if (searchString.trim() !== searchSuggestions[0]) {
|
if (searchString.trim() !== searchSuggestions[0]) {
|
||||||
fetch(`/api/searchSuggestion?query=${encodeURIComponent(searchString)}&providerName=${searchProvider.name}`).then(async (searchSuggestionResult) => {
|
fetch(`/api/searchSuggestion?query=${encodeURIComponent(searchString)}&providerName=${searchProvider.name}`).then(async (searchSuggestionResult) => {
|
||||||
const newSearchSuggestions = await searchSuggestionResult.json();
|
const newSearchSuggestions = await searchSuggestionResult.json();
|
||||||
|
|||||||
@ -1,11 +1,20 @@
|
|||||||
import { searchProviders } from "components/widgets/search/search";
|
import { searchProviders } from "components/widgets/search/search";
|
||||||
import cachedFetch from "utils/proxy/cached-fetch";
|
import cachedFetch from "utils/proxy/cached-fetch";
|
||||||
|
import { widgetsFromConfig } from "utils/config/widget-helpers"
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
const { query, providerName } = req.query;
|
const { query, providerName } = req.query;
|
||||||
|
|
||||||
const provider = Object.values(searchProviders).find(({ name }) => name === providerName);
|
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) {
|
if (!provider.suggestionUrl) {
|
||||||
return res.json([query, []]); // Responde with the same array format but with no suggestions.
|
return res.json([query, []]); // Responde with the same array format but with no suggestions.
|
||||||
}
|
}
|
||||||
|
|||||||
@ -211,9 +211,10 @@ function Home({ initialSettings }) {
|
|||||||
// if search provider is a list, try to retrieve from localstorage, fall back to the first
|
// if search provider is a list, try to retrieve from localstorage, fall back to the first
|
||||||
searchProvider = getStoredProvider() ?? searchProviders[searchWidget.options.provider[0]];
|
searchProvider = getStoredProvider() ?? searchProviders[searchWidget.options.provider[0]];
|
||||||
} else if (searchWidget.options?.provider === "custom") {
|
} else if (searchWidget.options?.provider === "custom") {
|
||||||
searchProvider = {
|
searchProvider = {...searchProviders.custom, ...{
|
||||||
url: searchWidget.options.url,
|
url: searchWidget.options.url,
|
||||||
};
|
suggestionUrl: searchWidget.options.suggestionUrl,
|
||||||
|
}};
|
||||||
} else {
|
} else {
|
||||||
searchProvider = searchProviders[searchWidget.options?.provider];
|
searchProvider = searchProviders[searchWidget.options?.provider];
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user