mirror of
https://codeberg.org/ashley/poke.git
synced 2024-12-25 08:18:43 +01:00
fix search
This commit is contained in:
parent
3dc33bbb47
commit
9157736e45
1 changed files with 18 additions and 40 deletions
|
@ -167,40 +167,14 @@ module.exports = function (app, config, renderTemplate) {
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/im-feeling-lucky", function (req, res) {
|
app.get("/im-feeling-lucky", function (req, res) {
|
||||||
const query = req.query.query;
|
res.send("WIP")
|
||||||
|
|
||||||
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);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/web", async (req, res) => {
|
app.get("/web", async (req, res) => {
|
||||||
const query = req.query.query;
|
const query = req.query.query;
|
||||||
const tab = req.query.tab;
|
const tab = req.query.tab;
|
||||||
|
|
||||||
const search = require("google-it");
|
const search = require("duckduckgo-search");
|
||||||
|
|
||||||
if (req.query.lucky === "true") {
|
if (req.query.lucky === "true") {
|
||||||
res.redirect("/im-feeling-lucky?query=" + query);
|
res.redirect("/im-feeling-lucky?query=" + query);
|
||||||
|
@ -239,18 +213,22 @@ module.exports = function (app, config, renderTemplate) {
|
||||||
let continuation = req.query.continuation || "";
|
let continuation = req.query.continuation || "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
search({ query: `${req.query.query}` }).then((results) => {
|
const results = []; // Initialize an array to store search results
|
||||||
renderTemplate(res, req, "search-web.ejs", {
|
|
||||||
j: "",
|
for await (const result of search.text(query)) {
|
||||||
IsOldWindows,
|
results.push(result); // Push each result to the results array
|
||||||
h: "",
|
}
|
||||||
tab,
|
|
||||||
continuation,
|
renderTemplate(res, req, "search-web.ejs", {
|
||||||
isMobile: req.useragent.isMobile,
|
j: "",
|
||||||
results: results,
|
IsOldWindows,
|
||||||
q: query,
|
h: "",
|
||||||
summary: "",
|
tab,
|
||||||
});
|
continuation,
|
||||||
|
isMobile: req.useragent.isMobile,
|
||||||
|
results: results,
|
||||||
|
q: query,
|
||||||
|
summary: "",
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error while searching for '${query}':`, error);
|
console.error(`Error while searching for '${query}':`, error);
|
||||||
|
|
Loading…
Reference in a new issue