do the thing

This commit is contained in:
Ashley //// 2024-04-01 15:47:51 +00:00
parent 640b472d66
commit 40b83509aa

View file

@ -167,40 +167,19 @@ module.exports = function (app, config, renderTemplate) {
});
app.get("/im-feeling-lucky", function (req, res) {
const query = req.query.query;
const search = require("google-it");
const getRandomLinkAndRedirect = (query, res) => {
search({ query: `${query}` }).then((results) => {
// Check if there are any results
if (results.length > 0) {
// Get a random index
const randomIndex = Math.floor(Math.random() * results.length);
// Get the random result object
const randomResult = results[randomIndex];
// Get the link from the random result
const randomLink = randomResult.link;
// Redirect to the random link
res.redirect(randomLink);
} else {
// Handle case when no results are found
res.send("No results found.");
}
});
};
getRandomLinkAndRedirect(query, res);
res.send("WIP");
});
app.get("/web", async (req, res) => {
const query = req.query.query;
const tab = req.query.tab;
const search = require("google-it");
const { fetch } = await import("undici");
const search = await fetch(
`https://librex.uk.to/api.php?q=${query}&p=1&t=0`
);
const web = getJson(await search.text());
if (req.query.lucky === "true") {
res.redirect("/im-feeling-lucky?query=" + query);
@ -239,7 +218,8 @@ module.exports = function (app, config, renderTemplate) {
let continuation = req.query.continuation || "";
try {
search({ query: `${req.query.query}`, disableConsole: true }).then((results) => {
const results = Object.entries(web);
renderTemplate(res, req, "search-web.ejs", {
j: "",
IsOldWindows,
@ -251,7 +231,6 @@ module.exports = function (app, config, renderTemplate) {
q: query,
summary: "",
});
});
} catch (error) {
console.error(`Error while searching for '${query}':`, error);
res.redirect("/");