Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getArrayBuffer(url, callback) {
// todo: global?
request.parse['application/x-protobuf'] = obj => obj
request.parse['application/octet-stream'] = obj => obj
/* eslint-disable indent */
request.get(url)
.on('request', function () {
// todo: needed?
// todo: check browser compat?? xhr2??? see https://github.com/visionmedia/superagent/pull/393 + https://github.com/visionmedia/superagent/pull/566
this.xhr.responseType = 'arraybuffer' // or blob
})
.end(function(err,res) {
// now res.body is an arraybuffer or a blob
if (!err && res.status >= 200 && res.status < 300) {
callback(null, res.body)
} else if (res && res.status === 404) {
callback(null, null)
} else {
// Add a query to the request
if (_isObject(auth)) {
const { user, pass, authOptions } = auth
client.auth(user, pass, authOptions)
}
if (body && httpMethod !== HTTP_METHOD_GET) {
client.send(body)
}
if (agent) {
client.agent(agent)
}
if (buffer) {
client.buffer(true)
}
if (responseParserType === CONTENT_TYPE_APPLICATION_OCTET_STREAM) {
const parser = superagent.parse[responseParserType]
client.parse(parser)
}
// Convert timeout to object if it is set and not an object
if (timeout && !_isObject(timeout)) {
timeout = { deadline: timeout }
}
client.timeout(_assign({}, timeout, DEAULT_TIMEOUT))
client.set(createDefaultHeaders(headers))
return client
}
fs.readFile(clip, function (err, data) {
if (err) return done(err);
request
.post('https://www.google.com/speech-api/v2/recognize')
.type('audio/x-flac; rate=' + opts.sampleRate)
.parse(request.parse.text)
.query({key: opts.key})
.query({lang: opts.lang})
.query({maxResults: opts.maxResults})
.query({pfilter: opts.pfilter ? 1 : 0})
.send(data)
.timeout(opts.timeout)
.end(function (err, res) {
if (err) return done(err);
var text = res.text;
if (text) text = text.split('\n')[1];
if (!text) return done(null, {result: []});
try {
done(null, JSON.parse(text));
} catch (ex) {
done(ex);
}
const url = $translation.attr('data-cdn_url')
if (url) {
const name = $translation.text()
return this._processTranslationCdnUrl(name, url)
} else {
const title = $translation.attr('title')
const translatorId = $translation.attr('data-translator_id')
const res = await requestFactory({ proxy: useProxy, charset: false})
.post(`${this.config.baseUrl}/ajax/get_cdn_series/`)
.set(this.config.headers)
.type('form')
.send({ 'id': posterId, 'translator_id': translatorId })
.buffer(true)
.parse(superagent.parse['application/json'])
return this._processTranslationResponse(title, res)
}
})
'use strict';
var Promise = require('bluebird');
var superagent = require('superagent');
module.exports = superagent;
superagent.parse[ 'text/javascript' ] = superagent.parse[ 'application/json' ];
var originalEnd = superagent.Request.prototype.end;
superagent.Request.prototype.end = function end(fn) {
var req = this;
return new Promise(function (resolve, reject) {
originalEnd.call(req, function (res) {
resolve(res);
});
req.on('error', function (err) {
reject(err);
});
router.get('/', (req, res, next) => {
const { url } = req.query
if (!url) {
throw new ResponseError('url parameter required')
}
superagent
.get(url)
.buffer(true)
.parse(superagent.parse.image)
.on('error', next)
.on('response', (resp) =>
PROXY_HEADERS.forEach((headerName) => {
const header = resp.header[headerName]
if(header) res.set(headerName, header)
})
)
.pipe(res)
})
transform: async ($el) => {
const postId = $el.attr('data-player')
const res = await this.agent
.post(`${this.config.baseUrl}/api/movies/player_data`)
.type('form')
.field({
'post_id': postId,
'showfull': true
})
.timeout(this.config.timeout)
.set(this.config.headers)
.set('X-Requested-With', 'XMLHttpRequest')
.parse(superagent.parse['application/json'])
const encryptedTranslations = res.body
.message
.translations
.video
const translations = Object.keys(encryptedTranslations)
.map((translation) => ({
translation,
url: this._decrypt(encryptedTranslations[translation])
}))
const translationsFiles = await Promise.all(translations
.map(({ translation, url }) =>
this._translationToFiles(translation, url)
))
static addParser(contentType, parseFunction) {
superagent.parse[contentType] = (res, done) => {
//if res is a string, that means we're likely in a browser environment
//and have only been provided the string to parse.
if (typeof(res) === 'string') {
return parseFunction(res);
}
//if we made it this far it's likely Node and have to do more work to parse
let baseUrl = null;
if (res.req && res.req.socket && res.req._headers && res.req._headers.host) {
const protocol = !!res.req.socket.encrypted ? 'https' : 'http';
baseUrl = new Uri({protocol: protocol, hostname: res.req._headers.host}).toString();
baseUrl = new Uri(res.req.path).absoluteTo(baseUrl).toString();
}