From c85b0d0b06ea97b489bc5af0f4b593dbf6539262 Mon Sep 17 00:00:00 2001 From: Ashley Date: Tue, 17 Oct 2023 18:24:10 +0000 Subject: [PATCH] add web search~ :3 --- .../init/pages-channel-and-download.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/libpoketube/init/pages-channel-and-download.js b/src/libpoketube/init/pages-channel-and-download.js index cbad8945..6bb1a8ce 100644 --- a/src/libpoketube/init/pages-channel-and-download.js +++ b/src/libpoketube/init/pages-channel-and-download.js @@ -63,7 +63,11 @@ module.exports = function (app, config, renderTemplate) { app.get("/search", async (req, res) => { const query = req.query.query; - + const tab = req.query.tab + + const search = require('google-it') + + var uaos = req.useragent.os; var IsOldWindows; @@ -112,15 +116,22 @@ module.exports = function (app, config, renderTemplate) { let didYouMean; if ( searchJson.Search?.Results?.DynamicItem?.id === "didYouMeanRenderer" ) { didYouMean = JSON.parse(searchJson.Search.Results.DynamicItem.Title); } - - renderTemplate(res, req, "search.ejs", { + + search({'query': `${req.query.query}`}).then(results => { + renderTemplate(res, req, "search.ejs", { j: searchJson, IsOldWindows, h: didYouMean, + tab, continuation, + results:results, q: query, summary: "", }); + }).catch(e => { + console.log(e) +}) + } catch (error) { console.error(`Error while searching for '${query}':`, error); res.redirect("/");