mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-26 12:18:14 +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,
|
initlog,
|
||||||
init,
|
init,
|
||||||
} = require("../libpoketube-initsys.js");
|
} = require("../libpoketube-initsys.js");
|
||||||
|
const { curly } = require("node-libcurl");
|
||||||
|
|
||||||
const {
|
const {
|
||||||
IsJsonString,
|
IsJsonString,
|
||||||
convert,
|
convert,
|
||||||
|
@ -90,12 +92,16 @@ module.exports = function (app, config, renderTemplate) {
|
||||||
let continuation = req.query.continuation || "";
|
let continuation = req.query.continuation || "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const headers = {};
|
||||||
|
|
||||||
const searchUrl = `https://inner-api.poketube.fun/api/search?query=${encodeURIComponent(
|
const searchUrl = `https://inner-api.poketube.fun/api/search?query=${encodeURIComponent(
|
||||||
query
|
query
|
||||||
)}&continuation=${encodeURIComponent(continuation)}`;
|
)}&continuation=${encodeURIComponent(continuation)}`;
|
||||||
const searchResponse = await modules.fetch(searchUrl);
|
const { data } = await curly.get(searchUrl, {
|
||||||
const searchText = await searchResponse.text();
|
httpHeader: Object.entries(headers).map(([k, v]) => `${k}: ${v}`),
|
||||||
const searchJson = JSON.parse(modules.toJson(searchText));
|
});
|
||||||
|
const searchText = modules.toJson(data);
|
||||||
|
const searchJson = getJson(searchText);
|
||||||
|
|
||||||
let didYouMean;
|
let didYouMean;
|
||||||
if (
|
if (
|
||||||
|
@ -104,19 +110,13 @@ module.exports = function (app, config, renderTemplate) {
|
||||||
didYouMean = JSON.parse(searchJson.Search.Results.DynamicItem.Title);
|
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", {
|
renderTemplate(res, req, "search.ejs", {
|
||||||
j: searchJson,
|
j: searchJson,
|
||||||
IsOldWindows,
|
IsOldWindows,
|
||||||
h: didYouMean,
|
h: didYouMean,
|
||||||
continuation,
|
continuation,
|
||||||
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);
|
||||||
|
|
Loading…
Reference in a new issue