]> git.lizzy.rs Git - google_images.git/commitdiff
Fix unresolved promise
authorElias Fleckenstein <eliasfleckenstein@web.de>
Sat, 5 Mar 2022 09:19:25 +0000 (10:19 +0100)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Sat, 5 Mar 2022 09:19:25 +0000 (10:19 +0100)
init.js

diff --git a/init.js b/init.js
index f850b45c36e7d0796c1748a9ab1d48739076038f..fd566ad287186d172c40fe3cc1ad7fb3e8b98126 100644 (file)
--- a/init.js
+++ b/init.js
@@ -3,9 +3,9 @@ const cheerio = require("cheerio")
 const jsonic = require("jsonic")
 
 module.exports.search = (query, userAgent = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:97.0) Gecko/20100101 Firefox/97.0") =>
-       fetch("https://www.google.com/search?tbm=isch&q=" + encodeURIComponent(query), {headers: {"User-Agent": userAgent}}).then(res =>
+       fetch("https://www.google.com/search?tbm=isch&q=" + encodeURIComponent(query), {headers: {"User-Agent": userAgent}}).then(res => res.text()).then(data =>
                jsonic( // jsonic is used because JSON.parse() requires strict JSON and eval() allows for remote code execution
-                       cheerio.load(res.text(), null, false)                      // parse HTML
+                       cheerio.load(data, null, false)                            // parse HTML
                        ("script")                                                 // find script tags
                        .toArray()                                                 // convert cheerio list to array
                        .map(script => script.children[0]?.data)                   // map script tags to their inline code