Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
await Promise.all(images.map(async (img) => {
const src = await img.getAttribute('src');
// small optimization: we only check an image once
// (we don't have dynamic images)
// (we still need to use selenium to check images rather than
// a linkchecker-style approach to make sure we catch JS-added
// images)
if (_checkedImages.has(src))
return;
_checkedImages.add(src);
// this is not exactly what the browser does
const res = await Tp.Helpers.Http.getStream(src, { extraHeaders: {
Referrer: currentUrl
}});
assert(res.headers['content-type'].startsWith('image/'),
`expected image/* content type for image, found ${res['content-type']}`);
res.resume();
}));
}
function channelHistory(SlackReceiveChannel, token, channel_name, channel_id, count, lastTs) {
// Construct the proper JSON message and send to channel
return Tp.Helpers.Http.post('https://slack.com/api/channels.history',
'token=' + token +
'&channel=' + encodeURIComponent(channel_id) +
'&count=' + encodeURIComponent(count), {
dataContentType: 'application/x-www-form-urlencoded'
}
)
.then(function(response) {
var parsed = JSON.parse(response);
if (!parsed.ok) {
console.log('[ERROR] invalid response from http POST (channel.history)');
throw ("Channels.History returned status of NOT OK.");
}
var msgs = parsed.messages;
_getUploadable(url) {
if (typeof url === 'string') {
// the url might expire, so get it first, upload it and then send it
if (url.startsWith('http')) {
return Tp.Helpers.Http.getStream(url).spread((res) => {
let contentType = res.headers['content-type'];
return [res, contentType];
});
} else {
return Tp.Helpers.Content.getStream(this._device.engine.platform, url).then((stream) => {
let contentType = stream.contentType;
return [stream, contentType];
});
}
} else if (Buffer.isBuffer(url)) {
return Q([url, 'application/octet-stream']);
} else {
throw new TypeError('Invalid type for call to sendPicture, must be string or buffer');
}
}
refreshCredentials: function() {
console.log(this.constructor.metadata.client_id);
console.log(this.constructor.metadata.client_secret);
return Tp.Helpers.Http.post('https://api.fitbit.com/oauth2/token',
{
auth: 'Basic ' + Buffer.from(this.constructor.metadata.client_id + ':' + this.constructor.metadata.client_secret).toString('base64'),
grant_type: 'refresh_token',
refresh_token: this.refreshToken
}).then(function(response) {
var parsed = JSON.parse(response);
console.log('parsed', parsed);
this.state.accessToken = parsed.access_token;
this.state.refreshToken = parsed.refresh_token;
return this.accessToken;
});
}
});
do_share({ status }) {
return Tp.Helpers.Http.post(SHARE_URL, JSON.stringify({
comment: status,
visibility: {
code: 'anyone'
}
}), {
useOAuth2: this,
dataContentType: 'application/json',
accept: 'application/json'
});
}
};
return Tp.Helpers.Http.get(url).then((result) => Tp.Helpers.Xml.parseString(result))
.then((parsed) => {
flags: JSON.stringify([
'turking',
'nofilter',
'primonly',
'policies',
'remote_programs',
'aggregation',
'bookkeeping',
'triple_commands',
'configure_actions'
]),
public: true,
version: 0
});
await codeStorage.storeZipFile(await Tp.Helpers.Http.getStream('https://almond-static.stanford.edu/test-data/en-thingtalk.zip'),
'org.thingpedia.genie.thingtalk', 0, 'template-files');
return tmpl.id;
}
invokeQuery: function(filters) {
var url = this.url;
return Tp.Helpers.Http.get(url).then((data) => {
var response = JSON.parse(data);
var posts = response.objects;
return posts.map((post) => {
return [
post.interest,
post.message,
post.poster,
post.phone
];
});
});
},
});
do_move({ old_name, new_name }) {
old_name = String(old_name);
new_name = String(new_name);
if (!old_name.startsWith('/'))
old_name = '/' + old_name;
if (new_name.indexOf('/') < 0)
new_name = path.resolve(path.dirname(old_name), new_name);
if (!new_name.startsWith('/'))
new_name = '/' + new_name;
return Tp.Helpers.Http.post('https://api.dropboxapi.com/2/files/move',
JSON.stringify({ from_path: old_name, to_path: new_name }),
{ useOAuth2: this,
dataContentType: 'application/json',
accept: 'application/json' });
}
Tp.Helpers.Http.get(BOXSCORE_URL.format(this._gameId)).then((response) => {
return Tp.Helpers.Xml.parseString(response);
}).then((parsed) => {
var match = parsed.boxscore.matches[0].match[0];