Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(config = {}) {
// Prepare
const me = this
// Extend and dereference our configuration
this.config = extendr.deep(
{
log: null,
cache: 1000 * 60 * 60 * 24, // one day by default
tmpPath: null,
requestOptions: null,
plugins: null
},
this.config || {},
config
)
// Get the temp path right away
safeps.getTmpPath(function(err, tmpPath) {
if (err) {
console.error(err)
} else {
setNestedTaskConfig(opts) {
// Fetch and copy options to the state's nested task configuration
extendr.deep(this.state.nestedTaskConfig, opts)
// Chain
return this
}
args.forEach(function(arg) {
if (arg == null) return
const type = typeof arg
switch (type) {
case 'string':
opts.name = arg
break
case 'function':
opts.method = arg
break
case 'object':
extendr.deep(opts, arg) // @TODO why deep?
break
default: {
throw new Error(
`Unknown argument type of [${type}] given to TaskGroup::setConfig()`
)
}
}
})
tasks.addTask(function(complete) {
// Prepare
if (typeChecker.isString(feed)) {
feed = { url: feed }
}
feeds[index] = feed = extendr.deep({}, defaultfeed, feed)
// Read
me.readFeed(feed, function(err, data) {
// Handle
if (err) {
me.log(
'warn',
`Feedr failed to fetch [${feed.url}] to [${feed.path}]`,
err.stack
)
failures.push(err)
} else {
results[index] = data
}
// Complete
})
}
})
checkTasks.run()
}
}
// Raw
else {
checkResponse = function(opts, checkComplete) {
checkComplete()
}
}
// Request options
const requestOptions = extendr.deep(
{
url: feed.url,
timeout: 1 * 60 * 1000,
encoding: null,
headers: {
'User-Agent': 'Wget/1.14 (linux-gnu)'
}
},
me.config.requestOptions || {},
feed.requestOptions || {}
)
// Read a file
function readFile(path, readFileComplete) {
// Log
me.log(
setConfig(...configs) {
deep(this._config, ...configs)
this.emit('config', ...configs)
return this
}
setConfig(...configs) {
deep(this._config, ...configs)
this.emit('config', ...configs)
return this
}
args.forEach(function(arg) {
if (arg == null) return
const type = typeof arg
switch (type) {
case 'string':
opts.name = arg
break
case 'function':
opts.method = arg
break
case 'object':
extendr.deep(opts, arg)
break
default: {
throw new Error(
`Unknown argument type of [${type}] given to Task::setConfig()`
)
}
}
})