Comparing version 0.1.11 to 0.1.12
@@ -20,9 +20,11 @@ const URL = require('url'); | ||
} | ||
if (!options) options = { limit: 100 }; | ||
if (!options) options = { limit: 100, safeSearch: false }; | ||
if (!searchString && !options.nextpageRef) return callback(new Error('search string or nextpageRef is mandatory')); | ||
if (isNaN(options.limit)) options.limit = 100; | ||
if (!UTIL.isBoolean(options.safeSearch)) options.safeSearch = false; | ||
// Save provided nextpageRef and do the request | ||
const currentRef = options.nextpageRef; | ||
UTIL.getPage(currentRef ? UTIL.buildFromNextpage(currentRef) : UTIL.buildLink(searchString), (err, body) => { // eslint-disable-line consistent-return, max-len | ||
// Setting cookie in request headers to get safe search results | ||
const requestOptions = options.safeSearch ? { headers: { Cookie: 'PREF=f2=8000000' } } : {}; | ||
UTIL.getPage(currentRef ? UTIL.buildFromNextpage(currentRef) : UTIL.buildLink(searchString), requestOptions, (err, body) => { // eslint-disable-line consistent-return, max-len | ||
if (err) return callback(err); | ||
@@ -113,3 +115,3 @@ let content; | ||
UTIL.getPage(queryString, (err, body) => { // eslint-disable-line consistent-return | ||
UTIL.getPage(queryString, {}, (err, body) => { // eslint-disable-line consistent-return | ||
if (err) return callback(err); | ||
@@ -116,0 +118,0 @@ let content; |
@@ -248,4 +248,4 @@ const ENTITIES = require('html-entities').AllHtmlEntities; | ||
exports.getPage = (ref, cb) => { | ||
const request = HTTPS.get(ref, resp => { // eslint-disable-line consistent-return | ||
exports.getPage = (ref, options, cb) => { | ||
const request = HTTPS.get(ref, options, resp => { // eslint-disable-line consistent-return | ||
if (resp.statusCode !== 200) return cb(new Error(`Status Code ${resp.statusCode}`)); | ||
@@ -283,1 +283,3 @@ const respBuffer = []; | ||
}; | ||
exports.isBoolean = variable => typeof variable === 'boolean'; |
@@ -8,3 +8,3 @@ { | ||
], | ||
"version": "0.1.11", | ||
"version": "0.1.12", | ||
"repository": { | ||
@@ -11,0 +11,0 @@ "type": "git", |
@@ -53,2 +53,3 @@ <div align="center"> | ||
* possible settings: | ||
* safeSearch[Boolean] -> pull items in youtube restriction mode. | ||
* limit[integer] -> limits the pulled items | ||
@@ -55,0 +56,0 @@ * nextpageRef[String] -> if u wanna continue a previous search or use filters |
22924
375
94