iframely
Version:
oEmbed/2 gateway endpoint. Get embed data for various http links through one self-hosted API
70 lines (56 loc) • 2.16 kB
JavaScript
import utils from './utils.js';
function getVideoLinks(video, whitelistRecord) {
var width = whitelistRecord.isAllowed('og.video', 'rotate') ? video.height : video.width;
var height = whitelistRecord.isAllowed('og.video', 'rotate') ? video.width : video.height;
var accept = ['video/*', 'audio/*', CONFIG.T.stream_apple_mpegurl, CONFIG.T.stream_x_mpegurl];
if (!whitelistRecord.isDefault) {
accept.push(CONFIG.T.text_html);
}
var players = [];
if (!whitelistRecord.isDefault || /\.?(mp4|m4v|m3u8|mp3)/i.test(video.url || video) || /^video\//i.test(video.type)) {
players.push({
href: video.url || video,
accept: accept,
rel: [CONFIG.R.player, CONFIG.R.og],
width: width,
height: height
});
}
if (whitelistRecord.isAllowed('og.video', 'ssl') && video.secure_url) {
players.push({
href: video.secure_url,
accept: accept,
rel: [CONFIG.R.player, CONFIG.R.og],
width: width,
height: height
});
}
if (whitelistRecord.isAllowed('og.video', 'iframe') && video.iframe) {
players.push({
href: video.iframe,
accept: CONFIG.T.text_html,
rel: [CONFIG.R.player, CONFIG.R.og],
width: width,
height: height
});
}
return players;
}
export default {
getLinks: function(og, whitelistRecord) {
if (og.video
&& (whitelistRecord.isAllowed && whitelistRecord.isAllowed('og.video')
|| !whitelistRecord.og && /\.(mp4|m3u8|mp3)/i.test(og.video.url || og.video)
|| !whitelistRecord.og && /^video\//i.test(og.video.type)) ) {
if (og.video instanceof Array) {
return utils.mergeMediaSize(
og.video.map(function(video) {
return getVideoLinks(video, whitelistRecord);
}).flat()
);
} else if (og.video) {
return getVideoLinks(og.video, whitelistRecord);
}
}
}
};