whatsthis
Version:
Discover embedable content from URL's
36 lines (29 loc) • 974 B
JavaScript
;
var img = require('image-extensions')
, path = require('path');
/**
* Detect if the given URL is an image.
*
* @param {Result} result Result of message parsing.
* @param {Function} next Continuation callback.
* @private
*/
module.exports = function image(result, next) {
var ext = path.extname(result.url.pathname).slice(1);
//
// Imgur edgecase, we don't want gifv's to be shown as movies, but as gifs
// because we lack the technical implementation for that at this point. So
// simply rewrite the gifv to gif and it shall work
//
if (~result.url.hostname.indexOf('imgur') && 'gifv' === ext) {
result.url.set('pathname', result.url.pathname.split('.')[0] + '.gif');
ext = 'gif';
}
if (!~img.indexOf(ext)) {
return next();
}
result.type = 'image';
result.service = 'image';
result.html = '<a href="'+ result.url.href +'" target="_blank"><img src="'+ result.url.href +'" /></a>';
next(undefined, true);
};