add a new page for web search results to make the search faster

This commit is contained in:
Ashley 2023-10-18 18:20:07 +00:00
parent 311880a0a2
commit 65c9953f05

View file

@ -119,35 +119,74 @@ module.exports = function (app, config, renderTemplate) {
didYouMean = JSON.parse(searchJson.Search.Results.DynamicItem.Title); didYouMean = JSON.parse(searchJson.Search.Results.DynamicItem.Title);
} }
if (tab) { renderTemplate(res, req, "search.ejs", {
search({ query: `${req.query.query}` }) j: searchJson,
.then((results) => { IsOldWindows,
renderTemplate(res, req, "search.ejs", { h: didYouMean,
j: searchJson, tab,
IsOldWindows, continuation,
h: didYouMean, results: "",
tab, q: query,
continuation, summary: "",
results: results, });
q: query, } catch (error) {
summary: "", console.error(`Error while searching for '${query}':`, error);
}); res.redirect("/");
}) }
.catch((e) => { });
console.log(e);
}); app.get("/web", async (req, res) => {
} else { const query = req.query.query;
renderTemplate(res, req, "search.ejs", { const tab = req.query.tab;
j: searchJson,
const search = require("google-it");
var uaos = req.useragent.os;
var IsOldWindows;
if (uaos == "Windows 7" && req.useragent.browser == "Firefox") {
IsOldWindows = true;
} else if (uaos == "Windows 8" && req.useragent.browser == "Firefox") {
IsOldWindows = true;
} else {
IsOldWindows = false;
}
const poketube_universe_value = "poketube_smart_search";
if (query?.includes("youtube.com/watch?v=")) {
try {
var videoid = query?.split("v=");
res.redirect("/watch?v=" + videoid[1]);
} catch {
return;
}
}
if (query && query.startsWith("!") && query.length > 2) {
res.redirect("https://lite.duckduckgo.com/lite/?q=" + query);
}
if (!query) {
return res.redirect("/");
}
let continuation = req.query.continuation || "";
try {
search({ query: `${req.query.query}` }).then((results) => {
renderTemplate(res, req, "search-web.ejs", {
j: "",
IsOldWindows, IsOldWindows,
h: didYouMean, h: "",
tab, tab,
continuation, continuation,
results: "", results: results,
q: query, q: query,
summary: "", summary: "",
}); });
} });
} catch (error) { } catch (error) {
console.error(`Error while searching for '${query}':`, error); console.error(`Error while searching for '${query}':`, error);
res.redirect("/"); res.redirect("/");