mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-10 06:28:35 +01:00
switch to libcurl :3
This commit is contained in:
parent
e888271e4a
commit
3628483af9
1 changed files with 10 additions and 10 deletions
|
@ -8,6 +8,8 @@ const {
|
|||
initlog,
|
||||
init,
|
||||
} = require("../libpoketube-initsys.js");
|
||||
const { curly } = require("node-libcurl");
|
||||
|
||||
const {
|
||||
IsJsonString,
|
||||
convert,
|
||||
|
@ -90,12 +92,16 @@ module.exports = function (app, config, renderTemplate) {
|
|||
let continuation = req.query.continuation || "";
|
||||
|
||||
try {
|
||||
const headers = {};
|
||||
|
||||
const searchUrl = `https://inner-api.poketube.fun/api/search?query=${encodeURIComponent(
|
||||
query
|
||||
)}&continuation=${encodeURIComponent(continuation)}`;
|
||||
const searchResponse = await modules.fetch(searchUrl);
|
||||
const searchText = await searchResponse.text();
|
||||
const searchJson = JSON.parse(modules.toJson(searchText));
|
||||
const { data } = await curly.get(searchUrl, {
|
||||
httpHeader: Object.entries(headers).map(([k, v]) => `${k}: ${v}`),
|
||||
});
|
||||
const searchText = modules.toJson(data);
|
||||
const searchJson = getJson(searchText);
|
||||
|
||||
let didYouMean;
|
||||
if (
|
||||
|
@ -104,19 +110,13 @@ module.exports = function (app, config, renderTemplate) {
|
|||
didYouMean = JSON.parse(searchJson.Search.Results.DynamicItem.Title);
|
||||
}
|
||||
|
||||
const summary = await wiki
|
||||
.summary(query + " ")
|
||||
.then((summary_) =>
|
||||
summary_.title !== "Not found." ? summary_ : "none"
|
||||
);
|
||||
|
||||
renderTemplate(res, req, "search.ejs", {
|
||||
j: searchJson,
|
||||
IsOldWindows,
|
||||
h: didYouMean,
|
||||
continuation,
|
||||
q: query,
|
||||
summary,
|
||||
summary:"",
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(`Error while searching for '${query}':`, error);
|
||||
|
|
Loading…
Reference in a new issue