Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
}
if (auth) {
if (apiState.token) {
options.headers.authorization = `Bearer ${apiState.token}`;
}
}
adjustedEndpoint = adjustedEndpoint.endsWith('/')
? adjustedEndpoint
: `${adjustedEndpoint}/`;
let apiURL = `${config.get('apiHost')}${adjustedEndpoint}${queryString}`;
if (_config.get('server')) {
_log.debug('Encoding `apiURL` in UTF8 before fetch().');
// Workaround for https://github.com/bitinn/node-fetch/issues/245
apiURL = utf8.encode(apiURL);
}
return fetch(apiURL, options)
.then((response) => {
// There isn't always a 'Content-Type' in headers, e.g., with a DELETE
// method or 5xx responses.
let contentType = response.headers.get('Content-Type');
contentType = contentType && contentType.toLowerCase();
// This is a bit paranoid, but we ensure the API returns a JSON response
// (see https://github.com/mozilla/addons-frontend/issues/1701).
// If not we'll store the text response in JSON and log an error.
// If the JSON parsing fails; we log the error and return an "unknown
// error".
if (contentType === 'application/json') {
return response
var value = ""
if( web3._extend.utils.isBigNumber( v ) ) { value = v }
else if( HEXRE.test( v ) ) { value = web3.toBigNumber( v ) }
else if( SHA256RE.test( v ) )
{
var out = bs58.decode( v )
ar = MH.decode( new Buffer( out ) )
if ( ar.length != 32 ) throw "HASH code should be 32 bytes long"
if ( ar.code != 0x12 ) throw "Only sha2-256 hashes are excepted"
var hex = "0x" + arrayToHex( ar.digest )
value = web3.toBigNumber( hex )
}
else
{
var utf = utf8.encode( v ).slice(0, 32);
var hex = "0x" + this.asciiToHex( utf )
value = web3.toBigNumber( hex )
}
if( v == 0 ) throw "Value cannot be zero"
if( typeof params == "function"){
callback = params
params = {}
}
if( params == undefined )
{
params = {}
}
ascii = ""
if( HEXRE.test(s) )
{
a = hexToArray( s )
hex = arrayToHex( a )
hex = "0x" + hex.substr( 0, 64 )
ascii = ""
try {
ascii = utf8.decode( toAscii( hex ) )
}
catch( x ) {}
}
else
{
utf = utf8.encode( s ).slice(0, 32);
hex = "0x" + asciiToHex( utf )
try {
ascii = utf8.decode( toAscii( hex ) )
}
catch( x ) {}
}
hex = remove0Prefix( hex )
current_domain = web3.toBigNumber( hex );
updateDomainPage()
$("#domain_hex").text( hex );
$("#domain_ascii").text( ascii );
function stringToHex(str) {
const utf8_str = utf8.encode(str)
return Buffer.from(utf8_str, 'utf8').toString('hex')
}
convertToByteString: function(str, type) {
switch (type.toLowerCase()) {
case "hex":
return Utils.byteArrayToChars(Utils.fromHex(str));
case "base64":
return Utils.byteArrayToChars(Utils.fromBase64(str, null, "byteArray"));
case "utf8":
return utf8.encode(str);
case "latin1":
default:
return str;
}
},
function stringToDebugString(str) {
return utf8.encode(str);
}
''
);
points.forEach(function(marker) {
var label = marker.label;
label = escapeHtml(label);
label = utf8.encode(label);
gpx.push(`\t`);
gpx.push(`\t\t${label}`);
gpx.push('\t');
}
);
const normalizedSegments = normalizeLines(segments);
if (normalizedSegments.length > 0) {
name = name || 'Track';
name = escapeHtml(name);
name = utf8.encode(name);
gpx.push('\t');
gpx.push('\t\t' + name + '');
for (let segment of normalizedSegments) {
gpx.push('\t\t');
for (let point of segment) {
let x = point.lng.toFixed(6);
let y = point.lat.toFixed(6);
//time element is not necessary, added for compatibility to Garmin Connect only
gpx.push(`\t\t\t<time>${fakeTime}</time>`);
}
gpx.push('\t\t');
}
gpx.push('\t');
}
gpx.push('');
module.exports = function orgs (options, callback) {
var requestOptions = {
url: 'https://api.github.com/repos/' + options.owner + '/' + options.repo + '/contents/' + options.path,
headers: { authorization: 'token ' + options.token },
method: 'put',
json: {
path: options.path,
message: options.message,
content: base64.encode(utf8.encode(options.content)),
sha: options.sha,
branch: options.branch
}
}
require('./github-get-blob')(options, function (err, res) {
if (err) return callback(err)
request(requestOptions, function (err, res, body) {
if (err) return callback(err)
callback(null, body)
})
})
}
module.exports = function createBlob (options, callback) {
var opts = {
url: 'https://api.github.com/repos/' + options.owner + '/' + options.repo + '/contents/' + options.path,
headers: { authorization: 'token ' + options.token },
method: 'put',
json: {
path: options.path,
message: options.message,
content: base64.encode(utf8.encode(options.content)),
branch: options.branch
}
}
request(opts, function (err, res, body) {
if (err) return callback(err)
var save = {
branch: options.branch,
owner: options.owner,
repo: options.repo,
location: body.content,
source: 'github'
}
callback(null, body, save)
})
}