Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
} catch (e) {
console.error("ActiveXObject object not defined.");
}
// now, consider RequireJS and/or Node.js objects
} else if (typeof require === "function"
&& require
) {
// look for xmlhttprequest module
try {
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
xml = new XMLHttpRequest();
} catch (e1) {
// or maybe the user is using xhr2
try {
var XMLHttpRequest = require("xhr2");
xml = new XMLHttpRequest();
} catch (e2) {
console.error("xhr2 object not defined, cancelling.");
}
}
}
return xml;
};
function getRequestWithOnlyUrl(theUrl) {
theRequest = new XMLHttpRequest();
theUrl = theUrl;
console.log("Checking URL: " + theUrl);
theRequest.open('GET', theUrl, /* async = */ false);
theRequest.send();
if (theRequest.status >= 200 && theRequest.status < 300) {
return theRequest.responseText;
} else {
console.log(theRequest.status);
}
}
var XHR = global.XMLHttpRequest = function() {
xhr.apply(this, arguments);
this._hackSend = this.send;
this.send = XHR.prototype.send;
this._hackOpen = this.open;
this.open = XHR.prototype.open;
// In browsers these default to null
this.onload = null;
this.onerror = null;
// jQuery checks for this property to see if XHR supports CORS
this.withCredentials = true;
};
function FPKMDownload(line){
const FPKMPath = path.join(folderPath, 'FPKM')
mkdirp.sync(FPKMPath)
const UUID = line.split(' ')[1]
const caseid = line.split(' ')[0]
const filepath = path.join(FPKMPath, 'FPKM_'+caseid+'.csv')
var options = null
var link = 'https://gdc-api.nci.nih.gov/data/' + UUID
var suffix
var filename
var client = new XMLHttpRequest()
try{
client.open("GET", link , true)
client.send()
client.onreadystatechange = function() {
if(this.readyState == 4 && this.status == 200) {
try{
var markerStream = fs.createWriteStream(filepath, {'flags':'w'})
var stream = request(link).pipe(zlib.createGunzip()).pipe(markerStream)
stream.on('finish', function() {
markerStream.end()
FPKM_index = FPKM_index + 1
console.log('F_'+FPKM_index)
if(FPKM_index < FPKM_list.length){FPKMDownload(FPKM_list[FPKM_index])}
})
}
catch(err){
var XHR = global.XMLHttpRequest = function() {
xhr.apply(this, arguments);
this._hackSend = this.send;
this.send = XHR.prototype.send;
var oldOpen = this.open;
this.open = function() {
var req = global.doneSsr.request;
var baseUri = req.url || "";
if ( req.protocol && req.get ) {
baseUri = req.protocol + '://' + req.get( "host" ) + baseUri;
}
var args = Array.prototype.slice.call(arguments);
var reqURL = args[1];
if ( reqURL && !fullUrl.test( reqURL ) ) {
args[1] = url.resolve( baseUri, reqURL );
}
function get (url, callback) {
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = _requestHandler(callback);
httpRequest.open("GET", url);
_maybeSetReferer(httpRequest);
httpRequest.send(null);
}
util.ua.hasCORS = 'undefined' != typeof XMLHttpRequest && (function () {
try {
var a = new XMLHttpRequest();
} catch (e) {
return false;
}
return a.withCredentials != undefined;
})();
return new Promise((resolve, reject) => {
let req = new XMLHttpRequest();
let conf = {
'ctype': null,
'data': null,
'url': `${this.config.host ? this.config.host + '/' : ''}`
+ `${endpoint.uri}`
};
req.addEventListener("load", function() {
let tmp = null;
switch(this.getResponseHeader('Content-Type')) {
case 'application/json':
tmp = JSON.parse(this.responseText);
if (tmp.error) {
reject(new APIError(tmp));
} else {
resolve(tmp);
function post (url, data, callback) {
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = _requestHandler(callback);
httpRequest.open("POST", url);
_maybeSetReferer(httpRequest);
httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
httpRequest.send(stringify(data));
}
return new Promise(function(resolve, reject) {
if (typeof method !== 'string' || !params) {
throw new Error('method and params are required args.');
}
var xhr = new XHR();
xhr.open(method.toUpperCase(), params.url, true);
xhr.withCredentials = !!params.withCredentials;
xhr.onreadystatechange = function onreadystatechange() {
if (xhr.readyState !== 4) { return; }
if (200 <= xhr.status && xhr.status < 300) {
resolve(xhr.responseText);
} else {
reject(xhr.responseText);
}
};
for (var headerName in params.headers) {
xhr.setRequestHeader(headerName, params.headers[headerName]);
}