mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-12 07:05:56 -07:00
81accd8dbe
Lint / Linting Checks (push) Has been cancelled
Release Drafter / Update Release Draft (push) Has been cancelled
Docker CI / Docker Build & Push (push) Has been cancelled
Tests / vitest (1) (push) Has been cancelled
Tests / vitest (2) (push) Has been cancelled
Release Drafter / Auto Label PR (push) Has been cancelled
Tests / vitest (3) (push) Has been cancelled
Tests / vitest (4) (push) Has been cancelled
Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com> Signed-off-by: dependabot[bot] <support@github.com>
37 lines
1.3 KiB
JavaScript
37 lines
1.3 KiB
JavaScript
import { searchProviders } from "components/widgets/search/search";
|
|
import { getSettings } from "utils/config/config";
|
|
import { widgetsFromConfig } from "utils/config/widget-helpers";
|
|
import { cachedRequest } from "utils/proxy/http";
|
|
|
|
export default async function handler(req, res) {
|
|
const { query, providerName } = req.query;
|
|
|
|
const provider = Object.values(searchProviders).find(({ name }) => name === providerName);
|
|
|
|
if (!provider) {
|
|
return res.json([query, []]);
|
|
}
|
|
|
|
if (provider.name === "Custom") {
|
|
const widgets = await widgetsFromConfig();
|
|
const searchWidget = widgets.find((w) => w.type === "search");
|
|
|
|
if (searchWidget) {
|
|
provider.url = searchWidget.options.url;
|
|
provider.suggestionUrl = searchWidget.options.suggestionUrl;
|
|
} else {
|
|
const settings = getSettings();
|
|
if (settings.quicklaunch && settings.quicklaunch.provider === "custom") {
|
|
provider.url = settings.quicklaunch.url;
|
|
provider.suggestionUrl = settings.quicklaunch.suggestionUrl;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!provider.suggestionUrl) {
|
|
return res.json([query, []]); // Responde with the same array format but with no suggestions.
|
|
}
|
|
|
|
return res.send(await cachedRequest(`${provider.suggestionUrl}${encodeURIComponent(query)}`, 5, "Mozilla/5.0"));
|
|
}
|