mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-10 10:18:26 +01:00
add google-it back :3
This commit is contained in:
parent
71f7f61ccb
commit
debe3ddd5c
1 changed files with 40 additions and 19 deletions
|
@ -167,19 +167,40 @@ module.exports = function (app, config, renderTemplate) {
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/im-feeling-lucky", function (req, res) {
|
app.get("/im-feeling-lucky", function (req, res) {
|
||||||
res.send("WIP");
|
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);
|
||||||
});
|
});
|
||||||
|
|
||||||
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 { fetch } = await import("undici");
|
const search = require("google-it");
|
||||||
|
|
||||||
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") {
|
if (req.query.lucky === "true") {
|
||||||
res.redirect("/im-feeling-lucky?query=" + query);
|
res.redirect("/im-feeling-lucky?query=" + query);
|
||||||
|
@ -218,8 +239,7 @@ module.exports = function (app, config, renderTemplate) {
|
||||||
let continuation = req.query.continuation || "";
|
let continuation = req.query.continuation || "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const results = Object.entries(web);
|
search({ query: `${req.query.query}` }).then((results) => {
|
||||||
|
|
||||||
renderTemplate(res, req, "search-web.ejs", {
|
renderTemplate(res, req, "search-web.ejs", {
|
||||||
j: "",
|
j: "",
|
||||||
IsOldWindows,
|
IsOldWindows,
|
||||||
|
@ -231,6 +251,7 @@ module.exports = function (app, config, renderTemplate) {
|
||||||
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("/");
|
||||||
|
|
Loading…
Reference in a new issue