whatsthis
Version:
Discover embedable content from URL's
41 lines (33 loc) • 910 B
JavaScript
;
var request = require('request');
/**
* Detect if the given URL is an image.
*
* @param {Result} result Result of message parsing.
* @param {Function} next Continuation callback.
* @private
*/
module.exports = function instagram(result, next) {
if (!(
result.url.hostname === 'instagram.com'
|| result.url.hostname === 'www.instagram.com'
|| result.url.hostname === 'instagr.am'
) || !/\/p\//g.test(result.url.pathname)) {
return next();
}
//
// Normalize shoturl's to longer urls.
//
result.url.set('hostname', 'instagram.com');
result.type = 'social';
result.service = 'instagram';
request({
json: true,
method: 'GET',
url: 'https://api.instagram.com/oembed?url='+ result.url.href
}, function generedembed(err, res, body) {
if (err) return fn();
result.html = body.html;
return next(undefined, true);
});
};