').append($el).html();
} else {
return '';
}
@@ -394,7 +394,7 @@
return [];
};
- exports.filterLinksByRel = function(rel, links, options) {
+ export function filterLinksByRel(rel, links, options) {
var options = options || {};
@@ -547,7 +547,7 @@
// Good link selection.
- var sortLinks = exports.sortLinks = function(links, autoplay_first, horizontal_first, mp4_first) {
+ export function sortLinks(links, autoplay_first, horizontal_first, mp4_first) {
var options = {
autoplay_first: autoplay_first,
@@ -676,7 +676,7 @@
});
}
- exports.findMainLink = function(iframely_data, options) {
+ export function findMainLink(iframely_data, options) {
var selectedLink;
@@ -702,6 +702,4 @@
}
return selectedLink;
- };
-
-})();
\ No newline at end of file
+ };
\ No newline at end of file
diff --git a/lib/loader/pluginLoader.js b/lib/loader/pluginLoader.js
index 0859149c1..0ce66a98e 100644
--- a/lib/loader/pluginLoader.js
+++ b/lib/loader/pluginLoader.js
@@ -1,15 +1,14 @@
-(function(pluginLoader) {
- var fs = require('fs'),
- path = require('path'),
- _ = require('underscore'),
- async = require('async'),
- url = require('url');
+ import * as fs from 'fs';
+ import * as path from 'path';
+ import * as node_jslint from 'jslint';
+ import { readFile } from 'fs/promises';
+ var JSLINT = node_jslint.load('latest');
+ import * as utils from './utils.js';
- var node_jslint = require('jslint'),
- JSLINT = node_jslint.load('latest');
-
- var utils = require('./utils');
+ import CONFIG from '../../config.loader.js';
+ // Global CONFIG used by plugins loaded during module import.
+ global.CONFIG = CONFIG;
var PLUGIN_METHODS = utils.PLUGIN_METHODS,
PLUGINS_FIELDS = utils.PLUGIN_FIELDS,
@@ -17,15 +16,25 @@
POST_PLUGIN_DEFAULT_PARAMS = utils.POST_PLUGIN_DEFAULT_PARAMS,
DEFAULT_PARAMS = utils.DEFAULT_PARAMS;
- var plugins = pluginLoader._plugins = {},
- providedParamsDict = pluginLoader._providedParamsDict = {},
- usedParamsDict = pluginLoader._usedParamsDict = {},
- templates = pluginLoader._templates = {},
+
+ const plugins = {},
+ providedParamsDict = {},
+ usedParamsDict = {},
+ templates = {},
metaMappings = {},
- pluginsList = pluginLoader._pluginsList = [],
- postPluginsList = pluginLoader._postPluginsList = [],
+ pluginsList = [],
+ postPluginsList = [],
pluginsByDomain = {};
+ export {
+ plugins as _plugins,
+ providedParamsDict as _providedParamsDict,
+ usedParamsDict as _usedParamsDict,
+ templates as _templates,
+ pluginsList as _pluginsList,
+ postPluginsList as _postPluginsList
+ };
+
/*
* ===================
* Loading plugins
@@ -134,7 +143,7 @@
return methods;
}
- function loadPluginFile(pluginPath) {
+ async function loadPluginFile(pluginPath) {
var bits = pluginPath.split(path.sep);
@@ -142,24 +151,33 @@
var plugin;
var pluginDeclaration = {};
+ var notPlugin = false;
+
+ var pluginLoadTimeout = setTimeout(() => {
+ console.error("-- Error: Timeout loading plugin " + pluginPath + ". Maybe recurring dependency.");
+ }, 1000);
// Load plugin.
try {
- plugin = require(pluginPath);
+ plugin = await import(pluginPath);
+ clearTimeout(pluginLoadTimeout);
+ if (plugin.notPlugin) {
+ notPlugin = true;
+ }
+ plugin = plugin && plugin.default;
} catch(ex) {
console.error("Error loading plugin", pluginPath, ex);
+ clearTimeout(pluginLoadTimeout);
return;
}
- if (plugin.notPlugin) {
+ if (notPlugin || plugin.notPlugin) {
// Skip utils modules.
return;
}
// Check if have required method.
- var hasSign = _.some(PLUGINS_FIELDS, function(sign) {
- return sign in plugin;
- });
+ var hasSign = PLUGINS_FIELDS.some(sign => sign in plugin);
if (!hasSign) {
console.warn("No plugin methods in " + pluginPath + ". Add exports.notPlugin = true; to skip this warning.");
return;
@@ -208,7 +226,7 @@
pluginDeclaration.re = [plugin.re];
} else if (plugin.re instanceof Array) {
- if (!_.every(plugin.re, function(re) { return re instanceof RegExp; })) {
+ if (!plugin.re.every(re => re instanceof RegExp)) {
console.error('Invalid RegExp in re of', pluginPath);
return;
}
@@ -327,11 +345,12 @@
for(var i = 0; i < mixins.length; i++) {
var mixin = mixins[i];
+ if (plugins[mixin]) {
+ var m = plugins[mixin].getPluginLastModifiedDate();
- var m = plugins[mixin].getPluginLastModifiedDate();
-
- if (m > modified) {
- modified = m;
+ if (m > modified) {
+ modified = m;
+ }
}
}
}
@@ -339,36 +358,36 @@
return modified;
}
- function loadPluginDir(pluginPath) {
+ async function loadPluginDir(pluginPath) {
// Scan plugin dir.
var plugins = fs.readdirSync(pluginPath);
- plugins.forEach(function(plugin_name) {
+ for (const plugin_name of plugins) {
var plugin = path.resolve(pluginPath, plugin_name);
var stats = fs.statSync(plugin);
if (stats.isFile()) {
- loadPluginFile(plugin);
+ await loadPluginFile(plugin);
}
- });
+ };
}
- function scanAllPluginsDir(modulePluginsPath) {
+ async function scanAllPluginsDir(modulePluginsPath) {
// Scan mudule plugins.
var plugins = fs.readdirSync(modulePluginsPath);
- plugins.forEach(function(plugin_name) {
+ for (const plugin_name of plugins) {
var plugin = path.resolve(modulePluginsPath, plugin_name);
var stats = fs.statSync(plugin);
if (stats.isFile()) {
- loadPluginFile(plugin);
+ await loadPluginFile(plugin);
} if (stats.isDirectory()) {
- loadPluginDir(plugin);
+ await loadPluginDir(plugin);
}
- });
+ };
}
function extractDomain(uri) {
@@ -406,7 +425,7 @@
return patterns;
}
- pluginLoader.findDomainPlugin = function(uri) {
+ export function findDomainPlugin(uri) {
var patterns = extractDomainPatterns(uri);
var record, i = 0;
@@ -418,7 +437,7 @@
return record;
};
- function scanModulesForPlugins() {
+ async function scanModulesForPlugins() {
// Scan node_modules dir.
var modulesRootPath = path.resolve('node_modules');
@@ -426,7 +445,7 @@
modules_listing.push(path.resolve('.'));
- modules_listing.forEach(function(modulePath) {
+ for (const modulePath of modules_listing) {
var modulePackagePath = path.resolve(modulePath, 'package.json');
@@ -434,43 +453,45 @@
// Scan plugins.
- var moduleInfo = require(modulePackagePath);
+
+ const moduleInfo = JSON.parse(await readFile(new URL(modulePackagePath, import.meta.url)));
+
if (!moduleInfo["iframely-proxy-plugins"]) {
- return;
+ continue;
}
- function loadPlugins() {
+ async function loadPlugins() {
var bits = Array.prototype.slice.call(arguments, 0);
bits.splice(0, 0, modulePath);
var modulePluginsPath = path.resolve.apply(path.resolve, bits);
if (fs.existsSync(modulePluginsPath)) {
- scanAllPluginsDir(modulePluginsPath);
+ await scanAllPluginsDir(modulePluginsPath);
}
}
- loadPlugins('plugins', 'domains');
- loadPlugins('plugins', 'custom');
- loadPlugins('plugins', 'links');
- loadPlugins('plugins', 'meta');
- loadPlugins('plugins', 'templates');
+ await loadPlugins('plugins', 'domains');
+ await loadPlugins('plugins', 'custom');
+ await loadPlugins('plugins', 'links');
+ await loadPlugins('plugins', 'meta');
+ await loadPlugins('plugins', 'templates');
// TODO: if has multiple modules_listing - CUSTOM_PLUGINS_PATH will be loaded multiple times.
if (CONFIG.CUSTOM_PLUGINS_PATH) {
if (fs.existsSync(CONFIG.CUSTOM_PLUGINS_PATH)) {
- loadPlugins(CONFIG.CUSTOM_PLUGINS_PATH, 'domains');
- loadPlugins(CONFIG.CUSTOM_PLUGINS_PATH, 'custom');
- loadPlugins(CONFIG.CUSTOM_PLUGINS_PATH, 'links');
- loadPlugins(CONFIG.CUSTOM_PLUGINS_PATH, 'meta');
- loadPlugins(CONFIG.CUSTOM_PLUGINS_PATH, 'templates');
+ await loadPlugins(CONFIG.CUSTOM_PLUGINS_PATH, 'domains');
+ await loadPlugins(CONFIG.CUSTOM_PLUGINS_PATH, 'custom');
+ await loadPlugins(CONFIG.CUSTOM_PLUGINS_PATH, 'links');
+ await loadPlugins(CONFIG.CUSTOM_PLUGINS_PATH, 'meta');
+ await loadPlugins(CONFIG.CUSTOM_PLUGINS_PATH, 'templates');
} else {
console.warn('Custom plugin folder "' + CONFIG.CUSTOM_PLUGINS_PATH + '" not found.');
}
}
- loadPlugins('lib', 'plugins', 'system');
- loadPlugins('lib', 'plugins', 'validators');
+ await loadPlugins('lib', 'plugins', 'system');
+ await loadPlugins('lib', 'plugins', 'validators');
}
- });
+ }
validateMixins();
validateDependencies();
@@ -542,13 +563,12 @@
}
});
- var keys = _.keys(metaMappingsNotSorted);
+ var keys = Object.keys(metaMappingsNotSorted);
keys.sort();
keys.forEach(function(key) {
metaMappings[key] = metaMappingsNotSorted[key];
});
}
- scanModulesForPlugins();
+ await scanModulesForPlugins();
-})(exports);
\ No newline at end of file
diff --git a/lib/loader/utils.js b/lib/loader/utils.js
index d8c1d8ef8..178d06726 100644
--- a/lib/loader/utils.js
+++ b/lib/loader/utils.js
@@ -1,24 +1,24 @@
-(function(utils) {
-
// TODO: not used anywhere.
- utils.DEFAULT_PARAMS = [
+ export const DEFAULT_PARAMS = [
"url",
"urlMatch",
"cb",
"options",
"request",
"whitelistRecord",
+ "iframelyRun",
"__readabilityEnabled"
];
- utils.POST_PLUGIN_DEFAULT_PARAMS = [
+ export const POST_PLUGIN_DEFAULT_PARAMS = [
"link",
"pluginContext",
- "pluginId",
+ "plugin",
+ "templates",
"iterationPluginContext"
];
- utils.PLUGIN_FIELDS_TYPE_DICT = {
+ export const PLUGIN_FIELDS_TYPE_DICT = {
"getLink": Function,
"getLinks": Function,
"getData": Function,
@@ -26,7 +26,7 @@
"mixins": Array
};
- utils.PLUGIN_METHODS = [
+ export const PLUGIN_METHODS = [
"getLink",
"getLinks",
"getData",
@@ -34,8 +34,6 @@
"prepareLink"
];
- utils.PLUGIN_FIELDS = utils.PLUGIN_METHODS.concat([
+ export const PLUGIN_FIELDS = PLUGIN_METHODS.concat([
"mixins"
- ]);
-
-})(exports);
\ No newline at end of file
+ ]);
\ No newline at end of file
diff --git a/lib/oembed.js b/lib/oembed.js
index 60b74f540..5c2c31d75 100644
--- a/lib/oembed.js
+++ b/lib/oembed.js
@@ -1,8 +1,7 @@
-var _ = require('underscore');
+import * as _ from 'underscore';
+import * as htmlUtils from './html-utils.js';
-var htmlUtils = require('./html-utils');
-
-exports.getOembed = function(uri, data, options) {
+export function getOembed(uri, data, options) {
if (!data) {
return;
diff --git a/lib/plugins/system/cheerio.js b/lib/plugins/system/cheerio.js
index a547d5848..d5832287e 100644
--- a/lib/plugins/system/cheerio.js
+++ b/lib/plugins/system/cheerio.js
@@ -1,8 +1,8 @@
-var cheerio = require('cheerio');
-var htmlparser2 = require("htmlparser2");
+import cheerio from 'cheerio';
+import htmlparser2 from "htmlparser2";
var DomHandler = htmlparser2.DomHandler;
-module.exports = {
+export default {
provides: 'self',
diff --git a/lib/plugins/system/decode.js b/lib/plugins/system/decode.js
index 1075cd4bd..e89f9e537 100644
--- a/lib/plugins/system/decode.js
+++ b/lib/plugins/system/decode.js
@@ -1,6 +1,6 @@
-var utils = require('../../utils');
+import * as utils from '../../utils.js';
-module.exports = {
+export default {
provides: 'self',
diff --git a/lib/plugins/system/htmlparser/CollectingHandlerForMutliTarget.js b/lib/plugins/system/htmlparser/CollectingHandlerForMutliTarget.js
index 0be2fde4c..efe915b80 100644
--- a/lib/plugins/system/htmlparser/CollectingHandlerForMutliTarget.js
+++ b/lib/plugins/system/htmlparser/CollectingHandlerForMutliTarget.js
@@ -5,39 +5,34 @@
*
* */
-function CollectingHandlerForMutliTarget(cbsArray){
+export function CollectingHandlerForMutliTarget(cbsArray){
this._cbsArray = cbsArray ||Â [];
this.events = [];
}
-var EVENTS = require("htmlparser2").EVENTS;
-
-Object.keys(EVENTS).forEach(function(name) {
-
- if (EVENTS[name] === 0) {
-
- name = "on" + name;
- CollectingHandlerForMutliTarget.prototype[name] = function() {
- this.emitCb([name]);
- };
-
- } else if (EVENTS[name] === 1) {
-
- name = "on" + name;
- CollectingHandlerForMutliTarget.prototype[name] = function(a) {
- this.emitCb([name, a]);
- };
-
- } else if (EVENTS[name] === 2) {
-
- name = "on" + name;
- CollectingHandlerForMutliTarget.prototype[name] = function(a, b) {
- this.emitCb([name, a, b]);
- };
-
- } else {
- throw Error("wrong number of arguments");
- }
+// Got from `export interface Handler {` (Parser.d.ts).
+const EVENTS = [
+ 'onparserinit',
+ 'onreset',
+ 'onend',
+ 'onerror',
+ 'onclosetag',
+ 'onopentagname',
+ 'onattribute',
+ 'onopentag',
+ 'ontext',
+ 'oncomment',
+ 'oncdatastart',
+ 'oncdataend',
+ 'oncommentend',
+ 'onprocessinginstruction',
+];
+
+EVENTS.forEach(function(name) {
+ CollectingHandlerForMutliTarget.prototype[name] = function() {
+ let args = [name, ...arguments];
+ this.emitCb(args);
+ };
});
CollectingHandlerForMutliTarget.prototype.addHandler = function(cbs) {
@@ -94,20 +89,9 @@ CollectingHandlerForMutliTarget.prototype._onreset = function(cbs) {
CollectingHandlerForMutliTarget.prototype.callCb = function(event, cbs) {
function cb(cbs) {
-
- if (cbs[event[0]]) {
-
- var num = event.length;
-
- if (num === 1) {
- cbs[event[0]]();
-
- } else if (num === 2) {
- cbs[event[0]](event[1]);
-
- } else {
- cbs[event[0]](event[1], event[2]);
- }
+ const name = event[0];
+ if (cbs[name]) {
+ cbs[name].apply(cbs, event.slice(1));
}
}
@@ -144,6 +128,4 @@ CollectingHandlerForMutliTarget.prototype._emitEventsFor = function(cbs) {
}
};
-module.exports = CollectingHandlerForMutliTarget;
-
-module.exports.notPlugin = true;
\ No newline at end of file
+export const notPlugin = true;
\ No newline at end of file
diff --git a/lib/plugins/system/htmlparser/htmlparser.js b/lib/plugins/system/htmlparser/htmlparser.js
index eb774da80..31c1c91d5 100644
--- a/lib/plugins/system/htmlparser/htmlparser.js
+++ b/lib/plugins/system/htmlparser/htmlparser.js
@@ -1,17 +1,14 @@
-var _ = require('underscore');
-var urlLib = require('url');
-var htmlparser2 = require('htmlparser2');
-var Parser = htmlparser2.Parser;
-
-var cache = require('../../../cache');
-var utils = require('../../../utils');
-var libUtils = require('../../../utils');
-var metaUtils = require('../meta/utils');
+import * as _ from 'underscore';
+import * as urlLib from 'url';
+import { Parser } from 'htmlparser2';
+import { cache } from '../../../cache.js';
+import * as utils from '../../../utils.js';
+import * as libUtils from '../../../utils.js';
+import * as metaUtils from '../meta/utils.js';
var getUrlFunctional = utils.getUrlFunctional;
+import { CollectingHandlerForMutliTarget } from './CollectingHandlerForMutliTarget.js';
-var CollectingHandlerForMutliTarget = require('./CollectingHandlerForMutliTarget');
-
-module.exports = {
+export default {
provides: [
'self',
@@ -21,8 +18,6 @@ module.exports = {
getData: function(url, whitelistRecord, options, __noCachedHtmlparserFallback, cb) {
- var request;
-
getUrlFunctional(url, _.extend({}, options, {
followRedirect: !!options.followHTTPRedirect
}), {
@@ -37,19 +32,17 @@ module.exports = {
});
}
},
- onRequest: function(req) {
- request = req;
- },
onResponse: function(resp) {
+
function cacheAndRespond(error, data, preventCache) {
var skip_cache = preventCache;
- if (CONFIG.TEMP_HTTP_ERROR_CODES.indexOf(resp.statusCode) > -1) {
+ if (CONFIG.TEMP_HTTP_ERROR_CODES.indexOf(resp.status) > -1) {
// Skip caching TEMP_HTTP_ERROR_CODES.
skip_cache = true;
}
- if (resp.statusCode >= 500 && resp.statusCode <= 599) {
+ if (resp.status >= 500 && resp.status <= 599) {
// Skip caching 5xx errors.
skip_cache = true;
}
@@ -88,43 +81,44 @@ module.exports = {
}
}
- if (resp.statusCode >= 300 && resp.statusCode < 400 && resp.headers.location) {
- utils.abortRequest(request);
- var redirectUrl = urlLib.resolve(url, resp.headers.location);
+ const headers = resp.headers;
+ const abortController = resp.abortController;
+
+ if (resp.status >= 300 && resp.status< 400 && headers.location) {
+ var redirectUrl = urlLib.resolve(url, headers.location);
// Prevent cache self redirect. Some sites changes cookies and stops redirect loop (e.g. https://miro.com/app/live-embed/o9J_lBwNMhI=/?embedAutoplay=true)
var preventCache = redirectUrl === url;
if (!options.exposeStatusCode) {
return cacheAndRespond({
- redirect: resp.headers.location
+ redirect: headers.location
}, null, preventCache);
} else {
return cacheAndRespond(null, {
- headers: resp.headers
+ headers: headers
});
}
}
- if (resp.statusCode !== 200) {
- utils.abortRequest(request);
+ if (resp.status !== 200) {
if (!!options.exposeStatusCode) {
return cacheAndRespond(null, {
- __statusCode: resp.statusCode,
- headers: resp.headers
+ __statusCode: resp.status,
+ headers: headers
});
} else {
return cacheAndRespond({
- responseStatusCode: resp.statusCode
+ responseStatusCode: resp.status
});
}
}
- if('content-type' in resp.headers && !/text\/html|application\/xhtml\+xml/gi.test(resp.headers['content-type'])){
- utils.abortRequest(request);
+ if('content-type' in headers && !/text\/html|application\/xhtml\+xml/gi.test(headers['content-type'])){
+ abortController.abort();
return cacheAndRespond(null, {
__nonHtmlContentData: {
- type: resp.headers['content-type'],
- content_length: resp.headers['content-length'],
- 'set-cookie': resp.headers['set-cookie']
+ type: headers['content-type'],
+ content_length: headers['content-length'],
+ 'set-cookie': headers['set-cookie']
}
});
}
@@ -132,19 +126,22 @@ module.exports = {
// Init htmlparser handler.
var handler = new CollectingHandlerForMutliTarget();
handler.onNoHandlers = function() {
- if (!request.response.isPaused()) {
- request.response.pause();
+ if (!resp.isPaused()) {
+ resp.pause();
}
};
handler.onFirstHandler = function() {
- if (request.response.isPaused()) {
- request.response.resume();
+ if (resp.isPaused()) {
+ resp.resume();
}
};
var parser = new Parser(handler, {
- lowerCaseTags: true
+ lowerCaseTags: true,
+ decodeEntities: false // Fixes decoding html characters like to UTF-8, we have own decoders.
});
- handler.request = request;
+ handler.headers = headers;
+ handler.abortController = abortController;
+ handler.h2 = resp.h2;
// Do before resume?
cb(null, {
diff --git a/lib/plugins/system/htmlparser/nonHtmlContentData.js b/lib/plugins/system/htmlparser/nonHtmlContentData.js
index 59623f5cf..efcc69793 100644
--- a/lib/plugins/system/htmlparser/nonHtmlContentData.js
+++ b/lib/plugins/system/htmlparser/nonHtmlContentData.js
@@ -1,6 +1,6 @@
-var sysUtils = require('../../../../logging');
+import log from '../../../../logging.js';
-module.exports = {
+export default {
provides: [
// Run for all who requests htmlparser or meta.
@@ -15,7 +15,7 @@ module.exports = {
// HEADS UP: do not ever remove the below check for 'javascript' or 'flash' in content type
// if left allowed, it'll make apps vulnerable for XSS attacks as such files will be rendered as regular embeds
if (/javascript|flash|application\/json|text\/xml|application\/xml/i.test(nonHtmlContentType)) {
- sysUtils.log(' -- Non html content type: "' + nonHtmlContentType + '" for ' + url);
+ log(' -- Non html content type: "' + nonHtmlContentType + '" for ' + url);
return cb({
responseStatusCode: 415
});
diff --git a/lib/plugins/system/ld.js b/lib/plugins/system/ld.js
index 320d7b1bb..1b92f1ed0 100644
--- a/lib/plugins/system/ld.js
+++ b/lib/plugins/system/ld.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
provides: 'self',
diff --git a/lib/plugins/system/meta/HTMLMetaHandler.js b/lib/plugins/system/meta/HTMLMetaHandler.js
index 20ccb5c28..abbb66886 100644
--- a/lib/plugins/system/meta/HTMLMetaHandler.js
+++ b/lib/plugins/system/meta/HTMLMetaHandler.js
@@ -1,10 +1,7 @@
-var decodeHTML5 = require('entities').decodeHTML5;
-var _ = require('underscore');
-var url = require('url');
-
-var utils = require('../../../utils');
-
-var ldParser = require('./ld-json');
+import { decodeHTML5 } from 'entities';
+import * as url from 'url';
+import * as utils from '../../../utils.js';
+import { ldParser } from './ld-json.js';
var getCharset = utils.getCharset;
var encodeText = utils.encodeText;
@@ -25,7 +22,7 @@ var LINK_REL_ARRAY_VALUES = [
'alternative'
];
-function HTMLMetaHandler(uri, contentType, callback) {
+export function HTMLMetaHandler(uri, contentType, callback) {
this._uri = uri;
this._charset = getCharset(contentType);
this._callback = callback;
@@ -325,7 +322,7 @@ HTMLMetaHandler.prototype._finalMerge = function(tag) {
function getSingleValue(parentName, obj) {
var key = getDefaultKey(parentName);
if (key in obj) {
- if (_.keys(obj).length === 1) {
+ if (Object.keys(obj).length === 1) {
return obj[key];
}
}
@@ -517,7 +514,7 @@ function merge(parentObj, props, value) {
// New node.
parentNode[currentNodeName] = value;
- } else if (_.isArray(parentNode[currentNodeName])) {
+ } else if (Array.isArray(parentNode[currentNodeName])) {
var append = false;
@@ -584,6 +581,4 @@ function merge(parentObj, props, value) {
}
}
-module.exports = HTMLMetaHandler;
-
-module.exports.notPlugin = true;
+export const notPlugin = true;
diff --git a/lib/plugins/system/meta/cachedMeta.js b/lib/plugins/system/meta/cachedMeta.js
index 2344d3178..968c5979a 100644
--- a/lib/plugins/system/meta/cachedMeta.js
+++ b/lib/plugins/system/meta/cachedMeta.js
@@ -1,10 +1,10 @@
-var urlLib = require('url');
-var cache = require('../../../cache');
-var sysUtils = require('../../../../logging');
-var utils = require('./utils');
-var libUtils = require('../../../utils');
+import * as urlLib from 'url';
+import { cache } from '../../../cache.js';
+import log from '../../../../logging.js';
+import * as utils from './utils.js';
+import * as libUtils from '../../../utils.js';
-module.exports = {
+export default {
provides: [
'__noCachedMeta',
@@ -35,7 +35,7 @@ module.exports = {
function callback(error, data) {
if (error) {
- sysUtils.log(' -- Error loading cached meta for: ' + url + '. ' + error);
+ log(' -- Error loading cached meta for: ' + url + '. ' + error);
}
function noCacheFound() {
@@ -56,7 +56,7 @@ module.exports = {
var record_age_sec = (new Date().getTime() / 1000) - data._sys_created_at;
if (record_age_sec > ttl) {
// Ignore cache older then requested ttl.
- sysUtils.log(' -- Disable using old cache for: ' + url);
+ log(' -- Disable using old cache for: ' + url);
return noCacheFound();
}
}
@@ -75,13 +75,13 @@ module.exports = {
}
// If data object has error attribute - return as error (e.g. redirect).
- sysUtils.log(' -- Using cached htmlparser error for: ' + url);
+ log(' -- Using cached htmlparser error for: ' + url);
cb(data.error);
} else if (data.htmlparser) {
- sysUtils.log(' -- Using cached htmlparser data for: ' + url);
+ log(' -- Using cached htmlparser data for: ' + url);
cb(null, data.htmlparser);
} else {
- sysUtils.log(' -- Using cached meta for: ' + url);
+ log(' -- Using cached meta for: ' + url);
cb(null, {
meta: data,
__hasCachedMeta: true,
diff --git a/lib/plugins/system/meta/ld-json.js b/lib/plugins/system/meta/ld-json.js
index a0e22e2fb..4f7c0ae7c 100644
--- a/lib/plugins/system/meta/ld-json.js
+++ b/lib/plugins/system/meta/ld-json.js
@@ -1,7 +1,7 @@
-const sysUtils = require('../../../../logging');
-const utils = require('../../../utils');
+import log from '../../../../logging.js';
+import * as utils from '../../../utils.js';
-module.exports = function(result, decode, uri) {
+export function ldParser(result, decode, uri) {
var ld = result["ld-json"];
delete result["ld-json"];
@@ -40,7 +40,7 @@ module.exports = function(result, decode, uri) {
} catch (ex) {
- sysUtils.log(' -- Error parsing ld-json', uri, ex.message);
+ log(' -- Error parsing ld-json', uri, ex.message);
}
}
@@ -51,4 +51,4 @@ module.exports = function(result, decode, uri) {
}
};
-module.exports.notPlugin = true;
\ No newline at end of file
+export const notPlugin = true;
\ No newline at end of file
diff --git a/lib/plugins/system/meta/meta.js b/lib/plugins/system/meta/meta.js
index 1a7c3a457..6f404abfb 100644
--- a/lib/plugins/system/meta/meta.js
+++ b/lib/plugins/system/meta/meta.js
@@ -1,11 +1,11 @@
-var HTMLMetaHandler = require('./HTMLMetaHandler');
-var cache = require('../../../cache');
-var sysUtils = require('../../../../logging');
-var libUtils = require('../../../utils');
-var iconv = require('iconv-lite');
-var utils = require('./utils');
+import { HTMLMetaHandler } from './HTMLMetaHandler.js';
+import { cache } from '../../../cache.js';
+import log from '../../../../logging.js';
+import * as libUtils from '../../../utils.js';
+import iconv from 'iconv-lite';
+import * as utils from './utils.js';
-module.exports = {
+export default {
provides: 'self',
@@ -13,7 +13,7 @@ module.exports = {
var metaHandler = new HTMLMetaHandler(
url,
- htmlparser.request.response.headers["content-type"],
+ htmlparser.headers["content-type"],
function(error, meta) {
htmlparser.removeHandler(metaHandler);
@@ -27,7 +27,7 @@ module.exports = {
// https://github.com/ashtuchkin/iconv-lite/issues/60
if (!iconv.encodingExists(meta.charset)) {
- sysUtils.log(' -- Unsupported encoding: ' + meta.charset + ' in ' + url);
+ log(' -- Unsupported encoding: ' + meta.charset + ' in ' + url);
return cb({
responseStatusCode: 415
});
@@ -46,7 +46,7 @@ module.exports = {
});
if (options.refresh) {
- sysUtils.log(' -- Refreshed meta cache for: ' + url);
+ log(' -- Refreshed meta cache for: ' + url);
}
}
diff --git a/lib/plugins/system/meta/utils.js b/lib/plugins/system/meta/utils.js
index 90305ab42..ff5c1fa70 100644
--- a/lib/plugins/system/meta/utils.js
+++ b/lib/plugins/system/meta/utils.js
@@ -1,4 +1,4 @@
-exports.getMetaCacheKey = function(url, whitelistRecord, options) {
+export function getMetaCacheKey(url, whitelistRecord, options) {
var meta_key = 'meta:' + url;
@@ -15,4 +15,4 @@ exports.getMetaCacheKey = function(url, whitelistRecord, options) {
return meta_key;
};
-module.exports.notPlugin = true;
\ No newline at end of file
+export const notPlugin = true;
\ No newline at end of file
diff --git a/lib/plugins/system/oembed/autoDiscovery.js b/lib/plugins/system/oembed/autoDiscovery.js
index 50bc9b54c..050963729 100644
--- a/lib/plugins/system/oembed/autoDiscovery.js
+++ b/lib/plugins/system/oembed/autoDiscovery.js
@@ -1,7 +1,7 @@
-const oembedUtils = require('./oembedUtils');
+import * as oembedUtils from './oembedUtils.js';
const RE = CONFIG.IGNORE_DOMAINS_RE || CONFIG.BLACKLIST_DOMAINS_RE;
-module.exports = {
+export default {
provides: 'oembedLinks',
diff --git a/lib/plugins/system/oembed/knownEndpoints.js b/lib/plugins/system/oembed/knownEndpoints.js
index a55fdb82b..b767eca7c 100644
--- a/lib/plugins/system/oembed/knownEndpoints.js
+++ b/lib/plugins/system/oembed/knownEndpoints.js
@@ -1,6 +1,6 @@
-var oembedUtils = require('./oembedUtils');
+import * as oembedUtils from './oembedUtils.js';
-module.exports = {
+export default {
provides: ['oembedLinks', '__noOembedLinks'],
diff --git a/lib/plugins/system/oembed/oembed.js b/lib/plugins/system/oembed/oembed.js
index 8026aca8e..63369052b 100644
--- a/lib/plugins/system/oembed/oembed.js
+++ b/lib/plugins/system/oembed/oembed.js
@@ -1,9 +1,9 @@
-const oembedUtils = require('./oembedUtils');
-const cheerio = require('cheerio');
-const entities = require('entities');
+import * as oembedUtils from './oembedUtils.js';
+import cheerio from 'cheerio';
-const URL = require('url');
-const querystring = require('querystring');
+import * as entities from 'entities';
+import * as URL from 'url';
+import * as querystring from 'querystring';
const pxRe = /^([\d\.]+)(?:px)?$/;
const percentRe = /^([\d\.]+)%$/;
@@ -51,11 +51,20 @@ function _getOembedIframe(oembed) {
oembed._iframe = fixOembedIframeAttributes($iframe[0].attribs);
if (oembed._iframe && oembed._iframe.src) {
- oembed._iframe.query = URL.parse(oembed._iframe.src, true).query;
+ var src = URL.parse(oembed._iframe.src, true);
+ oembed._iframe.host = src.host;
+ oembed._iframe.pathname = src.pathname;
+ oembed._iframe.path = src.path;
+ oembed._iframe.query = src.query;
+ oembed._iframe.placeholder = oembed.thumbnail_url;
oembed._iframe.replaceQuerystring = function(params) {
var qs = querystring.stringify({...oembed._iframe.query, ...params});
return oembed._iframe.src.replace(/\?.*$/, '') + (qs ? '?' + qs : '');
}
+ oembed._iframe.assignQuerystring = function(params) {
+ var qs = querystring.stringify(params);
+ return oembed._iframe.src.replace(/\?.*$/, '') + (qs ? '?' + qs : '');
+ }
}
} else {
oembed._iframe = null;
@@ -80,7 +89,7 @@ function getOembedIframeAttr(oembed) {
};
}
-module.exports = {
+export default {
provides: ['self', 'oembedError'],
diff --git a/lib/plugins/system/oembed/oembedUtils.js b/lib/plugins/system/oembed/oembedUtils.js
index 1c5030d3b..a59f9187b 100644
--- a/lib/plugins/system/oembed/oembedUtils.js
+++ b/lib/plugins/system/oembed/oembedUtils.js
@@ -1,17 +1,19 @@
-var sax = require('sax');
-var urlLib = require('url');
-var async = require('async');
-
-var utils = require('../../../utils');
-var sysUtils = require('../../../../logging');
-var cache = require('../../../cache');
+import sax from 'sax';
+import * as urlLib from 'url';
+import * as async from 'async';
+import * as utils from '../../../utils.js';
+import log from '../../../../logging.js';
+import { cache } from '../../../cache.js';
+import { readFile } from 'fs/promises';
var getUrlFunctional = utils.getUrlFunctional;
var getCharset = utils.getCharset;
var encodeText = utils.encodeText;
var lowerCaseKeys = utils.lowerCaseKeys;
-exports.notPlugin = true;
+export const notPlugin = true;
+
+const providers = JSON.parse(await readFile(new URL('./providers.json', import.meta.url)));
/**
* @private
@@ -20,8 +22,6 @@ exports.notPlugin = true;
* @return {String} The oembed uri
*/
function lookupStaticProviders(uri) {
- var providers = require('./providers.json');
-
var protocolMatch = uri.match(/^(https?:\/\/)/);
if (!protocolMatch || /^https?:\/\/blog\./i.test(uri)) {
return null;
@@ -83,7 +83,7 @@ function lookupStaticProviders(uri) {
return links;
}
-module.exports.findOembedLinks = function(uri, meta) {
+export function findOembedLinks(uri, meta) {
// Filter oembed from meta.
// allow misspelled discovery links
@@ -125,7 +125,7 @@ module.exports.findOembedLinks = function(uri, meta) {
* @param {String} uri Full oEmbed endpoint plus URL and any needed format parameter.
* @param {Function} callback Completion callback function. The callback gets two arguments (error, oembed) where oembed is json parsed oEmbed object.
* */
-module.exports.getOembed = function(uri, options, callback) {
+ export function getOembed(uri, options, callback) {
if (typeof options === 'function') {
callback = options;
@@ -181,7 +181,7 @@ module.exports.getOembed = function(uri, options, callback) {
// Fallback to `request` format. Remove after 10.10.2020.
var cachedError = (data && data.response && data.data && data.data.error) || (data && data.error);
if (cachedError) {
- sysUtils.log(' -- Oembed cache error: ' + uri, JSON.stringify(data));
+ log(' -- Oembed cache error: ' + uri, JSON.stringify(data));
}
if (data && !cachedError) {
@@ -189,7 +189,7 @@ module.exports.getOembed = function(uri, options, callback) {
// Fallback to `request` format. Remove after 10.10.2020.
data = data.data;
}
- sysUtils.log(' -- Using cached oembed for: ' + uri);
+ log(' -- Using cached oembed for: ' + uri);
return cb({good_data_from_cache: true}, data);
}
@@ -227,17 +227,15 @@ module.exports.getOembed = function(uri, options, callback) {
});
}
- getUrlFunctional(uri, {
- disableHttp2: options && options.disableHttp2
- }, {
+ getUrlFunctional(uri, {}, {
onError: cbWrapper,
onResponse: function(res) {
- if (res.statusCode == 200) {
+ if (res.status == 200) {
parseResponse(res);
} else if (options && options.parseErrorBody) {
- parseResponse(res, res.statusCode);
+ parseResponse(res, res.status);
} else {
- cbWrapper(res.statusCode);
+ cbWrapper(res.status);
}
}
});
@@ -354,7 +352,7 @@ function xmlStream2oembed(stream, callback) {
// Decode only non UTF-8 because sax makes decoding.
var oldValue = value;
value = encodeText(charset, value);
- sysUtils.log(' -- decode oembed xml (charset, in, out):', charset, oldValue, value);
+ log(' -- decode oembed xml (charset, in, out):', charset, oldValue, value);
}
if (prop.match(/(width|height)$/)) {
diff --git a/lib/plugins/system/og.js b/lib/plugins/system/og.js
index 21a24b7ed..abd626c9b 100644
--- a/lib/plugins/system/og.js
+++ b/lib/plugins/system/og.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
provides: 'self',
diff --git a/lib/plugins/system/readability.js b/lib/plugins/system/readability.js
index 226744e86..fdbd84d7e 100644
--- a/lib/plugins/system/readability.js
+++ b/lib/plugins/system/readability.js
@@ -1,6 +1,6 @@
-var Readability = require('readabilitySAX').Readability;
+import { Readability } from 'readabilitySAX';
-module.exports = {
+export default {
provides: 'self',
@@ -44,8 +44,6 @@ module.exports = {
readability.onend = onEnd;
htmlparser.addHandler(readability);
-
- htmlparser.request.response.on('onerror', cb);
}
};
\ No newline at end of file
diff --git a/lib/plugins/system/twitter.js b/lib/plugins/system/twitter.js
index 7d5b4e262..4c26e4ad0 100644
--- a/lib/plugins/system/twitter.js
+++ b/lib/plugins/system/twitter.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
provides: 'self',
diff --git a/lib/plugins/validators/async/20_checkFavicon.js b/lib/plugins/validators/async/20_checkFavicon.js
index 6ecce3aa0..6d095e783 100644
--- a/lib/plugins/validators/async/20_checkFavicon.js
+++ b/lib/plugins/validators/async/20_checkFavicon.js
@@ -1,10 +1,9 @@
-var urlLib = require('url');
-var _ = require('underscore');
+import * as urlLib from 'url';
+import * as _ from 'underscore';
+import * as utils from '../../../utils.js';
+import { cache } from '../../../cache.js';
-var utils = require('../../../utils');
-var cache = require('../../../cache');
-
-module.exports = {
+export default {
startIteration: function(iterationPluginContext) {
iterationPluginContext.multiCache = new cache.MultiCache();
diff --git a/lib/plugins/validators/async/21_checkContentType.js b/lib/plugins/validators/async/21_checkContentType.js
index 166ca7d90..5d01b1097 100644
--- a/lib/plugins/validators/async/21_checkContentType.js
+++ b/lib/plugins/validators/async/21_checkContentType.js
@@ -1,10 +1,10 @@
-const utils = require('../../../utils');
-const urlLib = require('url');
-const multimedia = require('../html5_multimedia');
-const mediaPlugin = require('../media');
-const player_no_scrolling = require('../player_no_scrolling');
+import * as utils from '../../../utils.js';
+import * as urlLib from 'url';
+import multimedia from '../html5_multimedia.js';
+import mediaPlugin from '../media.js';
+import player_no_scrolling from '../player_no_scrolling.js';
-module.exports = {
+export default {
prepareLink: function(url, link, options, pluginContext, cb) {
diff --git a/lib/plugins/validators/async/22_imageSize.js b/lib/plugins/validators/async/22_imageSize.js
index 797f3d5ad..9ea36e8d0 100644
--- a/lib/plugins/validators/async/22_imageSize.js
+++ b/lib/plugins/validators/async/22_imageSize.js
@@ -1,9 +1,9 @@
-const utils = require('../../../utils');
-const cache = require('../../../cache');
-const mediaPlugin = require('../media');
+import * as utils from '../../../utils.js';
+import { cache } from '../../../cache.js';
+import mediaPlugin from '../media.js';
-module.exports = {
+export default {
startIteration: function(iterationPluginContext) {
iterationPluginContext.multiCache = new cache.MultiCache();
diff --git a/lib/plugins/validators/html5_multimedia.js b/lib/plugins/validators/html5_multimedia.js
index 747d9e41d..08ecc65e0 100644
--- a/lib/plugins/validators/html5_multimedia.js
+++ b/lib/plugins/validators/html5_multimedia.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
prepareLink: function(link) {
diff --git a/lib/plugins/validators/media.js b/lib/plugins/validators/media.js
index 985e802b1..3880bde90 100644
--- a/lib/plugins/validators/media.js
+++ b/lib/plugins/validators/media.js
@@ -92,7 +92,7 @@ function moveMediaAttrs(link) {
}
}
-module.exports = {
+export default {
notPlugin: true,
diff --git a/lib/plugins/validators/player_no_scrolling.js b/lib/plugins/validators/player_no_scrolling.js
index fb65a851f..691655d9e 100644
--- a/lib/plugins/validators/player_no_scrolling.js
+++ b/lib/plugins/validators/player_no_scrolling.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
prepareLink: function(link) {
diff --git a/lib/plugins/validators/sync/00_validateLink.js b/lib/plugins/validators/sync/00_validateLink.js
index 5db62d447..f49dcfa26 100644
--- a/lib/plugins/validators/sync/00_validateLink.js
+++ b/lib/plugins/validators/sync/00_validateLink.js
@@ -1,6 +1,6 @@
-const urlLib = require('url');
+import * as urlLib from 'url';
-module.exports = {
+export default {
prepareLink: function(url, link) {
diff --git a/lib/plugins/validators/sync/01_qa_rels.js b/lib/plugins/validators/sync/01_qa_rels.js
index f204d8953..65e02a797 100644
--- a/lib/plugins/validators/sync/01_qa_rels.js
+++ b/lib/plugins/validators/sync/01_qa_rels.js
@@ -1,17 +1,12 @@
-var pluginLoader = require('../../../loader/pluginLoader'),
- plugins = pluginLoader._plugins;
+export default {
-module.exports = {
-
- prepareLink: function(whitelistRecord, options, link, pluginId) {
+ prepareLink: function(whitelistRecord, options, link, plugin) {
if (link.type === CONFIG.T.flash) {
link.error = 'Adobe Flash Player is no longer supported';
return;
}
- var plugin = plugins[pluginId];
-
if (plugin.domain || plugin.custom || (link.rel && (link.rel.indexOf(CONFIG.R.icon) > -1 || link.rel.indexOf(CONFIG.R.thumbnail) > -1))) {
return;
}
diff --git a/lib/plugins/validators/sync/02_html5_multimedia.js b/lib/plugins/validators/sync/02_html5_multimedia.js
index dbfb0bafc..d183dfc5b 100644
--- a/lib/plugins/validators/sync/02_html5_multimedia.js
+++ b/lib/plugins/validators/sync/02_html5_multimedia.js
@@ -1,6 +1,6 @@
-const multimedia = require('../html5_multimedia');
+import multimedia from '../html5_multimedia.js';
-module.exports = {
+export default {
prepareLink: function(link, options) {
multimedia.prepareLink(link, options);
diff --git a/lib/plugins/validators/sync/03_media.js b/lib/plugins/validators/sync/03_media.js
index 37b5e0812..183cfae28 100644
--- a/lib/plugins/validators/sync/03_media.js
+++ b/lib/plugins/validators/sync/03_media.js
@@ -1,6 +1,6 @@
-var mediaPlugin = require('../media');
+import mediaPlugin from '../media.js';
-module.exports = {
+export default {
prepareLink: function(link, options) {
diff --git a/lib/plugins/validators/sync/04_ssl_validator.js b/lib/plugins/validators/sync/04_ssl_validator.js
index 3821fe267..49d46d51a 100644
--- a/lib/plugins/validators/sync/04_ssl_validator.js
+++ b/lib/plugins/validators/sync/04_ssl_validator.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
prepareLink: function(link, url, options) {
diff --git a/lib/plugins/validators/sync/05_camoImage.js b/lib/plugins/validators/sync/05_camoImage.js
index 50db4e887..7bd1c8d31 100644
--- a/lib/plugins/validators/sync/05_camoImage.js
+++ b/lib/plugins/validators/sync/05_camoImage.js
@@ -1,8 +1,7 @@
/*
Should be last async plugin to prevent size check over camo.
*/
-
-var crypto = require('crypto');
+import * as crypto from 'crypto';
function isSSL(link) {
return link.rel.indexOf('ssl') > -1;
@@ -12,7 +11,7 @@ function isImage(link) {
return link.type.match(/^image/);
}
-module.exports = {
+export default {
// Get from default CONFIG. Not supposed to be enabled by dynamic custom provider options.
notPlugin: !CONFIG.providerOptions.camoProxy,
diff --git a/lib/plugins/validators/sync/06_autoplay.js b/lib/plugins/validators/sync/06_autoplay.js
index 2015e164f..2733bf16a 100644
--- a/lib/plugins/validators/sync/06_autoplay.js
+++ b/lib/plugins/validators/sync/06_autoplay.js
@@ -1,6 +1,6 @@
-var _ = require('underscore');
+import * as _ from 'underscore';
-module.exports = {
+export default {
prepareLink: function(link) {
diff --git a/lib/plugins/validators/sync/07_resizable.js b/lib/plugins/validators/sync/07_resizable.js
index 2f1a4f16e..14131b1bf 100644
--- a/lib/plugins/validators/sync/07_resizable.js
+++ b/lib/plugins/validators/sync/07_resizable.js
@@ -1,7 +1,7 @@
-const utils = require('../../../utils');
-const URL = require('url');
+import * as utils from '../../../utils.js';
+import * as URL from 'url';
-module.exports = {
+export default {
prepareLink: function(url, options, link) {
diff --git a/lib/plugins/validators/sync/08_render.js b/lib/plugins/validators/sync/08_render.js
index 9f985bc4e..41276c74b 100644
--- a/lib/plugins/validators/sync/08_render.js
+++ b/lib/plugins/validators/sync/08_render.js
@@ -1,15 +1,12 @@
-var ejs = require('ejs'),
- fs = require('fs');
+import * as ejs from 'ejs';
+import * as fs from 'fs';
-var pluginLoader = require('../../../loader/pluginLoader'),
- templates = pluginLoader._templates;
-
-module.exports = {
- prepareLink: function(link, pluginId) {
+export default {
+ prepareLink: function(link, plugin, templates) {
if (!link.href && !link.html && (link.template || link.template_context)) {
- var template = link.template || pluginId;
+ var template = link.template || plugin.id;
if (!(template in templates)) {
console.error("No template found: " + template);
diff --git a/lib/plugins/validators/sync/09_app_hml5.js b/lib/plugins/validators/sync/09_app_hml5.js
index 3bc64e21e..9ab459855 100644
--- a/lib/plugins/validators/sync/09_app_hml5.js
+++ b/lib/plugins/validators/sync/09_app_hml5.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
prepareLink: function(link) {
// Add 'html5' rel to 'app'.
diff --git a/lib/plugins/validators/sync/10_video_hml5.js b/lib/plugins/validators/sync/10_video_hml5.js
index 29e4920f8..0386bfea6 100644
--- a/lib/plugins/validators/sync/10_video_hml5.js
+++ b/lib/plugins/validators/sync/10_video_hml5.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
prepareLink: function(link) {
// Add 'html5' rel to 'video/*'.
diff --git a/lib/plugins/validators/sync/11_image_type_by_ext.js b/lib/plugins/validators/sync/11_image_type_by_ext.js
index 3555038e2..000ec43bc 100644
--- a/lib/plugins/validators/sync/11_image_type_by_ext.js
+++ b/lib/plugins/validators/sync/11_image_type_by_ext.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
prepareLink: function(link) {
diff --git a/lib/plugins/validators/sync/12_player_no_scrolling.js b/lib/plugins/validators/sync/12_player_no_scrolling.js
index da8581ade..494f19d8a 100644
--- a/lib/plugins/validators/sync/12_player_no_scrolling.js
+++ b/lib/plugins/validators/sync/12_player_no_scrolling.js
@@ -1,6 +1,6 @@
-const player_no_scrolling = require('../player_no_scrolling');
+import player_no_scrolling from '../player_no_scrolling.js';
-module.exports = {
+export default {
prepareLink: function(link, options) {
player_no_scrolling.prepareLink(link, options);
diff --git a/lib/plugins/validators/sync/14_options.js b/lib/plugins/validators/sync/14_options.js
index 680be6adc..175855bfe 100644
--- a/lib/plugins/validators/sync/14_options.js
+++ b/lib/plugins/validators/sync/14_options.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
prepareLink: function(link) {
diff --git a/lib/plugins/validators/sync/15_duplicateLink.js b/lib/plugins/validators/sync/15_duplicateLink.js
index af00028b9..2587163d7 100644
--- a/lib/plugins/validators/sync/15_duplicateLink.js
+++ b/lib/plugins/validators/sync/15_duplicateLink.js
@@ -1,4 +1,4 @@
-var _ = require('underscore');
+import * as _ from 'underscore';
function findBestMedia(m1, m2) {
@@ -57,7 +57,7 @@ function findBestMedia(m1, m2) {
return (m1.width > m2.width || m1.height > m2.height) ? m1 : m2;
}
-module.exports = {
+export default {
prepareLink: function(link, pluginContext) {
diff --git a/lib/request.js b/lib/request.js
index 4b6a1c096..657c87bdd 100644
--- a/lib/request.js
+++ b/lib/request.js
@@ -1,10 +1,9 @@
-var request = require('request');
-var _ = require('underscore');
-var crypto = require('crypto');
-var cache = require('./cache');
-var utils = require('./utils');
+import * as crypto from 'crypto';
+import { cache } from './cache.js';
+import * as utils from './utils.js';
+import log from '../logging.js';
-var sysUtils = require('../logging');
+import { fetchData } from './fetch.js';
var hash = function(value) {
return '"' + crypto.createHash('md5').update(value).digest("hex") + '"';
@@ -28,9 +27,23 @@ var hash = function(value) {
* - callback - final callback will called with data received from `prepareResult`.
*
* */
-module.exports = function(options, iframely_options, callback) {
- options = _.extend({}, options);
+/*
+
+TOOD:
+
+options:
+
+jar: false,
+limit: 1,
+
+oauth
+
+*/
+
+export default function(options, iframely_options, callback) {
+
+ options = Object.assign({}, options);
if (typeof options.prepareResult !== 'function') {
console.error('cached request call error: prepareResult not a function');
@@ -54,8 +67,6 @@ module.exports = function(options, iframely_options, callback) {
delete options.new_cache_key;
delete options.refresh;
- options.gzip = true;
-
var prefix = CONFIG.API_REQUEST_CACHE_PREFIX ? (CONFIG.API_REQUEST_CACHE_PREFIX + ':') : '';
var lang = iframely_options.getProviderOptions('locale');
@@ -67,23 +78,26 @@ module.exports = function(options, iframely_options, callback) {
function doRealRequest(secondAttempt) {
- request(utils.prepareRequestOptions(options, iframely_options), function(error, response, data) {
-
+ function finish(error, result) {
if (error) {
- var url = options.url || options.uri;
-
// Retry on ECONNRESET.
if (!secondAttempt && (error.code in CONFIG.HTTP2_RETRY_CODES)) {
- sysUtils.log(' -- request.js ' + error.code + ' first', url);
+ log(' -- request.js ' + error.code + ' first', options.uri);
process.nextTick(function() {
doRealRequest(true);
});
return;
} else if (secondAttempt && (error.code in CONFIG.HTTP2_RETRY_CODES)) {
- sysUtils.log(' -- request.js ' + error.code + ' second', url);
+ log(' -- request.js ' + error.code + ' second', options.uri);
}
}
+ const response = result && {
+ statusCode: result.status,
+ headers: result.headers
+ };
+ const data = result && result.data;
+
prepareResult(error, response, data, function(preparedError, preparedData) {
var doCaching;
@@ -122,7 +136,18 @@ module.exports = function(options, iframely_options, callback) {
// Send prepared data up.
callback(preparedError, preparedData);
});
- });
+ }
+
+ if (!options.headers || !options.headers['User-Agent']) {
+ options.headers = options.headers || {};
+ options.headers['User-Agent'] = CONFIG.USER_AGENT;
+ }
+
+ fetchData(utils.prepareRequestOptions(options, iframely_options))
+ .then(result => {
+ finish(null, result);
+ })
+ .catch(finish);
}
if (refresh) {
@@ -157,7 +182,7 @@ module.exports = function(options, iframely_options, callback) {
}
// Send cached data up.
- prepareResult(null, _.extend(data.response, {fromRequestCache: true}), data.data, callback);
+ prepareResult(null, Object.assign(data.response, {fromRequestCache: true}), data.data, callback);
if (new_cache_key) {
cache.set('req:' + prefix + new_cache_key, data, {
diff --git a/lib/utils.js b/lib/utils.js
index 00be2f252..595148192 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -1,26 +1,16 @@
-var events = require('events');
-var request = require('request');
-var Http2Agent = require('./agent-http2').Http2Agent;
-var zlib = require('zlib');
-var decompressStream = require('iltorb').decompressStream;
-var iconv = require('iconv-lite');
-var async = require('async');
-var imagesize = require('probe-image-size');
-var _ = require('underscore');
-
-var parseIsoDuration = require('parse-iso-duration');
-var entities = require('entities');
-
-var cache = require('./cache');
-var htmlUtils = require('./html-utils');
-
-var sysUtils = require('../logging');
-
-var http2Agent = new Http2Agent(/* options */);
-
-if (!global.CONFIG) {
- global.CONFIG = require('../config');
-}
+import * as events from 'events';
+import { fetchStream, fetchStreamKeepAlive, fetchStreamAuthorized } from './fetch.js';
+import * as iconv from 'iconv-lite';
+import * as async from 'async';
+import imagesize from 'probe-image-size';
+import * as _ from 'underscore';
+import * as parseIsoDuration from 'parse-iso-duration';
+import * as entities from 'entities';
+import { cache } from './cache.js';
+import * as htmlUtils from './html-utils.js';
+import log from '../logging.js';
+
+import CONFIG from '../config.loader.js';
function prepareEncodedUri(request_options, attr) {
var url = request_options[attr];
@@ -47,7 +37,7 @@ function maxTTL(ttl) {
return ttl;
}
-var getMaxCacheTTLOverride = exports.getMaxCacheTTLOverride = function(url, options) {
+export function getMaxCacheTTLOverride(url, options) {
var proxy = null;
if (CONFIG.PROXY || (options && options.proxy)) {
proxy = (options && options.proxy) || CONFIG.PROXY.find(p => {
@@ -57,7 +47,7 @@ var getMaxCacheTTLOverride = exports.getMaxCacheTTLOverride = function(url, opti
return proxy;
};
-var getMaxCacheTTL = exports.getMaxCacheTTL = function(url, options, default_min_ttl) {
+export function getMaxCacheTTL(url, options, default_min_ttl) {
var proxy = getMaxCacheTTLOverride(url, options);
var result = Math.max(fixTTL(options && options.cache_ttl), fixTTL(proxy && proxy.cache_ttl), fixTTL(default_min_ttl));
result = maxTTL(result);
@@ -72,24 +62,25 @@ var getMaxCacheTTL = exports.getMaxCacheTTL = function(url, options, default_min
return result;
};
-var prepareRequestOptions = exports.prepareRequestOptions = function(request_options, options) {
-
- var url = request_options.uri || request_options.url;
+export function prepareRequestOptions(request_options, options) {
- var disableHttp2 = options && options.disableHttp2 || CONFIG.DISABLE_HTTP2;
+ if (request_options.url && !request_options.uri) {
+ request_options.uri = request_options.url;
+ }
+ var uri = request_options.uri;
+ delete request_options.url;
if (CONFIG.PROXY || (options && options.proxy)) {
var proxy = (options && options.proxy) || CONFIG.PROXY.find(p => {
- return p && p.re && p.re.some(re => url.match(re));
+ return p && p.re && p.re.some(re => uri.match(re));
});
if (proxy) {
if (proxy.prerender && CONFIG.PRERENDER_URL) {
- delete request_options.uri;
- delete request_options.url;
- // `url` used above for agent check.
- url = CONFIG.PRERENDER_URL + encodeURIComponent(url);
- request_options.uri = url;
+ request_options.uri = CONFIG.PRERENDER_URL + encodeURIComponent(uri);
+
+ } else if (proxy.proxy && CONFIG.PROXY_URL) {
+ request_options.uri = CONFIG.PROXY_URL + encodeURIComponent(uri);
}
if (proxy.proxy_server) {
request_options.proxy = proxy.proxy_server;
@@ -106,62 +97,22 @@ var prepareRequestOptions = exports.prepareRequestOptions = function(request_opt
_.extend(request_options, proxy.request_options);
}
if (proxy.disable_http2) {
- disableHttp2 = true;
+ request_options.disable_http2 = true;
}
}
}
- if (!disableHttp2
- && !request_options.proxy
- && /^https:/.test(url)
- && (!request_options.method
- || request_options.method === 'GET'
- || request_options.method === 'HEAD')) {
- // http2 only for ssl and without proxy.
- request_options.agent = http2Agent;
- }
-
var lang = options && options.getProviderOptions && options.getProviderOptions('locale', 'en-US');
if (lang) {
request_options.headers = request_options.headers || {};
request_options.headers['Accept-Language'] = lang.replace('_', '-') + CONFIG.ACCEPT_LANGUAGE_SUFFIX;
}
- prepareEncodedUri(request_options, 'url');
prepareEncodedUri(request_options, 'uri');
return request_options;
};
-var getUrlFunctional = exports.getUrlFunctional = function(url, options, callbacks) {
-
- getUrl(url, options)
- .on('error', function(error, opts) {
-
- // Retry on ECONNRESET. Http2Agent will try with `http1` after this error.
- if (!options.secondAttempt && (error.code in CONFIG.HTTP2_RETRY_CODES)) {
- sysUtils.log(' -- getUrl ' + error.code + ' first', opts, url);
- process.nextTick(function() {
- getUrlFunctional(url, _.extend({}, options, {
- secondAttempt: true,
- disableHttp2: true
- }), callbacks);
- });
- return;
- } else if (options.secondAttempt && (error.code in CONFIG.HTTP2_RETRY_CODES)) {
- sysUtils.log(' -- getUrl ' + error.code + ' second', opts, url);
- }
-
- callbacks.onError && callbacks.onError(error);
- })
- .on('request', function(request) {
- callbacks.onRequest && callbacks.onRequest(request);
- })
- .on('response', function(response) {
- callbacks.onResponse && callbacks.onResponse(response);
- });
-}
-
/**
* @public
* Do HTTP GET request and handle redirects
@@ -172,178 +123,109 @@ var getUrlFunctional = exports.getUrlFunctional = function(url, options, callbac
* @param {Function} [callback] The completion callback function or events.EventEmitter object
* @returns {events.EventEmitter} The emitter object which emit error or response event
*/
-var getUrl = exports.getUrl = function(url, options) {
-
- var req = new events.EventEmitter();
+ export function getUrl(url, options, callbacks) {
var options = options || {};
- // Store cookies between redirects and requests.
- var jar = options.jar;
- if (!jar) {
- jar = request.jar();
+ var redirect, follow;
+ if (options.followRedirect) {
+ redirect = 'follow';
+ follow = options.maxRedirects || CONFIG.MAX_REDIRECTS;
+ }
+ if (options.followRedirect === false) {
+ redirect = 'manual';
+ follow = 0;
}
- process.nextTick(function() {
- try {
-
- var sslProtocol = /^(https:)?\/\//i.test(url);
-
- var request_options = prepareRequestOptions({
- uri: url,
- method: 'GET',
- headers: {
- 'User-Agent': options.user_agent || CONFIG.USER_AGENT,
- 'Connection': 'keep-alive',
- 'Accept-Encoding': 'gzip' + (sslProtocol ? ', br' : ''),
- 'Accept': '*/*'
- },
- maxRedirects: options.maxRedirects || CONFIG.MAX_REDIRECTS,
- timeout: options.timeout || CONFIG.RESPONSE_TIMEOUT,
- followRedirect: options.followRedirect,
- jar: jar
- }, options);
-
- var r = request(request_options)
- .on('error', function(error) {
- req.emit('error', error, {http2Agent: request_options.agent === http2Agent});
- })
- .on('response', function(res) {
-
- var contentEncoding = res.headers['content-encoding'];
- contentEncoding = contentEncoding && contentEncoding.trim().toLowerCase();
-
- var zlibOptions = {
- flush: zlib.Z_SYNC_FLUSH,
- finishFlush: zlib.Z_SYNC_FLUSH
- };
-
- if (contentEncoding === 'br') {
-
- var br = decompressStream();
-
- br.request = res.request;
- br.statusCode = res.statusCode;
- br.headers = res.headers;
-
- if (!options.asBuffer) {
- br.setEncoding("binary");
- }
-
- req.emit('response', br);
- res.pipe(br);
-
- } else if (contentEncoding === 'gzip' || contentEncoding === 'deflate') {
-
- var gunzip = contentEncoding === 'gzip' ? zlib.createGunzip(zlibOptions) : zlib.createInflate(zlibOptions);
-
- gunzip.request = res.request;
- gunzip.statusCode = res.statusCode;
- gunzip.headers = res.headers;
-
- if (!options.asBuffer) {
- gunzip.setEncoding("binary");
- }
-
- req.emit('response', gunzip);
- res.pipe(gunzip);
-
- } else {
-
- if (!options.asBuffer) {
- res.setEncoding("binary");
- }
-
- req.emit('response', res);
- }
- });
+ var request_options = prepareRequestOptions({
+ // TODO: jar: jar,
+
+ // Reviewed.
+ uri: url,
+ method: 'GET',
+ headers: {
+ 'User-Agent': options.user_agent || CONFIG.USER_AGENT,
+ 'Accept': '*/*'
+ },
+ timeout: options.timeout || CONFIG.RESPONSE_TIMEOUT,
+ redirect: redirect,
+ follow: follow
+ }, options);
- req.emit('request', r);
+ try {
+ fetchStreamKeepAlive(request_options)
+ .then(stream => {
+ if (!options.asBuffer) {
+ stream.setEncoding("binary");
+ }
+ callbacks.onResponse && callbacks.onResponse(stream);
+ })
+ .catch(error => {
+ callbacks.onError && callbacks.onError(error);
+ });
- } catch (ex) {
- console.error('Error on getUrl for', url, '.\n Error:' + ex);
- req.emit('error', ex);
- }
- });
- return req;
+ } catch (ex) {
+ console.error('Error on getUrl for', url, '.\n Error:' + ex);
+ callbacks.onError && callbacks.onError(ex);
+ }
};
-var getHeadFunctional = exports.getHeadFunctional = function(url, options, callbacks) {
-
- getHead(url, options)
- .on('error', function(error) {
-
- // Retry on ECONNRESET.
- if (!options.secondAttempt && (error.code in CONFIG.HTTP2_RETRY_CODES)) {
- sysUtils.log(' -- getHead ' + error.code + ' first', url);
- process.nextTick(function() {
- getHeadFunctional(url, _.extend({}, options, {secondAttempt: true}), callbacks);
- });
- return;
- } else if (options.secondAttempt && (error.code in CONFIG.HTTP2_RETRY_CODES)) {
- sysUtils.log(' -- getHead ' + error.code + ' second', url);
- }
-
- callbacks.onError && callbacks.onError(error);
- })
- .on('request', function(request) {
- callbacks.onRequest && callbacks.onRequest(request);
- })
- .on('response', function(response) {
- callbacks.onResponse && callbacks.onResponse(response);
- });
-}
-
-var getHead = function(url, options) {
+export const getUrlFunctional = getUrl;
- var req = new events.EventEmitter();
+var getHead = function(url, options, callbacks) {
var options = options || {};
+ // TODO:
// Store cookies between redirects and requests.
- var jar = options.jar;
- if (!jar) {
- jar = request.jar();
+ // var jar = options.jar;
+ // if (!jar) {
+ // jar = request.jar();
+ // }
+
+ var redirect, follow;
+ if (options.followRedirect) {
+ redirect = 'follow';
+ follow = options.maxRedirects || CONFIG.MAX_REDIRECTS;
}
+ if (options.followRedirect === false) {
+ redirect = 'manual';
+ follow = 0;
+ }
+
+ var request_options = prepareRequestOptions({
+ // jar: jar,
+
+ // Reviewed.
+ uri: url,
+ method: 'HEAD',
+ headers: {
+ 'User-Agent': CONFIG.USER_AGENT
+ },
+ timeout: options.timeout || CONFIG.RESPONSE_TIMEOUT,
+ redirect: redirect,
+ follow: follow
+ // No abort controller for head.
+ });
- process.nextTick(function() {
- try {
- var r = request(prepareRequestOptions({
- uri: url,
- method: 'HEAD',
- headers: {
- 'User-Agent': CONFIG.USER_AGENT,
- 'Connection': 'close'
- },
- maxRedirects: options.maxRedirects || CONFIG.MAX_REDIRECTS,
- timeout: options.timeout || CONFIG.RESPONSE_TIMEOUT,
- followRedirect: options.followRedirect,
- jar: jar,
- agentOptions: {
- // getHead called for video, need check certificate.
- rejectUnauthorized: true
- }
- }, {
- disableHttp2: options && options.disableHttp2
- }))
- .on('error', function(error) {
- req.emit('error', error);
- })
- .on('response', function(res) {
- req.emit('response', res);
- });
-
- req.emit('request', r);
+ try {
+ fetchStreamAuthorized(request_options)
+ .then(response => {
+ callbacks.onResponse && callbacks.onResponse(response);
+ })
+ .catch(error => {
+ callbacks.onError && callbacks.onError(error);
+ });
- } catch (ex) {
- console.error('Error on getHead for', url, '.\n Error:' + ex);
- req.emit('error', ex);
- }
- });
- return req;
+ } catch (ex) {
+ console.error('Error on getHead for', url, '.\n Error:' + ex);
+ callbacks.onError && callbacks.onError(ex);
+ }
};
-exports.getCharset = function(string, doNotParse) {
+export const getHeadFunctional = getHead;
+
+export function getCharset(string, doNotParse) {
var charset;
if (doNotParse) {
@@ -356,7 +238,7 @@ exports.getCharset = function(string, doNotParse) {
return charset;
};
-exports.encodeText = function(charset, text) {
+export function encodeText(charset, text) {
try {
var charset = charset || 'UTF-8';
@@ -382,7 +264,7 @@ exports.encodeText = function(charset, text) {
}
};
-exports.parseJSONSource = function(text, decode) {
+export function parseJSONSource(text, decode) {
try {
return JSON.parse(decode ? entities.decodeHTML(decode(text)) : entities.decodeHTML(text));
@@ -466,7 +348,7 @@ exports.parseJSONSource = function(text, decode) {
*
* error == 404 if not found.
* */
-exports.getImageMetadata = function(uri, options, callback){
+ export function getImageMetadata(uri, options, callback){
if (typeof options === 'function') {
callback = options;
@@ -478,7 +360,7 @@ exports.getImageMetadata = function(uri, options, callback){
cache.withCache("image-meta:" + uri, function(callback) {
var loadImageHead, imageResponseStarted, totalTime, timeout, contentLength;
- var requestInstance = null;
+ var abortController;
function finish(error, data) {
@@ -490,7 +372,7 @@ exports.getImageMetadata = function(uri, options, callback){
}
// We don't need more data. Abort causes error. timeout === null here so error will be skipped.
- abortRequest(requestInstance)
+ abortController && abortController.abort();
if (!error && !data) {
error = 404;
@@ -560,24 +442,22 @@ exports.getImageMetadata = function(uri, options, callback){
getUrlFunctional(uri, {
timeout: options.timeout || CONFIG.RESPONSE_TIMEOUT,
- asBuffer: true,
- disableHttp2: options && options.disableHttp2
+ asBuffer: true
}, {
- onRequest: function(req) {
- requestInstance = req;
- },
onResponse: function(res) {
+ abortController = res.abortController;
+
var content_type = res.headers['content-type'];
if (content_type && content_type !== 'application/octet-stream' && content_type !== 'binary/octet-stream') {
if (content_type.indexOf('image') === -1 && !uri.match(/\.(jpg|png|gif|webp)(\?.*)?$/i)) {
- return finishCb('invalid content type: ' + res.headers['content-type'], undefined, 'onResponse content_type');
+ return finishCb('invalid content type: ' + content_type, undefined, 'onResponse content_type');
}
}
- if (res.statusCode == 200) {
+ if (res.status == 200) {
if (options.debug) {
imageResponseStarted = totalTime();
}
@@ -589,7 +469,7 @@ exports.getImageMetadata = function(uri, options, callback){
finishCb(error, data, 'imagesize');
});
} else {
- finishCb(res.statusCode, undefined, 'onResponse !200');
+ finishCb(res.status, undefined, 'onResponse !200');
}
},
onError: function(error) {
@@ -621,7 +501,7 @@ exports.getImageMetadata = function(uri, options, callback){
}, callback);
};
-exports.getUriStatus = function(uri, options, callback) {
+export function getUriStatus(uri, options, callback) {
if (typeof options === 'function') {
callback = options;
@@ -664,7 +544,7 @@ exports.getUriStatus = function(uri, options, callback) {
time = createTimer();
}
- getUriStatus(uri, options, finish);
+ getUriStatusPrivate(uri, options, finish);
}, {
// Ignore proxy.cache_ttl, if options.cache_ttl === 0 - do not read from cache.
@@ -675,11 +555,11 @@ exports.getUriStatus = function(uri, options, callback) {
}, callback);
};
-exports.getContentType = function(uriForCache, uriOriginal, options, cb) {
+export function getContentType(uriForCache, uriOriginal, options, cb) {
cache.withCache("content-type:" + uriForCache, function(cb) {
- var timeout, requestInstance, totalTime;
+ var timeout, totalTime, abortController;
function finish(error, headers) {
@@ -691,7 +571,8 @@ exports.getContentType = function(uriForCache, uriOriginal, options, cb) {
}
// We don't need more data. Abort causes error. timeout === null here so error will be skipped.
- abortRequest(requestInstance);
+ // If 'abortController' not defined, then no request created?
+ abortController && abortController.abort();
var data = {};
@@ -742,14 +623,13 @@ exports.getContentType = function(uriForCache, uriOriginal, options, cb) {
var methodCaller = method && method === 'GET' ? getUrlFunctional : getHeadFunctional;
methodCaller(uriOriginal, {
- timeout: options.timeout || CONFIG.RESPONSE_TIMEOUT,
- disableHttp2: options && options.disableHttp2
+ timeout: options.timeout || CONFIG.RESPONSE_TIMEOUT
}, {
- onRequest: function(req) {
- requestInstance = req;
- },
onResponse: function(res) {
- var error = res.statusCode && res.statusCode != 200 ? res.statusCode : null;
+
+ abortController = res.abortController;
+
+ var error = res.status && res.status != 200 ? res.status : null;
if (!method
// If method HEAD is not allowed. ex. Amazon S3 (=403)
@@ -760,13 +640,15 @@ exports.getContentType = function(uriForCache, uriOriginal, options, cb) {
|| error >= 500
// Or ClourFront that gobbles up headers when checking CORS.
|| (res.headers && !res.headers['access-control-allow-origin']
- && res.headers.server === 'AmazonS3' && !error ))) {
+ && res.headers['server'] === 'AmazonS3' && !error ))) {
makeCall('GET');
return;
}
+ // TODO: what is res.request.href ?
+ // TODO: where used res.headers.location ?
if (res.request && res.request.href && res.headers && res.request.href !== uriOriginal) {
- res.headers.location = res.request.href;
+ //res.headers.location = res.request.href;
}
finish(error, res.headers);
@@ -787,7 +669,7 @@ exports.getContentType = function(uriForCache, uriOriginal, options, cb) {
}, cb);
};
-exports.unifyDuration = function(duration) {
+export function unifyDuration(duration) {
if (duration && typeof duration === 'string') {
if (duration.match(/^\d+$/)) {
@@ -810,9 +692,9 @@ var NOW = new Date().getTime();
var minDate = new Date(1990, 1);
-exports.unifyDate = function(date) {
+export function unifyDate(date) {
- if (_.isArray(date)) {
+ if (Array.isArray(date)) {
date = date[0];
}
@@ -868,7 +750,7 @@ exports.unifyDate = function(date) {
};
-var lowerCaseKeys = exports.lowerCaseKeys = function(obj) {
+export function lowerCaseKeys(obj) {
for (var k in obj) {
var lowerCaseKey = k.toLowerCase();
if (lowerCaseKey != k) {
@@ -882,7 +764,7 @@ var lowerCaseKeys = exports.lowerCaseKeys = function(obj) {
}
};
-exports.sendLogToWhitelist = function(uri, context) {
+export function sendLogToWhitelist(uri, context) {
const {meta, oembed, oembedLinks, whitelistRecord} = context;
@@ -939,23 +821,26 @@ exports.sendLogToWhitelist = function(uri, context) {
data.oembed = oembedHref;
}
- request({
+ // TODO: check options
+ fetchStream({
+ qs: data,
+
+ // Reviewed.
uri: CONFIG.WHITELIST_LOG_URL,
method: 'GET',
- qs: data
})
- .on('error', function(error) {
- console.error('Error logging url:', uri, error);
- })
- .on('response', function(res) {
- if (res.statusCode !== 200) {
- console.error('Error logging url:', uri, res.statusCode);
+ .then(res => {
+ if (res.status !== 200) {
+ console.error('Error logging url:', uri, res.status);
}
+ })
+ .catch(error => {
+ console.error('Error logging url:', uri, error);
});
}
};
-exports.filterLinks = function(data, options) {
+export function filterLinks(data, options) {
var links = data.links;
@@ -1039,7 +924,7 @@ function iterateLinks(links, func) {
}
}
-exports.generateLinksHtml = function(data, options) {
+export function generateLinksHtml(data, options) {
// Links may be grouped.
@@ -1106,26 +991,30 @@ exports.generateLinksHtml = function(data, options) {
// Private
//====================================================================================
-var getUriStatus = function(uri, options, cb) {
+var getUriStatusPrivate = function(uri, options, cb) {
+
+ var request_options = prepareRequestOptions({
+ // TODO:
+ //jar: request.jar(), //Enable cookies, uses new jar
+
+
+ // Reviewed.
+ uri: uri,
+ method: 'GET',
+ headers: {
+ 'User-Agent': CONFIG.USER_AGENT
+ },
+ timeout: options.timeout || CONFIG.RESPONSE_TIMEOUT,
+ follow: CONFIG.MAX_REDIRECTS
+ })
try {
- var r = request(prepareRequestOptions({
- uri: uri,
- method: 'GET',
- headers: {
- 'User-Agent': CONFIG.USER_AGENT
- },
- maxRedirects: CONFIG.MAX_REDIRECTS,
- timeout: options.timeout || CONFIG.RESPONSE_TIMEOUT,
- jar: request.jar() //Enable cookies, uses new jar
- }, {
- disableHttp2: options.disableHttp2
- }))
- .on('error', cb)
- .on('response', function(res) {
- abortRequest(r);
+ fetchStream(request_options)
+ .then(res => {
+ // TODO: may cause AbortError before cb.
+ res.abortController.abort();
var data = {
- code: res.statusCode,
+ code: res.status,
content_type: res.headers && res.headers['content-type'],
content_length: res.headers && res.headers['content-length'] ? parseInt(res.headers['content-length'] || '0', 10) : null
};
@@ -1133,14 +1022,14 @@ var getUriStatus = function(uri, options, cb) {
data.headers = res.headers;
}
cb(null, data);
- });
-
+ })
+ .catch(cb)
} catch (ex) {
cb(ex.message);
}
};
-var createTimer = exports.createTimer = function() {
+export function createTimer() {
var timer = new Date().getTime();
@@ -1260,7 +1149,7 @@ function getWhitelistLogData(meta, oembed) {
return hasTrue && result;
}
-exports.getIframelyErrorShortCode = function(error) {
+export function getIframelyErrorShortCode(error) {
if (error.responseCode) {
// 'http error'
@@ -1275,21 +1164,12 @@ exports.getIframelyErrorShortCode = function(error) {
return error.code;
};
-var abortRequest = exports.abortRequest = function(request) {
- if (request && request.response && request.response.h2) {
- // Abort http2 with special method.
- request.response.abort();
- } else if (request && !request.aborted) {
- request.abort();
- }
-};
-
/**
* @public
* Generate slug for provider based on domain name of URL provided
* @param url Request uri string
*/
-exports.getProviderName = function(url) {
+export function getProviderName(url) {
try {
var domain = url.match(/^https?:\/\/([^\/\?#]+)/)[1];
diff --git a/lib/whitelist.js b/lib/whitelist.js
index 15b356b3d..ed01ec165 100644
--- a/lib/whitelist.js
+++ b/lib/whitelist.js
@@ -1,13 +1,19 @@
-(function(whitelist) {
+ import * as chokidar from 'chokidar';
+ import * as fs from 'fs';
+ import * as path from 'path';
+ import * as crypto from 'crypto';
+ import * as _ from 'underscore';
+ import * as utils from './utils.js';
+ import log from '../logging.js';
+ import request from 'request';
- var chokidar = require('chokidar'),
- fs = require('fs'),
- path = require('path'),
- crypto = require('crypto'),
- _ = require('underscore'),
- request = require('request'),
- utils = require('./utils'),
- logging = require('../logging');
+ import { fileURLToPath } from 'url';
+ import { dirname } from 'path';
+
+ import CONFIG from '../config.loader.js';
+
+ const __filename = fileURLToPath(import.meta.url);
+ const __dirname = dirname(__filename);
var whitelistObject = {domains: {}};
var whitelistLastModified;
@@ -93,7 +99,7 @@
return hash(JSON.stringify(data));
}
- whitelist.findRawWhitelistRecordFor = function(uri) {
+ export function findRawWhitelistRecordFor(uri) {
if (!whitelistObject || !whitelistObject.domains) {
return null;
@@ -110,7 +116,7 @@
return record;
};
- whitelist.findWhitelistRecordFor = function(uri, options) {
+ export function findWhitelistRecordFor(uri, options) {
if (!whitelistObject) {
return null;
@@ -165,7 +171,7 @@
return record;
};
- whitelist.getWhitelistObject = function() {
+ export function getWhitelistObject() {
return whitelistObject;
};
@@ -231,7 +237,7 @@
addWildcard();
- logging.log('Whitelist activated. Domains, including blacklisted:', _.keys(data.domains).length);
+ log('Whitelist activated. Domains, including blacklisted:', Object.keys(data.domains).length);
}
function readWhitelist(filename) {
@@ -333,7 +339,7 @@
if (!currentWhitelistFilename && CONFIG.WHITELIST_URL && CONFIG.WHITELIST_URL_RELOAD_PERIOD) {
- logging.log("Loading whitelist from " + CONFIG.WHITELIST_URL);
+ log("Loading whitelist from " + CONFIG.WHITELIST_URL);
var options = {
uri: CONFIG.WHITELIST_URL,
@@ -346,6 +352,7 @@
// Prevent caching.
'Cache-Control': 'no-cache'
},
+ // TODO: remove in helix-fetch
gzip: true
};
@@ -360,7 +367,7 @@
} else if (r.statusCode === 500) {
console.error('Error loading whitelist from ' + CONFIG.WHITELIST_URL + ' : ' + newWhitelist);
} else if (r.statusCode === 304) {
- logging.log('Whitelist respond: 304 (not modified)');
+ log('Whitelist respond: 304 (not modified)');
} else if (!newWhitelist || typeof newWhitelist === 'string') {
console.error('Error loading whitelist from ' + CONFIG.WHITELIST_URL + ' : incorrect data: ' + newWhitelist);
} else {
@@ -373,6 +380,4 @@
setTimeout(loadWhitelistUrl, CONFIG.WHITELIST_URL_RELOAD_PERIOD);
});
}
- }
-
-})(exports);
+ }
\ No newline at end of file
diff --git a/logging.js b/logging.js
index 3b0947d26..74d9e68d2 100644
--- a/logging.js
+++ b/logging.js
@@ -1,6 +1,6 @@
-var moment = require('moment');
+import moment from 'moment';
-exports.log = function() {
+export default function log() {
var args = Array.prototype.slice.apply(arguments);
// Add ip if request provided.
diff --git a/modules/api/utils.js b/modules/api/utils.js
index e0993d69b..a2f2d23c2 100644
--- a/modules/api/utils.js
+++ b/modules/api/utils.js
@@ -1,6 +1,6 @@
var _RE = /^_.+/;
-exports.getProviderOptionsQuery = function(query) {
+export function getProviderOptionsQuery(query) {
var providerOptionsQuery = {};
for(var key in query) {
@@ -28,7 +28,7 @@ function normalizeValue(value) {
return value;
}
-exports.getProviderOptionsFromQuery = function(query) {
+export function getProviderOptionsFromQuery(query) {
/*
Convert '_option=value' to
providerOptions = {
diff --git a/modules/api/views.js b/modules/api/views.js
index 181296716..76ca0ac08 100644
--- a/modules/api/views.js
+++ b/modules/api/views.js
@@ -1,15 +1,15 @@
-var iframelyCore = require('../../lib/core');
-var utils = require('../../utils');
-var _ = require('underscore');
-var async = require('async');
-var cache = require('../../lib/cache');
-var iframelyUtils = require('../../lib/utils');
-var oembedUtils = require('../../lib/oembed');
-var whitelist = require('../../lib/whitelist');
-var pluginLoader = require('../../lib/loader/pluginLoader');
-var jsonxml = require('jsontoxml');
-var url = require('url');
-var apiUtils = require('./utils');
+import * as iframelyCore from '../../lib/core.js';
+import * as utils from '../../utils.js';
+import * as _ from 'underscore';
+import * as async from 'async';
+import { cache } from '../../lib/cache.js';
+import * as iframelyUtils from '../../lib/utils.js';
+import * as oembedUtils from '../../lib/oembed.js';
+import * as whitelist from '../../lib/whitelist.js';
+import * as pluginLoader from '../../lib/loader/pluginLoader.js';
+import * as jsonxml from 'jsontoxml';
+import * as url from 'url';
+import * as apiUtils from './utils.js';
var getProviderOptionsQuery = apiUtils.getProviderOptionsQuery;
var getProviderOptionsFromQuery = apiUtils.getProviderOptionsFromQuery;
@@ -35,7 +35,9 @@ function prepareUri(uri) {
var log = utils.log;
-var version = require('../../package.json').version;
+import { readFile } from 'fs/promises';
+const json = JSON.parse(await readFile(new URL('../../package.json', import.meta.url)));
+var version = json.version;
function getRenderLinkCacheKey(uri, req) {
var query = getProviderOptionsQuery(req.query);
@@ -106,7 +108,7 @@ function processInitialErrors(uri, next) {
}
}
-module.exports = function(app) {
+export default function(app) {
app.get('/iframely', function(req, res, next) {
diff --git a/modules/debug/views.js b/modules/debug/views.js
index 5b9314aa6..9aae734da 100644
--- a/modules/debug/views.js
+++ b/modules/debug/views.js
@@ -1,6 +1,6 @@
-var getProviderOptionsQuery = require('../api/utils').getProviderOptionsQuery;
+import { getProviderOptionsQuery } from '../api/utils.js';
-module.exports = function(app) {
+export default function(app) {
app.get('/debug', function(req, res, next) {
diff --git a/modules/tests-ui/models.js b/modules/tests-ui/models.js
index 890e2cf32..46f00f783 100644
--- a/modules/tests-ui/models.js
+++ b/modules/tests-ui/models.js
@@ -1,28 +1,15 @@
-(function() {
-
- if (!CONFIG.tests) {
- return;
+ import moment from 'moment';
+ import mongoose from 'mongoose';
+ import CONFIG from '../../config.loader.js';
+
+ mongoose.set('useUnifiedTopology', true);
+ mongoose.set('useCreateIndex', true);
+ mongoose.set('useNewUrlParser', true);
+ if (global.Promise) {
+ mongoose.Promise = global.Promise;
}
- var moment = require('moment');
-
- var mongoose, db;
-
- // DB connect.
- try {
- mongoose = require('mongoose');
- mongoose.set('useUnifiedTopology', true);
- mongoose.set('useCreateIndex', true);
- mongoose.set('useNewUrlParser', true);
- if (global.Promise) {
- mongoose.Promise = global.Promise;
- }
- db = mongoose.createConnection(CONFIG.tests.mongodb);
- } catch (ex) {
- console.error("Plugins testing framework will not work. Can't connect to mongodb.");
- console.error(ex.stack);
- return;
- }
+ const db = mongoose.createConnection(CONFIG.tests.mongodb);
var Schema = mongoose.Schema;
@@ -169,9 +156,7 @@
return moment(this.created_at).format("DD-MM-YY HH:mm");
};
- exports.PluginTest = db.model('PluginTest', PluginTestSchema);
- exports.PageTestLog = db.model('PageTestLog', PageTestLogSchema);
- exports.TestUrlsSet = db.model('TestUrlsSet', TestUrlsSetSchema);
- exports.TestingProgress = db.model('TestingProgress', TestingProgressSchema);
-
-})();
\ No newline at end of file
+ export const PluginTest = db.model('PluginTest', PluginTestSchema);
+ export const PageTestLog = db.model('PageTestLog', PageTestLogSchema);
+ export const TestUrlsSet = db.model('TestUrlsSet', TestUrlsSetSchema);
+ export const TestingProgress = db.model('TestingProgress', TestingProgressSchema);
\ No newline at end of file
diff --git a/modules/tests-ui/tester.js b/modules/tests-ui/tester.js
index 8fb7a9fe6..01c7f2048 100644
--- a/modules/tests-ui/tester.js
+++ b/modules/tests-ui/tester.js
@@ -1,23 +1,21 @@
-global.CONFIG = require('../../config');
+import CONFIG from '../../config.loader.js';
+global.CONFIG = CONFIG;
if (!CONFIG.tests) {
console.error('Tests not started: CONFIG.tests not configured.');
process.exit(0);
- return;
+ // return;
}
process.title = "iframely-tests";
-process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
-var async = require('async');
-var _ = require('underscore');
-
-var models = require('./models');
-var utils = require('./utils');
-
-var iframely = require('../../lib/core').run;
-var whitelist = require('../../lib/whitelist');
-var pluginLoader = require('../../lib/loader/pluginLoader');
+import * as async from 'async';
+import * as _ from 'underscore';
+import * as models from './models.js';
+import * as utils from './utils.js';
+import { run as iframely } from '../../lib/core.js';
+import * as whitelist from '../../lib/whitelist.js';
+import * as pluginLoader from '../../lib/loader/pluginLoader.js';
var plugins = pluginLoader._plugins;
var testOnePlugin = false;
@@ -49,11 +47,6 @@ var PageTestLog = models.PageTestLog;
var TestUrlsSet = models.TestUrlsSet;
var TestingProgress = models.TestingProgress;
-if (!PluginTest) {
- process.exit(0);
- return;
-}
-
function log() {
if (CONFIG.DEBUG) {
console.log.apply(console, arguments);
diff --git a/modules/tests-ui/utils.js b/modules/tests-ui/utils.js
index 388040982..6d0f58308 100644
--- a/modules/tests-ui/utils.js
+++ b/modules/tests-ui/utils.js
@@ -1,20 +1,14 @@
-var _ = require('underscore');
-var FeedParser = require('feedparser');
-var request = require('request');
-var async = require('async');
-var url = require('url');
+import * as _ from 'underscore';
+import FeedParser from 'feedparser';
+import request from 'request';
+import * as async from 'async';
+import * as url from 'url';
+import { PageTestLog, TestUrlsSet, PluginTest } from './models.js';
+import { findWhitelistRecordFor } from '../../lib/whitelist.js';
+import { getPluginData as iframelyGetPluginData } from '../../lib/core.js';
+import * as pluginLoader from '../../lib/loader/pluginLoader.js';
+import * as pluginUtils from '../../lib/loader/utils.js';
-var models = require('./models');
-var PageTestLog = models.PageTestLog;
-var TestUrlsSet = models.TestUrlsSet;
-var PluginTest = models.PluginTest;
-
-var findWhitelistRecordFor = require('../../lib/whitelist').findWhitelistRecordFor;
-
-var iframelyGetPluginData = require('../../lib/core').getPluginData;
-
-var pluginLoader = require('../../lib/loader/pluginLoader');
-var pluginUtils = require('../../lib/loader/utils');
var plugins = pluginLoader._plugins,
pluginsList = pluginLoader._pluginsList,
DEFAULT_PARAMS = [].concat(pluginUtils.DEFAULT_PARAMS, pluginUtils.POST_PLUGIN_DEFAULT_PARAMS),
@@ -37,7 +31,7 @@ const COLORS = {
const SLACK_USERNAME = "Testy";
-exports.sendQANotification = function(logEntry, data) {
+export function sendQANotification(logEntry, data) {
if (CONFIG.SLACK_WEBHOOK_FOR_QA && CONFIG.SLACK_CHANNEL_FOR_QA) {
@@ -93,7 +87,7 @@ exports.sendQANotification = function(logEntry, data) {
}
function getTestsSummary(cb) {
- exports.loadPluginTests(function(error, pluginTests) {
+ loadPluginTests(function(error, pluginTests) {
pluginTests.forEach(function(pluginTest) {
@@ -129,7 +123,7 @@ function getTestsSummary(cb) {
});
}
-exports.loadPluginTests = function(cb) {
+export function loadPluginTests(cb) {
var pluginTests;
@@ -216,7 +210,7 @@ exports.loadPluginTests = function(cb) {
});
}
-exports.getPluginUnusedMethods = function(pluginId, debugData) {
+export function getPluginUnusedMethods(pluginId, debugData) {
var usedMethods = getAllUsedMethods(debugData);
var pluginMethods = findAllPluginMethods(pluginId, plugins);
@@ -228,7 +222,7 @@ exports.getPluginUnusedMethods = function(pluginId, debugData) {
};
};
-exports.getErrors = function(debugData) {
+export function getErrors(debugData) {
var errors = [];
@@ -248,7 +242,7 @@ exports.getErrors = function(debugData) {
var MAX_FEED_URLS = 5;
-var fetchFeedUrls = exports.fetchFeedUrls = function(feedUrl, options, cb) {
+export function fetchFeedUrls(feedUrl, options, cb) {
if (typeof options === "function") {
cb = options;
@@ -266,7 +260,12 @@ var fetchFeedUrls = exports.fetchFeedUrls = function(feedUrl, options, cb) {
cb(error, urls);
};
- request(feedUrl)
+ request({
+ uri: feedUrl,
+ agentOptions: {
+ rejectUnauthorized: false
+ }
+ })
.pipe(new FeedParser({addmeta: false}))
.on('error', function(error) {
_cb(error);
@@ -300,7 +299,7 @@ var fetchFeedUrls = exports.fetchFeedUrls = function(feedUrl, options, cb) {
});
};
-exports.fetchUrlsByPageOnFeed = function(pageWithFeed, otpions, cb) {
+export function fetchUrlsByPageOnFeed(pageWithFeed, otpions, cb) {
if (typeof options === "function") {
cb = options;
@@ -343,7 +342,7 @@ exports.fetchUrlsByPageOnFeed = function(pageWithFeed, otpions, cb) {
], cb);
};
-exports.fetchUrlsByPageAndSelector = function(page, selector, options, cb) {
+export function fetchUrlsByPageAndSelector(page, selector, options, cb) {
if (typeof options === "function") {
cb = options;
@@ -356,14 +355,14 @@ exports.fetchUrlsByPageAndSelector = function(page, selector, options, cb) {
iframelyGetPluginData(page, 'cheerio', findWhitelistRecordFor, cb);
},
- function($, cb) {
+ function(cheerio, cb) {
- var $links = $(selector);
+ var $links = cheerio(selector);
var urls = [];
$links.each(function() {
if (urls.length < MAX_FEED_URLS) {
- var href = $(this).attr(options.urlAttribute || "href");
+ var href = cheerio(this).attr(options.urlAttribute || "href");
if (href) {
var href = url.resolve(page, href);
if (urls.indexOf(href) == -1) {
diff --git a/modules/tests-ui/views.js b/modules/tests-ui/views.js
index 8f4702826..ba411589e 100644
--- a/modules/tests-ui/views.js
+++ b/modules/tests-ui/views.js
@@ -1,22 +1,14 @@
-(function() {
-
- if (!CONFIG.tests) {
- module.exports = function(){};
- return;
- }
-
- var async = require('async');
- var moment = require('moment');
- var _ = require('underscore');
- var exec = require('child_process').exec;
-
- var models = require('./models');
- var utils = require('./utils');
+ import * as async from 'async';
+ import moment from 'moment';
+ import * as _ from 'underscore';
+ import { exec as exec } from 'child_process';
+ import * as models from './models.js';
+ import * as utils from './utils.js';
var PluginTest = models.PluginTest;
var TestingProgress = models.TestingProgress;
- module.exports = function(app){
+ export default function(app){
app.get('/tests/run/:plugin', function(req, res, next) {
@@ -158,5 +150,4 @@
});
});
});
- }
-})();
+ }
\ No newline at end of file
diff --git a/package.json b/package.json
index 11cef840c..239fa5d46 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,7 @@
{
"name": "iframely",
"version": "1.6.1",
+ "type": "module",
"description": "oEmbed/2 gateway endpoint. Get embed data for various http links through one self-hosted API",
"keywords": [
"oembed",
@@ -19,17 +20,17 @@
},
"license": "MIT",
"dependencies": {
+ "@adobe/helix-fetch": "^3.0.0",
"async": "2.4.1",
- "cheerio": "0.22.0",
+ "cheerio": "^0.22.0",
"chokidar": "^3.3.1",
"ejs": "^3.1.6",
"entities": "1.1.1",
"express": "^4.16.3",
+ "globby": "^12.0.2",
"graceful-cluster": "0.0.3",
- "htmlparser2": "3.9.2",
- "http-parser-js": "itteco/http-parser-js#magicode-fix-22",
- "iconv-lite": "0.4.17",
- "iltorb": "^2.4.3",
+ "htmlparser2": "^7.1.2",
+ "iconv-lite": "^0.6.3",
"jslint": "^0.12.1",
"jsontoxml": "0.0.11",
"memcached": "2.2.2",
@@ -55,7 +56,7 @@
"supertest": "^4.0.2"
},
"iframely-proxy-plugins": true,
- "main": "./lib/core",
+ "main": "./lib/core.js",
"scripts": {
"test": "npm run test-core-plugins && npm run test-e2e",
"test-core-plugins": "mocha --exit test/core-plugins.js",
diff --git a/plugins/custom/domain-icon.js b/plugins/custom/domain-icon.js
index 1b4b332a7..f99571706 100644
--- a/plugins/custom/domain-icon.js
+++ b/plugins/custom/domain-icon.js
@@ -1,13 +1,10 @@
// use this mixin for domain plugins where you do not want to pull out htmlparser but do need an icon or logo
+import { cache } from '../../lib/cache.js';
+import * as async from 'async';
+import * as _ from 'underscore';
+import log from '../../logging.js';
-var core = require('../../lib/core');
-var cache = require('../../lib/cache');
-var async = require('async');
-var _ = require('underscore');
-
-var log = exports.log = require('../../logging').log;
-
-module.exports = {
+export default {
provides: 'domain_icons',
@@ -15,7 +12,7 @@ module.exports = {
return domain_icons;
},
- getData: function(url, cb, options) {
+ getData: function(url, iframelyRun, options, cb) {
// find domain and protocol
var domain, protocol;
@@ -73,7 +70,7 @@ module.exports = {
// + run icons validation right away
// forceSyncCheck - ask 'checkFavicon' to check favicon this time before callback.
- core.run(domainUri, _.extend({}, options, {forceSyncCheck: true}), function(error, data) {
+ iframelyRun(domainUri, _.extend({}, options, {forceSyncCheck: true}), function(error, data) {
var icons;
diff --git a/plugins/custom/fb-error.js b/plugins/custom/fb-error.js
index ea429000e..89620c5ff 100644
--- a/plugins/custom/fb-error.js
+++ b/plugins/custom/fb-error.js
@@ -1,6 +1,6 @@
-var logging = require('../../logging');
+import log from '../../logging.js';
-module.exports = {
+export default {
getLink: function(oembedError, url, cb) {
@@ -49,7 +49,7 @@ module.exports = {
result.message = fbError.message;
}
- logging.log('Facebook oembed api - error getting oembed for', url, JSON.stringify(fbError), JSON.stringify(result));
+ log('Facebook oembed api - error getting oembed for', url, JSON.stringify(fbError), JSON.stringify(result));
return cb(result);
},
diff --git a/plugins/custom/http-headers.js b/plugins/custom/http-headers.js
index c3de6bbf5..2e8a7732c 100644
--- a/plugins/custom/http-headers.js
+++ b/plugins/custom/http-headers.js
@@ -1,12 +1,12 @@
-module.exports = {
+export default {
provides: "headers",
getData: function(htmlparser, cb) {
- if (htmlparser.request && htmlparser.request.response && htmlparser.request.response.headers) {
+ if (htmlparser.headers) {
return cb (null, {
- headers: htmlparser.request.response.headers
+ headers: htmlparser.headers
})
} else {
cb();
diff --git a/plugins/custom/noindex/noindex-header.js b/plugins/custom/noindex/noindex-header.js
index 4c91f1c83..19944f13c 100644
--- a/plugins/custom/noindex/noindex-header.js
+++ b/plugins/custom/noindex/noindex-header.js
@@ -1,9 +1,9 @@
-var pluginUtils = require('./utils');
+import * as pluginUtils from './utils.js';
-module.exports = {
+export default {
getData: function(htmlparser, cb) {
- var headers = htmlparser.request.response.headers;
+ var headers = htmlparser.headers;
if (pluginUtils.checkRobots(headers['x-robots-tag'], cb)) {
return;
} else {
diff --git a/plugins/custom/noindex/noindex-meta.js b/plugins/custom/noindex/noindex-meta.js
index ef08942d2..83ffbd843 100644
--- a/plugins/custom/noindex/noindex-meta.js
+++ b/plugins/custom/noindex/noindex-meta.js
@@ -1,6 +1,6 @@
-var pluginUtils = require('./utils');
+import * as pluginUtils from './utils.js';
-module.exports = {
+export default {
getData: function(meta, cb) {
if (pluginUtils.checkRobots(meta.robots, cb)) {
diff --git a/plugins/custom/noindex/utils.js b/plugins/custom/noindex/utils.js
index 4f8e0889c..2b653581d 100644
--- a/plugins/custom/noindex/utils.js
+++ b/plugins/custom/noindex/utils.js
@@ -1,8 +1,8 @@
-exports.notPlugin = true;
+export const notPlugin = true;
var NO_INDEX_TAGS = ['noindex'];
-exports.checkRobots = function(noindexHeader, cb) {
+export function checkRobots(noindexHeader, cb) {
if (noindexHeader) {
var i;
for(i = 0; i < NO_INDEX_TAGS.length; i++) {
diff --git a/plugins/custom/oembed-error.js b/plugins/custom/oembed-error.js
index a320c5063..b0a88bffd 100644
--- a/plugins/custom/oembed-error.js
+++ b/plugins/custom/oembed-error.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
getData: function(oembedError, cb) {
diff --git a/plugins/custom/og-image-rel-image.js b/plugins/custom/og-image-rel-image.js
index 370877d03..ede29456c 100644
--- a/plugins/custom/og-image-rel-image.js
+++ b/plugins/custom/og-image-rel-image.js
@@ -1,4 +1,4 @@
-var _ = require("underscore");
+import * as _ from "underscore";
var rel = [CONFIG.R.image, CONFIG.R.og];
@@ -18,7 +18,7 @@ function getImageLinks(image) {
}];
}
-module.exports = {
+export default {
getLinks: function(og) {
diff --git a/plugins/custom/query.js b/plugins/custom/query.js
new file mode 100644
index 000000000..ace40f385
--- /dev/null
+++ b/plugins/custom/query.js
@@ -0,0 +1,17 @@
+import * as URL from "url"
+
+export default {
+
+ provides: 'query',
+
+ getData: function(url) {
+
+ if (/\?/i.test(url)) {
+ return {
+ query: URL.parse(url, true).query
+ };
+ } else {
+ return {query: {}}
+ }
+ }
+}
\ No newline at end of file
diff --git a/plugins/custom/twitter-image-rel-image.js b/plugins/custom/twitter-image-rel-image.js
index 828df579f..d6c122372 100644
--- a/plugins/custom/twitter-image-rel-image.js
+++ b/plugins/custom/twitter-image-rel-image.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
getLink: function(twitter) {
diff --git a/plugins/domains/500px/500px.com.js b/plugins/domains/500px/500px.com.js
index bc2a01a76..d0a05aeb5 100644
--- a/plugins/domains/500px/500px.com.js
+++ b/plugins/domains/500px/500px.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: /^https?:\/\/(?:web\.)?500px\.com\/photo\/(\d+)/i,
diff --git a/plugins/domains/absnews.go.com.js b/plugins/domains/absnews.go.com.js
index c575b940c..6a876ff6e 100644
--- a/plugins/domains/absnews.go.com.js
+++ b/plugins/domains/absnews.go.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/abcnews\.go\.com\/\w+\/(?:\w+\/)?video\/[a-zA-Z0-9\-_]+\-(\d+)/i
diff --git a/plugins/domains/animoto.com.js b/plugins/domains/animoto.com.js
index bf983ce7b..0bc060041 100644
--- a/plugins/domains/animoto.com.js
+++ b/plugins/domains/animoto.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: /^https?:\/\/animoto\.com\/play\/\w+/i,
diff --git a/plugins/domains/archive.org.js b/plugins/domains/archive.org.js
index ef7dd4e38..2a19def8c 100644
--- a/plugins/domains/archive.org.js
+++ b/plugins/domains/archive.org.js
@@ -1,6 +1,6 @@
-var utils = require('../../lib/utils');
+import * as utils from '../../lib/utils.js';
-module.exports = {
+export default {
re: [
/^https?:\/\/archive\.org\/details\/([^\/]+)\/?\??/i
diff --git a/plugins/domains/art19.com.js b/plugins/domains/art19.com.js
index 96806681b..fdf55b2dd 100644
--- a/plugins/domains/art19.com.js
+++ b/plugins/domains/art19.com.js
@@ -1,8 +1,4 @@
-var $ = require('cheerio');
-const querystring = require('querystring');
-const URL = require("url");
-
-module.exports = {
+export default {
re: [
/^(https?:\/\/art19\.com\/shows\/[a-zA-Z0-9\-_]+\/episodes\/[a-zA-Z0-9\-_]+)/i,
@@ -14,68 +10,55 @@ module.exports = {
"oembed-description",
"og-image",
"oembed-site",
- "domain-icon"
+ "domain-icon",
+ "oembed-iframe"
],
- getLink: function(oembed, options) {
-
- if (oembed.html) {
-
- var $container = $('
');
- try {
- $container.html(oembed.html);
- } catch(ex) {}
-
- var $iframe = $container.find('iframe');
-
- if ($iframe.length == 1) {
+ getLink: function(iframe, options) {
- var player = $iframe.attr('src');
- var params = URL.parse(player, true).query;
+ var params = Object.assign(iframe.query);
- var theme = options.getRequestOptions('players.theme', 'light');
- params.theme = theme === 'light' ? 'light-gray-blue' : 'dark-blue';
+ var theme = options.getRequestOptions('players.theme', 'light');
+ params.theme = theme === 'light' ? 'light-gray-blue' : 'dark-blue';
- var opts = {};
+ var opts = {};
- var horizontal = options.getRequestOptions('players.horizontal', true);
+ var horizontal = options.getRequestOptions('players.horizontal', true);
- if (horizontal) {
- delete params.type;
- delete params.stretch;
+ if (horizontal) {
+ delete params.type;
+ delete params.stretch;
- var theme = options.getRequestOptions('players.theme', 'light');
- params.theme = theme === 'light' ? 'light-gray-blue' : 'dark-blue';
+ var theme = options.getRequestOptions('players.theme', 'light');
+ params.theme = theme === 'light' ? 'light-gray-blue' : 'dark-blue';
- opts.theme = {
- label: CONFIG.L.theme,
- value: theme,
- values: {
- light: CONFIG.L.light,
- dark: CONFIG.L.dark
- }
- };
- } else {
- params.type = 'artwork';
- params.stretch = true;
- delete params.theme;
- }
-
- opts.horizontal = {
- label: CONFIG.L.horizontal,
- value: horizontal
+ opts.theme = {
+ label: CONFIG.L.theme,
+ value: theme,
+ values: {
+ light: CONFIG.L.light,
+ dark: CONFIG.L.dark
}
+ };
+ } else {
+ params.type = 'artwork';
+ params.stretch = true;
+ delete params.theme;
+ }
- return {
- href: (/\?/.test(player) ? player.replace(/\?.+/, '?') : player + '?') + querystring.stringify(params),
- type: CONFIG.T.text_html,
- rel: [CONFIG.R.player, CONFIG.R.html5, CONFIG.R.oembed], // keep rel oembed here - it prevents validators from removing embed srcz
- media: horizontal ? {height: oembed.height, scrolling: 'no'} : {'aspect-ratio': 1},
- scrolling: 'no',
- options: opts
- };
- }
+ opts.horizontal = {
+ label: CONFIG.L.horizontal,
+ value: horizontal
}
+
+ return {
+ href: iframe.assignQuerystring(params),
+ type: CONFIG.T.text_html,
+ rel: [CONFIG.R.player, CONFIG.R.html5, CONFIG.R.oembed], // keep rel oembed here - it prevents validators from removing embed srcz
+ media: horizontal ? {height: iframe.height, scrolling: 'no'} : {'aspect-ratio': 1},
+ scrolling: 'no',
+ options: opts
+ };
},
tests: [{
diff --git a/plugins/domains/bandcamp.com.js b/plugins/domains/bandcamp.com.js
index 12bc2108d..547908ff4 100644
--- a/plugins/domains/bandcamp.com.js
+++ b/plugins/domains/bandcamp.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/[a-z0-9-]+\.bandcamp\.com\/(album|track)\/(\w+)/i,
diff --git a/plugins/domains/beatport.com.js b/plugins/domains/beatport.com.js
index e77981099..f57971399 100644
--- a/plugins/domains/beatport.com.js
+++ b/plugins/domains/beatport.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/(?:www|pro)\.beatport\.com\/(track|mix)\/[a-zA-Z0-9\.\-]+\/(\d+)/i
diff --git a/plugins/domains/bigthink.com.js b/plugins/domains/bigthink.com.js
index d599e035e..702771309 100644
--- a/plugins/domains/bigthink.com.js
+++ b/plugins/domains/bigthink.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
mixins: [
"*"
diff --git a/plugins/domains/box.com.js b/plugins/domains/box.com.js
index 66c1889c0..e1bcbbbf0 100644
--- a/plugins/domains/box.com.js
+++ b/plugins/domains/box.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https:\/\/app\.box\.com\/(?:embed|embed_widget)?\/?s\/([a-zA-Z0-9]+)/,
diff --git a/plugins/domains/brainyquote.com.js b/plugins/domains/brainyquote.com.js
index 2e93c9a94..09491f91c 100644
--- a/plugins/domains/brainyquote.com.js
+++ b/plugins/domains/brainyquote.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/(?:www\.)?brainyquote\.com\/quotes(?:\/quotes)?\/\w\/?/i
diff --git a/plugins/domains/brightcove.com/players.brightcove.net.js b/plugins/domains/brightcove.com/players.brightcove.net.js
index 6ac245852..c0e1d164f 100644
--- a/plugins/domains/brightcove.com/players.brightcove.net.js
+++ b/plugins/domains/brightcove.com/players.brightcove.net.js
@@ -1,7 +1,6 @@
-var cheerio = require('cheerio');
-var utils = require('../../../lib/utils');
+import * as utils from '../../../lib/utils.js';
-module.exports = {
+export default {
re: [
/^https?:\/\/players\.brightcove\.net\/\d+\/[a-zA-Z0-9]+_[a-zA-Z0-9]+\/index\.html\?videoId=\d+/i
@@ -12,15 +11,16 @@ module.exports = {
mixins: [
"oembed-title",
"oembed-site",
- "oembed-error"
+ "oembed-error",
+ "oembed-iframe"
],
//HTML parser will 404 if BC account or player does not exist.
- getLinks: function(url, oembed, options, cb) {
+ getLinks: function(url, iframe, options, cb) {
var player = {
type: CONFIG.T.text_html,
- rel: [CONFIG.R.oembed, CONFIG.R.player, CONFIG.R.html5]
+ rel: [CONFIG.R.player, CONFIG.R.html5, CONFIG.R.oembed]
};
// autoplay=true comes from `brightcove-in-page-promo` only and follows whitelistRecord
@@ -30,15 +30,8 @@ module.exports = {
player.autoplay = "autoplay=true";
}
- var $container = cheerio('
');
- try {
- $container.html(oembed.html);
- } catch (ex) {}
-
- var $iframe = $container.find('iframe');
-
- if ($iframe.length == 1) {
- player.href = $iframe.attr('src') + (/&autoplay=true/.test(url) ? '&autoplay=true' : ''); // autoplay=true in URL comes from brightcove-allow-in-page whitelist record
+ if (iframe.src) {
+ player.href = iframe.src + (/&autoplay=true/.test(url) ? '&autoplay=true' : ''); // autoplay=true in URL comes from brightcove-allow-in-page whitelist record
}
if (/&iframe-url=/.test(url)) {
@@ -49,9 +42,9 @@ module.exports = {
player.accept = CONFIG.T.text_html; // verify that it exists and isn't X-Frame-Optioned
}
- if (oembed.thumbnail_url) {
+ if (iframe.placeholder) {
- utils.getImageMetadata(oembed.thumbnail_url, options, function(error, data) {
+ utils.getImageMetadata(iframe.placeholder, options, function(error, data) {
var links = [];
@@ -62,7 +55,7 @@ module.exports = {
} else if (data.width && data.height) {
links.push({
- href: oembed.thumbnail_url,
+ href: iframe.placeholder,
type: CONFIG.T.image,
rel: CONFIG.R.thumbnail,
width: data.width,
@@ -70,14 +63,14 @@ module.exports = {
});
}
- player['aspect-ratio'] = (data.width && data.height) ? data.width / data.height : oembed.width / oembed.height;
+ player['aspect-ratio'] = (data.width && data.height) ? data.width / data.height : iframe.width / iframe.height;
links.push(player);
- cb(null, links);
+ return cb(null, links);
});
} else {
- cb (null, player);
+ return cb (null, player);
}
},
diff --git a/plugins/domains/buzzfeed.com/buzzfeed.isvideo.js b/plugins/domains/buzzfeed.com/buzzfeed.isvideo.js
index 1e5367a38..150b36d37 100644
--- a/plugins/domains/buzzfeed.com/buzzfeed.isvideo.js
+++ b/plugins/domains/buzzfeed.com/buzzfeed.isvideo.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/www\.buzzfeed\.com\//i
diff --git a/plugins/domains/buzzfeed.com/buzzfeed.video.js b/plugins/domains/buzzfeed.com/buzzfeed.video.js
index 78369ab49..a4a3e65f0 100644
--- a/plugins/domains/buzzfeed.com/buzzfeed.video.js
+++ b/plugins/domains/buzzfeed.com/buzzfeed.video.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
provides: '__promoUri',
diff --git a/plugins/domains/c-span.org/c-span.org-options.js b/plugins/domains/c-span.org/c-span.org-options.js
index 2eea886d6..13535429f 100644
--- a/plugins/domains/c-span.org/c-span.org-options.js
+++ b/plugins/domains/c-span.org/c-span.org-options.js
@@ -1,6 +1,8 @@
-module.exports = {
+import c_span_org from './c-span.org.js';
- re: require('./c-span.org.js').re,
+export default {
+
+ re: c_span_org.re,
getData: function(url, options) {
options.exposeStatusCode = true;
diff --git a/plugins/domains/c-span.org/c-span.org.js b/plugins/domains/c-span.org/c-span.org.js
index acd11cc54..147f98426 100644
--- a/plugins/domains/c-span.org/c-span.org.js
+++ b/plugins/domains/c-span.org/c-span.org.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: /^https?:\/\/www\.c-span\.org\/video\/\?(c?[\d-]+)(\/[\w-]+)/i,
diff --git a/plugins/domains/cartodb.com.js b/plugins/domains/cartodb.com.js
index f10d2b3cf..8ebbf26ab 100644
--- a/plugins/domains/cartodb.com.js
+++ b/plugins/domains/cartodb.com.js
@@ -1,6 +1,4 @@
-var cheerio = require('cheerio');
-
-module.exports = {
+export default {
re: /^https?:(\/\/[\w-]+\.carto(?:db)?\.com\/(?:u\/[\w-]+\/)?viz\/[a-z0-9-]+)/i,
@@ -13,7 +11,8 @@ module.exports = {
"oembed-author",
"oembed-site",
"keywords",
- "favicon"
+ "favicon",
+ "oembed-iframe"
],
getMeta: function(url, meta) {
@@ -23,27 +22,15 @@ module.exports = {
};
},
- getLink: function(oembed) {
-
- var $container = cheerio('
');
- try {
- $container.html(oembed.html5 || oembed.html);
- } catch (ex) {}
-
- var $iframe = $container.find('iframe');
-
- if ($iframe.length == 1) {
-
- return {
- href: $iframe.attr('src'),
- type: CONFIG.T.text_html,
- rel: [CONFIG.R.app, CONFIG.R.ssl, CONFIG.R.html5],
- "aspect-ratio": 4/3,
- "padding-bottom": 30
- // aspect 4:3 is better than height=520px and width=100%
- };
+ getLink: function(iframe) {
+ return {
+ href: iframe.src,
+ type: CONFIG.T.text_html,
+ rel: [CONFIG.R.app, CONFIG.R.ssl, CONFIG.R.html5],
+ "aspect-ratio": 4/3,
+ "padding-bottom": 30
+ // aspect 4:3 is better than height=520px and width=100%
}
-
},
tests: [{
diff --git a/plugins/domains/cbc.ca.js b/plugins/domains/cbc.ca.js
index 956bad3a6..5dc0a5b40 100644
--- a/plugins/domains/cbc.ca.js
+++ b/plugins/domains/cbc.ca.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/www\.cbc\.ca\/player\//i,
diff --git a/plugins/domains/channel9.msdn.com.js b/plugins/domains/channel9.msdn.com.js
index b94b4b422..38b57e183 100644
--- a/plugins/domains/channel9.msdn.com.js
+++ b/plugins/domains/channel9.msdn.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: /^https?:\/\/channel9\.msdn\.com\/Events\/([\w-]+\/\d+\/[\w-]+)/i,
diff --git a/plugins/domains/cnevids.com.js b/plugins/domains/cnevids.com.js
index d0aa03ab0..105d6c72e 100644
--- a/plugins/domains/cnevids.com.js
+++ b/plugins/domains/cnevids.com.js
@@ -1,22 +1,19 @@
-module.exports = {
+export default {
mixins: [
"oembed-thumbnail",
"oembed-author",
"oembed-site",
- "oembed-title"
+ "oembed-title",
+ "oembed-iframe"
],
- getLink: function(oembed, whitelistRecord) {
+ getLink: function(iframe, oembed, whitelistRecord) {
- var iframe = oembed.getIframe();
-
- if (iframe && whitelistRecord.isAllowed && whitelistRecord.isAllowed('oembed.video', 'autoplay')) {
-
- var href = iframe.src;
+ if (iframe.src && whitelistRecord.isAllowed && whitelistRecord.isAllowed('oembed.video', 'autoplay')) {
var links = [{
- href: href + (href.indexOf('?') > -1 ? '&' : '?') + 'autoplay=0',
+ href: iframe.replaceQuerystring({autoplay:0}),
type: CONFIG.T.text_html,
rel: [CONFIG.R.player, CONFIG.R.oembed, CONFIG.R.html5],
autoplay: "autoplay=1",
diff --git a/plugins/domains/cnn.com.js b/plugins/domains/cnn.com.js
index 40f2e1f04..7345613d9 100644
--- a/plugins/domains/cnn.com.js
+++ b/plugins/domains/cnn.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/(www|edition)?\.?cnn\.com\/videos?\//i,
diff --git a/plugins/domains/codepen.io.js b/plugins/domains/codepen.io.js
index 7fe20444a..05dc128a3 100644
--- a/plugins/domains/codepen.io.js
+++ b/plugins/domains/codepen.io.js
@@ -1,8 +1,4 @@
-const $ = require('cheerio');
-const querystring = require('querystring');
-const URL = require("url");
-
-module.exports = {
+export default {
re: /https?:\/\/codepen\.io\/(?:[a-z0-9\-_]+\/)?(pen|details|full)\/([a-z0-9\-]+)/i,
@@ -11,11 +7,12 @@ module.exports = {
"oembed-author",
"oembed-site",
"oembed-title",
+ "oembed-iframe",
//"description", // don't enable to avoid 403 from CodePen's htmlparser. Description is '...' in most cases anyway
"domain-icon"
],
- getLink: function(oembed, options) {
+ getLink: function(oembed, iframe, options) {
if (oembed.author_url === "https://codepen.io/anon/") {
return { // And no fallback to generics
@@ -23,57 +20,47 @@ module.exports = {
}
}
- var $container = $('
');
- try{
- $container.html(oembed.html);
- } catch(ex) {}
-
- var $iframe = $container.find('iframe');
-
- if ($iframe.length == 1) {
-
- var href = $iframe.attr('src');
- var params = URL.parse(href, true).query;
+ var params = Object.assign(iframe.query);
- var click_to_load = options.getRequestOptions('codepen.click_to_load', /\/embed\/preview\//.test(href));
- href = href.replace(/\/embed\/(?:preview\/)?/, '/embed/').replace(/\/embed\//, '/embed/' + (click_to_load ? 'preview/' : ''));
+ params.height = options.getRequestOptions('codepen.height', oembed.height);
- params.height = options.getRequestOptions('codepen.height', oembed.height);
+ var theme = options.getRequestOptions('players.theme', params.theme || 'auto');
- var theme = options.getRequestOptions('players.theme', params.theme || 'auto');
-
- if (theme === 'auto') {
- delete params['theme-id'];
- } else {
- params['theme-id'] = theme;
- }
+ if (theme === 'auto') {
+ delete params['theme-id'];
+ } else {
+ params['theme-id'] = theme;
+ }
- return {
- href: href.replace(/\?.+/, '') + querystring.stringify(params).replace(/^(.)/, '?$1'),
- type: CONFIG.T.text_html,
- rel: [CONFIG.R.app, CONFIG.R.oembed, CONFIG.R.html5],
- height: params.height,
- options: {
- height: {
- label: CONFIG.L.height,
- value: params.height,
- placeholder: 'ex.: 600, in px'
- },
- click_to_load: {
- label: 'Use click-to-load',
- value: click_to_load
- },
- theme: {
- label: CONFIG.L.theme,
- value: theme,
- values: {
- light: CONFIG.L.light,
- dark: CONFIG.L.dark,
- auto: CONFIG.L.default
- }
+ var href = iframe.assignQuerystring(params);
+ var click_to_load = options.getRequestOptions('codepen.click_to_load', /\/embed\/preview\//.test(href));
+ href = href.replace(/\/embed\/(?:preview\/)?/, '/embed/').replace(/\/embed\//, '/embed/' + (click_to_load ? 'preview/' : ''));
+
+ return {
+ href: href,
+ type: CONFIG.T.text_html,
+ rel: [CONFIG.R.app, CONFIG.R.oembed, CONFIG.R.html5],
+ height: params.height,
+ options: {
+ height: {
+ label: CONFIG.L.height,
+ value: params.height,
+ placeholder: 'ex.: 600, in px'
+ },
+ click_to_load: {
+ label: 'Use click-to-load',
+ value: click_to_load
+ },
+ theme: {
+ label: CONFIG.L.theme,
+ value: theme,
+ values: {
+ light: CONFIG.L.light,
+ dark: CONFIG.L.dark,
+ auto: CONFIG.L.default
}
}
- };
+ }
}
},
diff --git a/plugins/domains/d.pr.js b/plugins/domains/d.pr.js
index 3e8542754..852b43da8 100644
--- a/plugins/domains/d.pr.js
+++ b/plugins/domains/d.pr.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/(\w+\.)?d\.pr(?:\/free)?\/(?:i|v|)\//i
diff --git a/plugins/domains/dailymail.co.uk/dailymail.embeddedvideo.js b/plugins/domains/dailymail.co.uk/dailymail.embeddedvideo.js
index 36d07521e..cf9203b6d 100644
--- a/plugins/domains/dailymail.co.uk/dailymail.embeddedvideo.js
+++ b/plugins/domains/dailymail.co.uk/dailymail.embeddedvideo.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
// direct "share" links to players from DailyMail articles. They end with #v-1467332342001
re: [
diff --git a/plugins/domains/dailymail.co.uk/dailymail.galleryvideo.js b/plugins/domains/dailymail.co.uk/dailymail.galleryvideo.js
index a8cc52a61..8c5fdfb66 100644
--- a/plugins/domains/dailymail.co.uk/dailymail.galleryvideo.js
+++ b/plugins/domains/dailymail.co.uk/dailymail.galleryvideo.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/www\.dailymail\.co\.uk\/video\/\w+\/video\-(\d+)\//i
diff --git a/plugins/domains/dailymail.co.uk/dailymail.video.js b/plugins/domains/dailymail.co.uk/dailymail.video.js
index dbca24d02..e0f0fd525 100644
--- a/plugins/domains/dailymail.co.uk/dailymail.video.js
+++ b/plugins/domains/dailymail.co.uk/dailymail.video.js
@@ -1,8 +1,10 @@
-const decodeHTML5 = require('entities').decodeHTML5;
+import { decodeHTML5 } from 'entities';
+import dailymail_embeddedvideo from './dailymail.embeddedvideo.js';
+import dailymail_galleryvideo from './dailymail.galleryvideo.js';
-module.exports = {
+export default {
- re: [].concat(require('./dailymail.embeddedvideo').re, require('./dailymail.galleryvideo').re),
+ re: [].concat(dailymail_embeddedvideo.re, dailymail_galleryvideo.re),
provides: 'dailymailVideo',
diff --git a/plugins/domains/dailymail.co.uk/mol.im.js b/plugins/domains/dailymail.co.uk/mol.im.js
index fed5cf0e5..1a51c2678 100644
--- a/plugins/domains/dailymail.co.uk/mol.im.js
+++ b/plugins/domains/dailymail.co.uk/mol.im.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
// #v-1467332342001 isn't passed by Dailymail URL shortener
re: /^https:\/\/mol\.im\/a\/\d+(#v\-\d+)/i,
diff --git a/plugins/domains/dailymotion.com/dailymotion.com.js b/plugins/domains/dailymotion.com/dailymotion.com.js
index 57a8b5146..1940d03c6 100644
--- a/plugins/domains/dailymotion.com/dailymotion.com.js
+++ b/plugins/domains/dailymotion.com/dailymotion.com.js
@@ -1,6 +1,7 @@
-const querystring = require('querystring');
+import * as querystring from 'querystring';
+import request from 'request';
-module.exports = {
+export default {
mixins: [
"oembed-title",
@@ -10,6 +11,7 @@ module.exports = {
"domain-icon",
"og-description",
"canonical",
+ "oembed-iframe",
"video"
],
@@ -18,17 +20,15 @@ module.exports = {
* - queue-enable=false - https://faq.dailymotion.com/hc/en-us/articles/360000713928-Disabling-the-Up-Next-Queue
* - ui-start-screen-info=0 - hide title amontg other things - https://nextgenthemes.com/how-to-hide-titles-and-change-other-setting-for-youtube-vimeo-embeds-in-wordpress-with-arve/
*/
- getLink: function (url, oembed, options) {
+ getLink: function (url, iframe, options) {
var playlistParams = querystring.parse(options.getProviderOptions('dailymotion.get_params', '').replace(/^\?/, ''));
- var qs = querystring.stringify(playlistParams);
- var href = oembed.getIframeAttr('src');
- if (href && oembed.height) {
+ if (iframe.src && iframe.height) {
return {
- href: href + (href.indexOf("?") > -1 ? "&" : (qs !== "" ? "?" : "")) + qs,
+ href: iframe.replaceQuerystring(playlistParams),
type: CONFIG.T.text_html,
"rel": [CONFIG.R.player, CONFIG.R.html5, CONFIG.R.ssl, CONFIG.R.oembed],
- "aspect-ratio": oembed.width / oembed.height,
+ "aspect-ratio": iframe.width / iframe.height,
scrolling: 'no',
autoplay: "autoplay=1"
};
@@ -49,7 +49,6 @@ module.exports = {
tests: [{
getUrls: function(cb) {
- var request = require('request');
request({
url: 'https://api.dailymotion.com/videos',
json: true
diff --git a/plugins/domains/dailymotion.com/dailymotion.playlist.js b/plugins/domains/dailymotion.com/dailymotion.playlist.js
index 6f529bc36..b80975b16 100644
--- a/plugins/domains/dailymotion.com/dailymotion.playlist.js
+++ b/plugins/domains/dailymotion.com/dailymotion.playlist.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
/**
* Endpoint `http://www.dailymotion.com/services/oembed`
* does not provide oembed results for playlist url currently
diff --git a/plugins/domains/dailymotion.com/dailymotion.swf.js b/plugins/domains/dailymotion.com/dailymotion.swf.js
index 8335ebedf..55b7a869b 100644
--- a/plugins/domains/dailymotion.com/dailymotion.swf.js
+++ b/plugins/domains/dailymotion.com/dailymotion.swf.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: /^https?:\/\/www\.dailymotion\.com\/(swf|embed)\/video\//i,
diff --git a/plugins/domains/documentcloud.org.js b/plugins/domains/documentcloud.org.js
index eb5610448..c03a3b1ad 100644
--- a/plugins/domains/documentcloud.org.js
+++ b/plugins/domains/documentcloud.org.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: /^https?:\/\/(?:www)?\.?documentcloud\.org\/documents?\/\d+/i,
diff --git a/plugins/domains/dribbble.com.js b/plugins/domains/dribbble.com.js
index a58f818c6..1f5bdd3a3 100644
--- a/plugins/domains/dribbble.com.js
+++ b/plugins/domains/dribbble.com.js
@@ -1,6 +1,6 @@
const PROFILE_RE = /^https?:\/\/dribbble\.com\/([a-zA-Z0-9\-]+)(?:\?[^\/]+)?$/i;
-module.exports = {
+export default {
re: [
/^https?:\/\/dribbble\.com\/shots\/([a-zA-Z0-9\-]+)/i,
diff --git a/plugins/domains/ebaumsworld.com.js b/plugins/domains/ebaumsworld.com.js
index 2d5724e59..d998c7b45 100644
--- a/plugins/domains/ebaumsworld.com.js
+++ b/plugins/domains/ebaumsworld.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/www\.ebaumsworld\.com\/video\/watch\/(\d+)/i,
diff --git a/plugins/domains/espn.com.js b/plugins/domains/espn.com.js
index ffb00ceae..bf18f76ae 100644
--- a/plugins/domains/espn.com.js
+++ b/plugins/domains/espn.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/(?:www\.)?espn\.com?(?:\.\w{2})?\/video\/clip\?id=espn:(\d+)/i,
diff --git a/plugins/domains/facebook.com/facebook.ld.js b/plugins/domains/facebook.com/facebook.ld.js
index af0d41371..dbec152eb 100644
--- a/plugins/domains/facebook.com/facebook.ld.js
+++ b/plugins/domains/facebook.com/facebook.ld.js
@@ -1,6 +1,8 @@
-module.exports = {
+import facebook_video_re from './facebook.video.js';
- re: require('./facebook.video').re,
+export default {
+
+ re: facebook_video_re.re,
getMeta: function(__allowFBThumbnail, schemaVideoObject) {
diff --git a/plugins/domains/facebook.com/facebook.meta.js b/plugins/domains/facebook.com/facebook.meta.js
index bdaa48d0f..160486128 100644
--- a/plugins/domains/facebook.com/facebook.meta.js
+++ b/plugins/domains/facebook.com/facebook.meta.js
@@ -1,6 +1,9 @@
-const entities = require('entities');
+import * as entities from 'entities';
-module.exports = {
+import facebook_post from './facebook.post.js';
+import facebook_video from './facebook.video.js';
+
+export default {
/**
* HEADS-UP: New endpoints as of Oct 24, 2020:
@@ -9,7 +12,7 @@ module.exports = {
* as desribed on https://github.com/itteco/iframely/issues/284.
*/
- re: [].concat(require('./facebook.post').re, require('./facebook.video').re),
+ re: [].concat(facebook_post.re, facebook_video.re),
mixins: [
"domain-icon",
diff --git a/plugins/domains/facebook.com/facebook.page.js b/plugins/domains/facebook.com/facebook.page.js
index a9f35bf6d..fae39efe6 100644
--- a/plugins/domains/facebook.com/facebook.page.js
+++ b/plugins/domains/facebook.com/facebook.page.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/(www|m)\.facebook\.com\/([^\/\?]+(? 20 ? 20 : zoom;
}
-module.exports = {
+export default {
re: [
/^https?:\/\/maps\.google\.(?:com?\.)?[a-z]+\/(?:maps(?:\/ms|\/preview)?)?[\?\#].+/i,
diff --git a/plugins/domains/hockeydb.com.js b/plugins/domains/hockeydb.com.js
index 625c21101..789a1332f 100644
--- a/plugins/domains/hockeydb.com.js
+++ b/plugins/domains/hockeydb.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: /^https?:\/\/www\.hockeydb\.com\/ihdb\/stats\/pdisplay\.php\?pid=(\d+)/i,
diff --git a/plugins/domains/i.gfycat.com.js b/plugins/domains/i.gfycat.com.js
index 24fa38f4d..2807de952 100644
--- a/plugins/domains/i.gfycat.com.js
+++ b/plugins/domains/i.gfycat.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/https?:\/\/(?:giant|thumbs|zippy)\.gfycat\.com\/([a-zA-Z0-9]+)(?:\-mobile|\-size_restricted)?\.(?:webm|mp4|gif)$/i,
diff --git a/plugins/domains/i.gifs.com.js b/plugins/domains/i.gifs.com.js
index 03271791e..aa9fb684e 100644
--- a/plugins/domains/i.gifs.com.js
+++ b/plugins/domains/i.gifs.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/https?:\/\/j\.gifs\.com\/(\w+)\.gif$/i
diff --git a/plugins/domains/i.giphy.com.js b/plugins/domains/i.giphy.com.js
index 103c0bea9..c4d01fa1a 100644
--- a/plugins/domains/i.giphy.com.js
+++ b/plugins/domains/i.giphy.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/https?:\/\/i\.giphy\.com\/(\w+)\.gif(\?.*)?$/i,
diff --git a/plugins/domains/ignore.js b/plugins/domains/ignore.js
index 0a0bbb944..3eb30c8fb 100644
--- a/plugins/domains/ignore.js
+++ b/plugins/domains/ignore.js
@@ -2,7 +2,7 @@
const RE = CONFIG.IGNORE_DOMAINS_RE || CONFIG.BLACKLIST_DOMAINS_RE;
-module.exports = {
+export default {
re: RE,
diff --git a/plugins/domains/imageshack.com.js b/plugins/domains/imageshack.com.js
index ada5358dd..7e7e957d5 100644
--- a/plugins/domains/imageshack.com.js
+++ b/plugins/domains/imageshack.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: /^https?:\/\/imageshack\.com\/i\/\w+/i,
mixins: [
diff --git a/plugins/domains/imdb.com.js b/plugins/domains/imdb.com.js
index ac1f7990c..d067c69b6 100644
--- a/plugins/domains/imdb.com.js
+++ b/plugins/domains/imdb.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/www\.imdb\.com\/video\/(?:[\w]+\/)?vi(\d+)/i,
diff --git a/plugins/domains/instagram.com/instagram-post-allow-meta.js b/plugins/domains/instagram.com/instagram-post-allow-meta.js
index 662027d18..87f7dfc19 100644
--- a/plugins/domains/instagram.com/instagram-post-allow-meta.js
+++ b/plugins/domains/instagram.com/instagram-post-allow-meta.js
@@ -1,6 +1,8 @@
-module.exports = {
+import instagram_com from './instagram.com.js';
- re: require('./instagram.com').re,
+export default {
+
+ re: instagram_com.re,
provides: 'ipOG',
diff --git a/plugins/domains/instagram.com/instagram-post-rate-limit-429.js b/plugins/domains/instagram.com/instagram-post-rate-limit-429.js
index 003fca3ba..1c904d1a4 100644
--- a/plugins/domains/instagram.com/instagram-post-rate-limit-429.js
+++ b/plugins/domains/instagram.com/instagram-post-rate-limit-429.js
@@ -1,6 +1,8 @@
-module.exports = {
+import instagram_com from './instagram.com.js';
- re: require('./instagram.com').re,
+export default {
+
+ re: instagram_com.re,
provides: 'ipOG',
diff --git a/plugins/domains/instagram.com/instagram.com.js b/plugins/domains/instagram.com/instagram.com.js
index f6c041973..63eeb4849 100644
--- a/plugins/domains/instagram.com/instagram.com.js
+++ b/plugins/domains/instagram.com/instagram.com.js
@@ -1,7 +1,8 @@
-const cheerio = require('cheerio');
-const decodeHTML5 = require('entities').decodeHTML5;
+import cheerio from 'cheerio';
-module.exports = {
+import { decodeHTML5 } from 'entities';
+
+export default {
/**
* HEADS-UP: New endpoints as of Oct 24, 2020:
diff --git a/plugins/domains/issuu.com.js b/plugins/domains/issuu.com.js
index 33c43532f..7afa45739 100644
--- a/plugins/domains/issuu.com.js
+++ b/plugins/domains/issuu.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: /^https?:\/\/issuu\.com\/[\w_.-]+\/docs\/([\w_.-]+)/i,
diff --git a/plugins/domains/itunes.apple.com/apple.music.js b/plugins/domains/itunes.apple.com/apple.music.js
index 1452b5a18..a13935c51 100644
--- a/plugins/domains/itunes.apple.com/apple.music.js
+++ b/plugins/domains/itunes.apple.com/apple.music.js
@@ -1,7 +1,7 @@
-const URL = require('url');
-const _ = require('underscore');
+import * as URL from 'url';
+import * as _ from 'underscore';
-module.exports = {
+export default {
re: [
/^https?:\/\/music\.apple\.com\/(\w{2})\/(album)(?:\/[^\/]+)?\/id(\d+)\?i=(\d+)?/i,
diff --git a/plugins/domains/jsfiddle.net.js b/plugins/domains/jsfiddle.net.js
index 6dfbe6e2d..85048acda 100644
--- a/plugins/domains/jsfiddle.net.js
+++ b/plugins/domains/jsfiddle.net.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: /^(https?:\/\/jsfiddle.net\/(?:\w+\/)?\w+\/)\/?(?:[^\/]+)?$/i,
diff --git a/plugins/domains/kickstarter.com.js b/plugins/domains/kickstarter.com.js
index 5958ec936..61ab356ec 100644
--- a/plugins/domains/kickstarter.com.js
+++ b/plugins/domains/kickstarter.com.js
@@ -1,6 +1,6 @@
-var utils = require('../../lib/utils');
+import * as utils from '../../lib/utils.js';
-module.exports = {
+export default {
re: [
/^https?:\/\/(?:www\.)?kickstarter\.com\/projects\/[a-zA-Z0-9-]+\/[a-zA-Z0-9-]+\/?(?:widget\/video\.html)?(?:\?.*)?$/i
diff --git a/plugins/domains/knightlab.js b/plugins/domains/knightlab.js
index 7d16c9289..2e152a53e 100644
--- a/plugins/domains/knightlab.js
+++ b/plugins/domains/knightlab.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/s3\.amazonaws\.com\/(?:uploads|CDN)\.knightlab\.com\/(storymapjs)\/\w+\/(?:[a-zA-Z0-9\-\/]+)\.html/i,
diff --git a/plugins/domains/libsyn.com.js b/plugins/domains/libsyn.com.js
index 6def89e57..67c9274ae 100644
--- a/plugins/domains/libsyn.com.js
+++ b/plugins/domains/libsyn.com.js
@@ -1,10 +1,9 @@
-module.exports = {
+export default {
re: /^https?:\/\/[a-zA-Z0-9\.]+\.libsyn(?:pro)?\.com\//,
mixins: [
- "*",
- "oembed-iframe"
+ "*"
],
getLink: function(iframe, meta, options) {
diff --git a/plugins/domains/live.amcharts.com.js b/plugins/domains/live.amcharts.com.js
index 8f08b7890..0f8828f69 100644
--- a/plugins/domains/live.amcharts.com.js
+++ b/plugins/domains/live.amcharts.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: /^https?:\/\/live\.amcharts\.com\/([a-zA-Z0-9\-]+)/i,
diff --git a/plugins/domains/livestream.com.js b/plugins/domains/livestream.com.js
index 2fdb6ed67..80f6efa56 100644
--- a/plugins/domains/livestream.com.js
+++ b/plugins/domains/livestream.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/livestream\.com\/(\w+)\/events\/(\d+)(\/videos?\/\d+)?/i,
diff --git a/plugins/domains/mail.ru.js b/plugins/domains/mail.ru.js
index eb665bc0e..89cfe0993 100644
--- a/plugins/domains/mail.ru.js
+++ b/plugins/domains/mail.ru.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/my\.mail\.ru\/\/?[a-z\.]+\/[a-zA-Z0-9\._\-]+\/video\/([a-zA-Z0-9_]+)\/([a-zA-Z0-9_]+)\.html/i
diff --git a/plugins/domains/maps.yandex.ru/maps.yandex.ru.js b/plugins/domains/maps.yandex.ru/maps.yandex.ru.js
index 345e0ee47..0c781433f 100644
--- a/plugins/domains/maps.yandex.ru/maps.yandex.ru.js
+++ b/plugins/domains/maps.yandex.ru/maps.yandex.ru.js
@@ -1,6 +1,6 @@
-var URL = require("url");
+import * as URL from "url";
-module.exports = {
+export default {
re: /^https:\/\/yandex\.ru\/maps\//,
diff --git a/plugins/domains/maps.yandex.ru/maps.yandex.ru.short.js b/plugins/domains/maps.yandex.ru/maps.yandex.ru.short.js
index 9641ff518..5225db92d 100644
--- a/plugins/domains/maps.yandex.ru/maps.yandex.ru.short.js
+++ b/plugins/domains/maps.yandex.ru/maps.yandex.ru.short.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: /^https:\/\/yandex\.ru\/maps\/-\//,
diff --git a/plugins/domains/medium.com.js b/plugins/domains/medium.com.js
index 663f58d76..bf1ba5d1e 100644
--- a/plugins/domains/medium.com.js
+++ b/plugins/domains/medium.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: /^https:\/\/(?:[a-z0-9\-]+\.)?medium\.com\/@?[\w-]+/i,
diff --git a/plugins/domains/mixcloud.com.js b/plugins/domains/mixcloud.com.js
index 565ad6302..67fb909ba 100644
--- a/plugins/domains/mixcloud.com.js
+++ b/plugins/domains/mixcloud.com.js
@@ -1,8 +1,4 @@
-const cheerio = require('cheerio');
-const querystring = require('querystring');
-const URL = require("url");
-
-module.exports = {
+export default {
re: [
/^https?:\/\/(?:www\.)mixcloud\.com\/(?:live\/)?[a-zA-Z0-9\.\-_]+\/?(?:\?.+)?$/,
@@ -15,13 +11,14 @@ module.exports = {
"oembed-author",
"oembed-site",
"oembed-error",
+ "oembed-iframe",
"domain-icon"
],
- getLink: function (oembed, whitelistRecord, options) {
+ getLink: function (oembed, iframe, whitelistRecord, options) {
// let Whitelist/default fallbacks take control if oEmbed fails
- if (!(oembed.type === "rich" && whitelistRecord.isAllowed && whitelistRecord.isAllowed('oembed.rich'))) {
+ if (!(oembed.type === "rich" && iframe.src && whitelistRecord.isAllowed && whitelistRecord.isAllowed('oembed.rich'))) {
return;
} else {
@@ -30,92 +27,82 @@ module.exports = {
type: CONFIG.T.text_html
};
- var $container = cheerio('
');
- try {
- $container.html(oembed.html);
- } catch (ex) {}
-
- var $iframe = $container.find('iframe');
-
- if ($iframe.length == 1) {
-
- var href = $iframe.attr('src');
-
- if (/\/widget\/follow\//.test(href)) {
- widget.href = href;
- widget.rel.push(CONFIG.R.summary);
- widget.width = oembed.width;
- widget.height = oembed.height;
-
- // widget.error = 'Mixcloud user summary is currently broken'; // Sept 22, 2020 - works as of Jan 25, 2021
-
- } else {
-
- var params = URL.parse(href, true).query;
- if (options.getProviderOptions('players.horizontal') === false) {
- delete params.hide_cover;
- }
- var style = options.getRequestOptions('mixcloud.style', params.mini == 1 ? 'mini' : (params.hide_cover == 1 ? 'classic' : 'cover'));
- var theme = options.getRequestOptions('players.theme', params.light == 1 ? 'light' : 'dark');
-
- if (theme === 'light') {
- params.light = 1;
- }
-
- if (options.getRequestOptions('mixcloud.hide_artwork', params.hide_artwork)) {
- params.hide_artwork = 1;
- }
-
- if (style === 'mini') {
- params.mini = 1;
- params.hide_cover = 1;
- } else if (style === 'classic') {
- delete params.mini;
- params.hide_cover = 1;
- } else if (style === 'cover') {
- delete params.mini;
- delete params.hide_cover;
- delete params.light;
- delete params.hide_artwork;
+ var href = iframe.src;
+
+ if (/\/widget\/follow\//.test(href)) {
+ widget.href = href;
+ widget.rel.push(CONFIG.R.summary);
+ widget.width = oembed.width;
+ widget.height = oembed.height;
+
+ // widget.error = 'Mixcloud user summary is currently broken'; // Sept 22, 2020 - works as of Jan 25, 2021
+
+ } else {
+
+ var params = Object.assign(iframe.query);
+ if (options.getProviderOptions('players.horizontal') === false) {
+ delete params.hide_cover;
+ }
+ var style = options.getRequestOptions('mixcloud.style', params.mini == 1 ? 'mini' : (params.hide_cover == 1 ? 'classic' : 'cover'));
+ var theme = options.getRequestOptions('players.theme', params.light == 1 ? 'light' : 'dark');
+
+ if (theme === 'light') {
+ params.light = 1;
+ }
+
+ if (options.getRequestOptions('mixcloud.hide_artwork', params.hide_artwork)) {
+ params.hide_artwork = 1;
+ }
+
+ if (style === 'mini') {
+ params.mini = 1;
+ params.hide_cover = 1;
+ } else if (style === 'classic') {
+ delete params.mini;
+ params.hide_cover = 1;
+ } else if (style === 'cover') {
+ delete params.mini;
+ delete params.hide_cover;
+ delete params.light;
+ delete params.hide_artwork;
+ }
+
+ widget.href = iframe.assignQuerystring(params);
+ widget.autoplay = 'autoplay=1';
+
+ // mixcloud ignores &mini=1 if there's no &hide_cover=1.
+ widget.height = !/&?hide_cover=1/i.test(widget.href) ? 400 : (/&?mini=1/i.test(widget.href) ? 60 : 120);
+ widget.scrolling = "no";
+ widget.rel.push(CONFIG.R.player);
+ widget.rel.push(CONFIG.R.auido);
+
+ widget.options = {
+ style: {
+ label: 'Widget style',
+ value: style,
+ values: {
+ 'mini': 'Mini',
+ 'classic': 'Classic',
+ 'cover': 'Picture'
+ }
}
-
- widget.href = href.replace(/\?.+/, '') + querystring.stringify(params).replace(/^(.)/, '?$1');
- widget.autoplay = 'autoplay=1';
-
- // mixcloud ignores &mini=1 if there's no &hide_cover=1.
- widget.height = !/&?hide_cover=1/i.test(widget.href) ? 400 : (/&?mini=1/i.test(widget.href) ? 60 : 120);
- widget.scrolling = "no";
- widget.rel.push(CONFIG.R.player);
- widget.rel.push(CONFIG.R.auido);
-
- widget.options = {
- style: {
- label: 'Widget style',
- value: style,
- values: {
- 'mini': 'Mini',
- 'classic': 'Classic',
- 'cover': 'Picture'
- }
+ };
+
+ if (style !== 'cover') {
+ widget.options.theme = {
+ label: CONFIG.L.theme,
+ value: theme,
+ values: {
+ light: CONFIG.L.light,
+ dark: CONFIG.L.dark
}
};
+ widget.options.hide_artwork = {
+ label: CONFIG.L.hide_artwork,
+ value: params.hide_artwork === 1
+ };
- if (style !== 'cover') {
- widget.options.theme = {
- label: CONFIG.L.theme,
- value: theme,
- values: {
- light: CONFIG.L.light,
- dark: CONFIG.L.dark
- }
- };
- widget.options.hide_artwork = {
- label: CONFIG.L.hide_artwork,
- value: params.hide_artwork === 1
- };
-
- }
- }
+ }
return [widget, {
href: oembed.image,
diff --git a/plugins/domains/momindum.com.js b/plugins/domains/momindum.com.js
index 13b441407..2dbc2e334 100644
--- a/plugins/domains/momindum.com.js
+++ b/plugins/domains/momindum.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
mixins: [
"*"
diff --git a/plugins/domains/nbcnews.com.js b/plugins/domains/nbcnews.com.js
index 74e1db79a..658b7cfa4 100644
--- a/plugins/domains/nbcnews.com.js
+++ b/plugins/domains/nbcnews.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: /^https?:\/\/www\.nbcnews\.com\/(?:[a-z\-]+\/)?videos?\/[a-zA-Z0-9-]+\-(\d+)/i,
diff --git a/plugins/domains/nbcsports.com.js b/plugins/domains/nbcsports.com.js
index 5387d4e0d..000020ba5 100644
--- a/plugins/domains/nbcsports.com.js
+++ b/plugins/domains/nbcsports.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/www\.nbcsports\.com\/videos?\/[a-zA-Z0-9-]+/i
diff --git a/plugins/domains/nhl.com/nhl.com.js b/plugins/domains/nhl.com/nhl.com.js
index 2e79997e8..458569ad6 100644
--- a/plugins/domains/nhl.com/nhl.com.js
+++ b/plugins/domains/nhl.com/nhl.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/https?:\/\/(?:www\.)?nhl\.com(\/\w+\/)video\/(?:embed\/)?([a-zA-Z0-9\-]+\/t\-\d+\/c\-\d+)/i,
diff --git a/plugins/domains/npr.org/npr.sections.js b/plugins/domains/npr.org/npr.sections.js
index e79882272..b2fa55989 100644
--- a/plugins/domains/npr.org/npr.sections.js
+++ b/plugins/domains/npr.org/npr.sections.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/www\.npr\.org\/sections\//i,
diff --git a/plugins/domains/nytimes.video.js b/plugins/domains/nytimes.video.js
index 01a875c51..bda5ec89d 100644
--- a/plugins/domains/nytimes.video.js
+++ b/plugins/domains/nytimes.video.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/www\.nytimes\.com\/video\/[a-zA-Z0-9\-]+\/(\d+)\//,
diff --git a/plugins/domains/openstreetmap.org.js b/plugins/domains/openstreetmap.org.js
index 43cb9f47a..59a6f9aef 100644
--- a/plugins/domains/openstreetmap.org.js
+++ b/plugins/domains/openstreetmap.org.js
@@ -1,5 +1,5 @@
-var URL = require("url");
-var QueryString = require("querystring");
+import * as URL from "url";
+import * as QueryString from "querystring";
var LayerMap = {
M: 'mapnik',
@@ -53,7 +53,7 @@ function getBBox(lat, lon, zoom, width, height) {
return [lonlat_s[0], lonlat_s[1], lonlat_e[0], lonlat_e[1]];
}
-module.exports = {
+export default {
re: /^https?:\/\/(?:www\.)?openstreetmap\.org\/(?:node\/\d+)?(?:\?.+|\#.*map=.+|export\/embed\.html\?)/i,
diff --git a/plugins/domains/ow.ly.js b/plugins/domains/ow.ly.js
index 27e6b6dce..da63cbd82 100644
--- a/plugins/domains/ow.ly.js
+++ b/plugins/domains/ow.ly.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/ow\.ly\/i\//i
diff --git a/plugins/domains/padlet.com.js b/plugins/domains/padlet.com.js
index 910f80db3..88adbb2f8 100644
--- a/plugins/domains/padlet.com.js
+++ b/plugins/domains/padlet.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/padlet\.com\/[0-9a-zA-Z_\-]+\/([0-9a-zA-Z_\-]+)/i
diff --git a/plugins/domains/pastebin.com.js b/plugins/domains/pastebin.com.js
index d55669639..d08c8c12c 100644
--- a/plugins/domains/pastebin.com.js
+++ b/plugins/domains/pastebin.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/pastebin\.com\/(?!search)([a-zA-Z0-9]+)/i
diff --git a/plugins/domains/piktochart.com/piktochart.com.js b/plugins/domains/piktochart.com/piktochart.com.js
index e6efc9f66..2e954a64d 100644
--- a/plugins/domains/piktochart.com/piktochart.com.js
+++ b/plugins/domains/piktochart.com/piktochart.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: /^https?:\/\/(?:magic|create)\.piktochart\.com\/output\/(\d+\-[\-a-zA-Z-0-9_]+)/i,
diff --git a/plugins/domains/pinterest.com/pinterest.board.js b/plugins/domains/pinterest.com/pinterest.board.js
index 158d7d500..4f4bd8f5e 100644
--- a/plugins/domains/pinterest.com/pinterest.board.js
+++ b/plugins/domains/pinterest.com/pinterest.board.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: /^https?:\/\/(?:\w{2,3}\.)?pinterest(?:\.com?)?\.\w{2,3}\/((?!pin)[a-zA-Z0-9%_]+|pinterest)\/([a-zA-Z0-9%\-]+)\/?(?:$|\?|#)/i,
diff --git a/plugins/domains/pinterest.com/pinterest.pin.js b/plugins/domains/pinterest.com/pinterest.pin.js
index 56def9f4d..e1f67efc0 100644
--- a/plugins/domains/pinterest.com/pinterest.pin.js
+++ b/plugins/domains/pinterest.com/pinterest.pin.js
@@ -1,11 +1,10 @@
-module.exports = {
+export default {
re: /^(https?:\/\/(?:\w{2,3}\.)?pinterest(?:\.com?)?\.\w{2,3})\/pin\/(?:[^\/]+\-)?(\d+)/i,
mixins: [
- "*",
- "oembed-iframe"
+ "*"
],
// https://developers.pinterest.com/tools/widget-builder/?type=pin&terse=true&size=large
diff --git a/plugins/domains/pinterest.com/pinterest.user.js b/plugins/domains/pinterest.com/pinterest.user.js
index bafa21366..266546af1 100644
--- a/plugins/domains/pinterest.com/pinterest.user.js
+++ b/plugins/domains/pinterest.com/pinterest.user.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: /^https?:\/\/(?:\w{2,3}\.)?pinterest(?:\.com?)?\.\w{2,3}\/((?!pin)[a-zA-Z0-9%_]+|pinterest)\/?(?:$|\?|#)/i,
diff --git a/plugins/domains/polldaddy.com.js b/plugins/domains/polldaddy.com.js
index b737898f8..f534adb10 100644
--- a/plugins/domains/polldaddy.com.js
+++ b/plugins/domains/polldaddy.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/(?:\w+\.)?polldaddy\.com\/poll\/([0-9]+)/i,
diff --git a/plugins/domains/prezi.com.js b/plugins/domains/prezi.com.js
index cb460d533..dc1f6fd3c 100644
--- a/plugins/domains/prezi.com.js
+++ b/plugins/domains/prezi.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: /^https:\/\/prezi\.com\/([a-z0-9\-_]+)\/[^\/]+\/(?:\?[^\/\?]+)?$/i,
diff --git a/plugins/domains/quizlet.com.js b/plugins/domains/quizlet.com.js
index b29a759fb..d4dc4cf03 100644
--- a/plugins/domains/quizlet.com.js
+++ b/plugins/domains/quizlet.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/quizlet\.com\/(?:\w{2}\/)?(\d+)\/([^\/]+)\/?/i
diff --git a/plugins/domains/rapgenius.com.js b/plugins/domains/rapgenius.com.js
index 7b469de82..f90770575 100644
--- a/plugins/domains/rapgenius.com.js
+++ b/plugins/domains/rapgenius.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: /^https?:\/\/(?:[\w\-]+\.)?genius\.com\/(?!jobs)([a-zA-Z0-9\-]+)/i,
diff --git a/plugins/domains/readymag.com.js b/plugins/domains/readymag.com.js
index 773912e5d..563c9b702 100644
--- a/plugins/domains/readymag.com.js
+++ b/plugins/domains/readymag.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/readymag\.com\/\w+\/(\d+)/i
diff --git a/plugins/domains/scribd.com/scribd.com-error.js b/plugins/domains/scribd.com/scribd.com-error.js
index 74ae24214..e155a89e7 100644
--- a/plugins/domains/scribd.com/scribd.com-error.js
+++ b/plugins/domains/scribd.com/scribd.com-error.js
@@ -1,8 +1,9 @@
-const URL = require("url");
+import * as URL from "url";
+import scribd_com from './scribd.com.js';
-module.exports = {
+export default {
- re: require('./scribd.com').re,
+ re: scribd_com.re,
provides: ["scribdData"],
diff --git a/plugins/domains/scribd.com/scribd.com.js b/plugins/domains/scribd.com/scribd.com.js
index dffc16ab7..fd53f1be1 100644
--- a/plugins/domains/scribd.com/scribd.com.js
+++ b/plugins/domains/scribd.com/scribd.com.js
@@ -1,22 +1,14 @@
-const $ = require('cheerio');
-const utils = require('../../../lib/utils');
-const querystring = require('querystring');
-const URL = require("url");
-
-module.exports = {
+export default {
re: [
/^https?:\/\/(?:www|\w{2})\.scribd\.com\/(doc|document|embeds|presentation|fullscreen)\/(\d+)/i
],
- provides: ['scribdData'],
-
- mixins: [ "*" ],
+ mixins: [ "*", "query"],
- getLink: function(url, scribdData, options) {
- var href = scribdData.href;
- var params = URL.parse(href, true).query;
- var hash = URL.parse(url, true).hash;
+ getLink: function(url, iframe, query, options) {
+ var params = Object.assign(iframe.query);
+ var hash = query.hash;
var slideshow = options.getRequestOptions('scribd.slideshow', params.view_mode === 'slideshow');
if (slideshow) {
@@ -36,10 +28,10 @@ module.exports = {
}
return {
- href: href.replace(/\?.+/, '') + querystring.stringify(params).replace(/^(.)/, '?$1'),
+ href: iframe.assignQuerystring(params),
accept: CONFIG.T.text_html,
rel: slideshow ? [CONFIG.R.player, CONFIG.R.slideshow, CONFIG.R.html5, CONFIG.R.oembed] : [CONFIG.R.reader, CONFIG.R.html5, CONFIG.R.oembed],
- 'aspect-ratio': scribdData.aspect,
+ 'aspect-ratio': iframe['data-aspect-ratio'],
'padding-bottom': 45, // toolbar
options: {
slideshow: {
@@ -55,48 +47,15 @@ module.exports = {
}
},
- getData: function(urlMatch, og, oembed, options, cb) {
-
- if (!og.image) {
- return 'embeds' === urlMatch[1]
- ? cb({redirect: `https://www.scribd.com/document/${urlMatch[2]}`})
- : cb(null, null);
- }
-
- utils.getImageMetadata(og.image.value || og.image, options, function(error, data) {
-
- if (error || data.error) {
- console.log ('Error getting preview for Scribd: ' + error);
- } else {
- var $container = $('
');
- try {
- $container.html(oembed.html);
- } catch(ex) {}
-
- var $iframe = $container.find('iframe');
- if ($iframe.length === 1) {
-
- return cb(null, {
- scribdData: {
- aspect:
- data.width
- && data.height
- ? data.width / data.height
- : (oembed.thumbnail_height ? oembed.thumbnail_width / oembed.thumbnail_height : null),
-
- href: $iframe.attr('src')
- }
- })
-
- } else {
- return cb(null, null)
- }
- }
- });
+ getData: function(urlMatch, options, cb) {
+ return 'embeds' === urlMatch[1]
+ ? cb({redirect: `https://www.scribd.com/document/${urlMatch[2]}`})
+ : cb(null, null);
},
tests: [{
- noFeeds: true
+ noFeeds: true,
+ skipMethods: ['getData']
},
"https://www.scribd.com/doc/116154615/Australia-Council-Arts-Funding-Guide-2013",
"https://www.scribd.com/document/399637688/Prestons-Advert"
diff --git a/plugins/domains/simplecast.com.js b/plugins/domains/simplecast.com.js
index a2c5ddcb8..dce05bbf9 100644
--- a/plugins/domains/simplecast.com.js
+++ b/plugins/domains/simplecast.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
// also used for hosted simplecasts
re: [
diff --git a/plugins/domains/slid.es.js b/plugins/domains/slid.es.js
index 2e8af5342..3b35555d2 100644
--- a/plugins/domains/slid.es.js
+++ b/plugins/domains/slid.es.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/slides\.com\/([a-zA-Z0-9_\-]+)\/([a-zA-Z0-9_\-]+)/i
],
diff --git a/plugins/domains/slideshare.net.js b/plugins/domains/slideshare.net.js
index 9d401bb12..5ac94e6c9 100644
--- a/plugins/domains/slideshare.net.js
+++ b/plugins/domains/slideshare.net.js
@@ -1,7 +1,6 @@
-var utils = require('../../lib/utils');
-var $ = require('cheerio');
+import * as utils from '../../lib/utils.js';
-module.exports = {
+export default {
mixins: [
// "*" // Linking to * will enable oembed-rich and will result in incorrect aspect-ratios
@@ -12,7 +11,8 @@ module.exports = {
"canonical",
"description",
"oembed-site",
- "oembed-title"
+ "oembed-title",
+ "oembed-iframe"
],
getMeta: function(meta) {
@@ -30,62 +30,47 @@ module.exports = {
},
- getLink: function(oembed, options, cb) {
+ getLink: function(oembed, iframe, options, cb) {
- if (oembed.slide_image_baseurl && oembed.slide_image_baseurl_suffix) {
- var links = [];
+ if (iframe.src && oembed.slide_image_baseurl && oembed.slide_image_baseurl_suffix) {
var firstSlide = (/^\/\//.test(oembed.slide_image_baseurl) ? 'http:' : '') + oembed.slide_image_baseurl + '1' + oembed.slide_image_baseurl_suffix;
utils.getImageMetadata(firstSlide, options, function(error, data) {
- if (error || data.error) {
-
- console.log ('Error getting first slide for Slideshare: ' + error);
-
- } else if (data.width && data.height) {
-
- links.push({
- href: firstSlide,
- type: CONFIG.T.image,
- rel: CONFIG.R.thumbnail,
- width: data.width,
- height: data.height
- });
- }
-
- var $container = $('
');
- try {
- $container.html(oembed.html);
- } catch(ex) {}
-
- var $iframe = $container.find('iframe');
-
- var aspect = (data.width && data.height) ? data.width / data.height : oembed.width / oembed.height;
-
- if ($iframe.length == 1) {
- links.push({
- href: $iframe.attr('src').replace('http:', ''),
- type: CONFIG.T.text_html,
- rel: [aspect > 1 ? CONFIG.R.player : CONFIG.R.reader, CONFIG.R.slideshow, CONFIG.R.html5],
- "aspect-ratio": aspect,
- "padding-bottom": 58
- });
+ if (error || data.error || !data.width || !data.height) {
+
+ return cb('Error getting first slide for Slideshare: ' + error);
+
+ } else {
+
+ var aspect = (data.width && data.height) ? data.width / data.height : oembed.width / oembed.height;
+
+ return cb(null, [{
+ href: firstSlide,
+ type: CONFIG.T.image,
+ rel: CONFIG.R.thumbnail,
+ width: data.width,
+ height: data.height
+ }, {
+ href: oembed.thumbnail,
+ type: CONFIG.T.image,
+ rel: [CONFIG.R.thumbnail, CONFIG.R.oembed],
+ width: oembed.thumbnail_width,
+ height: data.height ? Math.round (oembed.thumbnail_width / (data.width / data.height)) : oembed.thumbnail_height
+ }, {
+ href: iframe.src,
+ type: CONFIG.T.text_html,
+ rel: [aspect > 1 ? CONFIG.R.player : CONFIG.R.reader, CONFIG.R.slideshow, CONFIG.R.html5],
+ "aspect-ratio": aspect,
+ "padding-bottom": 58
+ }
+ ]);
}
- links.push ({
- href: oembed.thumbnail,
- type: CONFIG.T.image,
- rel: [CONFIG.R.thumbnail, CONFIG.R.oembed],
- width: oembed.thumbnail_width,
- height: data.height ? Math.round (oembed.thumbnail_width / (data.width / data.height)) : oembed.thumbnail_height
- });
-
- cb(null, links);
-
});
} else {
- cb (null, null);
+ cb(null, null);
}
},
@@ -104,7 +89,7 @@ module.exports = {
page: "http://www.slideshare.net/popular/today",
selector: "a.iso_slideshow_link"
}, {skipMethods: ["getData"]},
- "http://www.slideshare.net/geniusworks/gamechangers-the-next-generation-of-business-innovation-by-peter-fisk#btnNext",
+ "https://www.slideshare.net/DataReportal/digital-2020-global-digital-overview-january-2020-v01-226017535",
"https://www.slideshare.net/EnjoyDigitAll/le-design-thinking-by-enjoydigitall-71136562"
]
};
\ No newline at end of file
diff --git a/plugins/domains/smugmug.com.js b/plugins/domains/smugmug.com.js
index f67ac9f47..3d4f2cdc2 100644
--- a/plugins/domains/smugmug.com.js
+++ b/plugins/domains/smugmug.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
mixins: [
"*"
diff --git a/plugins/domains/soundcloud.com/soundcloud-fallbacks.js b/plugins/domains/soundcloud.com/soundcloud-fallbacks.js
index 1c1f69a2d..46dde6e9a 100644
--- a/plugins/domains/soundcloud.com/soundcloud-fallbacks.js
+++ b/plugins/domains/soundcloud.com/soundcloud-fallbacks.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
provides: ['sound'],
diff --git a/plugins/domains/soundcloud.com/soundcloud-oembed-error.js b/plugins/domains/soundcloud.com/soundcloud-oembed-error.js
index 38a2cc529..c4beb1ce9 100644
--- a/plugins/domains/soundcloud.com/soundcloud-oembed-error.js
+++ b/plugins/domains/soundcloud.com/soundcloud-oembed-error.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
provides: ['__allow_soundcloud_meta', 'iframe'],
diff --git a/plugins/domains/soundcloud.com/soundcloud.com.js b/plugins/domains/soundcloud.com/soundcloud.com.js
index c6d11a2e6..a27734e83 100644
--- a/plugins/domains/soundcloud.com/soundcloud.com.js
+++ b/plugins/domains/soundcloud.com/soundcloud.com.js
@@ -1,16 +1,13 @@
-const $ = require('cheerio');
-const querystring = require('querystring');
-const URL = require("url");
+export default {
-module.exports = {
-
- provides: ['__allow_soundcloud_meta', 'sound', 'iframe'],
+ provides: ['__allow_soundcloud_meta', 'sound'],
mixins: [
"oembed-title",
"oembed-site",
"oembed-author",
"oembed-description",
+ "oembed-iframe",
// do not link to meta as it disables support for direct player urls redirects from w.soundcloud.com
"domain-icon"
],
@@ -21,8 +18,7 @@ module.exports = {
if (iframe.src && sound.count !== 0) {
- var href = iframe.src;
- var params = URL.parse(href, true).query;
+ var params = Object.assign(iframe.query);
if (options.getRequestOptions('players.horizontal', options.getProviderOptions('soundcloud.old_player') || options.getProviderOptions(CONFIG.O.less))) {
params.visual = false;
@@ -37,7 +33,7 @@ module.exports = {
params.color = options.getProviderOptions('soundcloud.color');
}
- href = href.replace(/\?.+/, '') + querystring.stringify(params).replace(/^(.)/, '?$1');
+ var href = iframe.assignQuerystring(params);
var height = options.getRequestOptions('soundcloud.height', options.getProviderOptions('players.horizontal') === false ? 0 : (/visual=false/.test(href) ? 166 : iframe.height));
// Fallback to old values.
if (height === 'auto') {
@@ -118,8 +114,7 @@ module.exports = {
) || !oembed.description)
) {
return {
- __allow_soundcloud_meta: true,
- iframe: oembed.getIframe()
+ __allow_soundcloud_meta: true
}
} else {
@@ -132,8 +127,7 @@ module.exports = {
width: oembed.thumbnail_width,
height: oembed.thumbnail_height
}
- },
- iframe: oembed.getIframe()
+ }
}
}
},
diff --git a/plugins/domains/soundcloud.com/w.soundcloud.com.js b/plugins/domains/soundcloud.com/w.soundcloud.com.js
index bd8851bae..0cbb93820 100644
--- a/plugins/domains/soundcloud.com/w.soundcloud.com.js
+++ b/plugins/domains/soundcloud.com/w.soundcloud.com.js
@@ -1,6 +1,6 @@
-const URL = require('url');
+import * as URL from 'url';
-module.exports = {
+export default {
re: [
/^https:?\/\/w\.soundcloud\.com\/player\/?\?/i
diff --git a/plugins/domains/speakerdeck.com.js b/plugins/domains/speakerdeck.com.js
index a36ffb5ea..c732438b1 100644
--- a/plugins/domains/speakerdeck.com.js
+++ b/plugins/domains/speakerdeck.com.js
@@ -1,53 +1,32 @@
-var $ = require('cheerio');
-
-module.exports = {
+export default {
mixins: [
- "oembed-title",
- "oembed-site",
- "oembed-author",
- "domain-icon",
- "og-description"
+ "*", "query"
],
- getLink: function (url, oembed) {
- var $container = $('
');
- try {
- $container.html(oembed.html);
- } catch(ex) {}
+ getLink: function (url, iframe, query, options) {
- var $iframe = $container.find('iframe');
- var doc;
+ var slide = options.getRequestOptions('speakerdeck.slide', query.slide ? parseInt(query.slide) || 1 : 1);
- if ($iframe.length == 1) {
- var href = $iframe.attr('src').replace(/^\/\//, 'https://');
- if (/\?slide=\d+/i.test(url)) {
+ if (iframe.src && iframe.width && iframe.height) {
+ var href = iframe.src.replace(/^\/\//, 'https://');
+ if (slide > 1) {
href += href.indexOf('?') > -1 ? '&' : '?';
- href += url.match(/\?(slide=\d+)/i)[1];
+ href += 'slide=' + slide;
}
- doc = {
+ return {
href: href,
type: CONFIG.T.text_html,
rel: [CONFIG.R.player, CONFIG.R.html5],
- "aspect-ratio": oembed.width / oembed.height
+ "aspect-ratio": iframe.width / iframe.height,
+ options: {
+ slide: {
+ label: CONFIG.L.page,
+ value: slide
+ }
+ }
}
}
-
- var thumbnail;
-
- if (doc) {
- var id = doc.href.match(/\/\/speakerdeck\.com\/player\/([a-z0-9\-]+)/i)[1];
-
- if (id) {
- thumbnail = {
- href: 'https://speakerd.s3.amazonaws.com/presentations/' + id + '/slide_0.jpg',
- type: CONFIG.T.image,
- rel: [CONFIG.R.thumbnail]
- };
- }
- }
-
- return [doc, thumbnail];
},
diff --git a/plugins/domains/spotify.com-meta-fallback.js b/plugins/domains/spotify.com-meta-fallback.js
index cad168e23..b445f041f 100644
--- a/plugins/domains/spotify.com-meta-fallback.js
+++ b/plugins/domains/spotify.com-meta-fallback.js
@@ -1,6 +1,8 @@
-module.exports = {
+import spotify_com from './spotify.com.js';
- re: require('./spotify.com').re,
+export default {
+
+ re: spotify_com.re,
provides: ['meta'],
diff --git a/plugins/domains/spotify.com.js b/plugins/domains/spotify.com.js
index f11d9fca6..2b7adf0bf 100644
--- a/plugins/domains/spotify.com.js
+++ b/plugins/domains/spotify.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/(?:open|play|www)\.spotify\.com\/(?:track|album|artist|show|episode|playlist)/i
@@ -6,9 +6,9 @@ module.exports = {
mixins: [
"oembed-title",
- "oembed-iframe",
"og-image",
"oembed-thumbnail",
+ "oembed-iframe",
"domain-icon"
],
@@ -28,18 +28,16 @@ module.exports = {
if (iframe.src) {
- var src = iframe.src;
-
var horizontal_player = options.getRequestOptions('players.horizontal', options.getProviderOptions(CONFIG.O.less));
var player = {
- href: src,
+ href: iframe.src,
type: CONFIG.T.text_html,
rel: [CONFIG.R.player, CONFIG.R.ssl, CONFIG.R.html5],
options: {}
};
- if (/album|playlist/.test(src)) {
+ if (/album|playlist/.test(iframe.src)) {
var include_playlist = options.getRequestOptions('spotify.playlist', true);
player.rel.push(CONFIG.R.playlist);
player.options.playlist = {
@@ -55,8 +53,8 @@ module.exports = {
};
// Temp fix for broken v2 playlist.
- player.href = src.replace(/\/embed\/playlist\-v2\//, '/embed/playlist/');
- } else if (/episode|show/.test(src)) {
+ player.href = iframe.src.replace(/\/embed\/playlist\-v2\//, '/embed/playlist/');
+ } else if (/episode|show/.test(iframe.src)) {
player.rel.push(CONFIG.R.audio);
player.height = iframe.height || 232;
} else {
diff --git a/plugins/domains/strawpoll.me.js b/plugins/domains/strawpoll.me.js
index 20066396f..d270a4ca5 100644
--- a/plugins/domains/strawpoll.me.js
+++ b/plugins/domains/strawpoll.me.js
@@ -1,7 +1,6 @@
-var $ = require('cheerio');
-var entities = require('entities');
+import * as entities from 'entities';
-module.exports = {
+export default {
re: /^https?:\/\/(?:www\.)?strawpoll\.me\/([0-9]+)$/i,
@@ -10,7 +9,7 @@ module.exports = {
getLink: function(urlMatch, cheerio) {
var embed = entities.decodeHTML(cheerio('#embed-field-' + urlMatch[1]).attr('value'));
- var iframe = $('
').html(embed).children('iframe');
+ var iframe = cheerio('
').html(embed).children('iframe');
var height = parseInt(iframe.css('height').replace(/px$/, ''), 10) || 300;
var width = parseInt(iframe.css('width').replace(/px$/, ''), 10) || 690;
@@ -26,7 +25,7 @@ module.exports = {
},
tests: [
- "http://www.strawpoll.me/1696",
+ "https://www.strawpoll.me/1696",
"https://strawpoll.me/136"
]
};
diff --git a/plugins/domains/sverigesradio.se.js b/plugins/domains/sverigesradio.se.js
index 4fb71b863..82b15e34b 100644
--- a/plugins/domains/sverigesradio.se.js
+++ b/plugins/domains/sverigesradio.se.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
// This is for articles only - players are covered by oembed auto-discovery
re: [
@@ -14,8 +14,6 @@ module.exports = {
request({
uri: "http://sverigesradio.se/sida/playerajax/getaudiourl?id=" + urlMatch[1] + "&type=publication&quality=medium&format=iis",
- limit: 1,
- timeout: 1000,
prepareResult: function(error, response, body, cb) {
// 404 means article is not embeddable
diff --git a/plugins/domains/ted.com/ted.com.js b/plugins/domains/ted.com/ted.com.js
index 3d88243c7..a36b6dab7 100644
--- a/plugins/domains/ted.com/ted.com.js
+++ b/plugins/domains/ted.com/ted.com.js
@@ -1,6 +1,6 @@
-const URL = require('url');
+import * as URL from 'url';
-module.exports = {
+export default {
re: /^https?:\/\/(?:www\.)?ted\.com\/talks\//i,
diff --git a/plugins/domains/ted.com/ted.playlists.js b/plugins/domains/ted.com/ted.playlists.js
index daed00cf6..d3a0769be 100644
--- a/plugins/domains/ted.com/ted.playlists.js
+++ b/plugins/domains/ted.com/ted.playlists.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: /^https?:\/\/(?:www\.)?ted\.com\/playlists\//i,
diff --git a/plugins/domains/test.com/test1.js b/plugins/domains/test.com/test1.js
index d82cda261..01ef363d1 100644
--- a/plugins/domains/test.com/test1.js
+++ b/plugins/domains/test.com/test1.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
provides: 'test_data1',
diff --git a/plugins/domains/test.com/test2.js b/plugins/domains/test.com/test2.js
index 519bfb8cf..33fd1557c 100644
--- a/plugins/domains/test.com/test2.js
+++ b/plugins/domains/test.com/test2.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
provides: ['test_data2', 'test_plugin'],
diff --git a/plugins/domains/test.com/test3.js b/plugins/domains/test.com/test3.js
index 45843d327..7e0d746cc 100644
--- a/plugins/domains/test.com/test3.js
+++ b/plugins/domains/test.com/test3.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
getLink: function(test_data2) {
return {
diff --git a/plugins/domains/theatlas.com/theatlas.com.js b/plugins/domains/theatlas.com/theatlas.com.js
index db2f7ff29..04dd29855 100644
--- a/plugins/domains/theatlas.com/theatlas.com.js
+++ b/plugins/domains/theatlas.com/theatlas.com.js
@@ -1,6 +1,6 @@
-var utils = require('../../../lib/utils');
+import * as utils from '../../../lib/utils.js';
-module.exports = {
+export default {
re: [
/^https?:\/\/(?:www\.)?theatlas\.com\/charts\/([a-zA-Z0-9]+)/i
diff --git a/plugins/domains/theguardian.com/guardian.video.js b/plugins/domains/theguardian.com/guardian.video.js
index 9e2ebcafd..352d42157 100644
--- a/plugins/domains/theguardian.com/guardian.video.js
+++ b/plugins/domains/theguardian.com/guardian.video.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: /https?:\/\/www\.theguardian\.com\/[\w-]+\/video\/\d+\/\w+\/\d+\/[\w-]+/i,
diff --git a/plugins/domains/theta360.com/theta360.com.js b/plugins/domains/theta360.com/theta360.com.js
index 7f6c185b4..0cdffe9c3 100644
--- a/plugins/domains/theta360.com/theta360.com.js
+++ b/plugins/domains/theta360.com/theta360.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: /https:\/\/theta360\.com\/(?:spheres|s)(?:\/\w+)?\/[\w-]+/i,
diff --git a/plugins/domains/tmz.com.js b/plugins/domains/tmz.com.js
index 345a1040d..fcca586c1 100644
--- a/plugins/domains/tmz.com.js
+++ b/plugins/domains/tmz.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: /^https?:\/\/www\.tmz\.com\/videos\/([a-zA-Z0-9_]+)/,
diff --git a/plugins/domains/tumblr.com/tumblr.api.js b/plugins/domains/tumblr.com/tumblr.api.js
index 0cbdd25d3..a3a44edf1 100644
--- a/plugins/domains/tumblr.com/tumblr.api.js
+++ b/plugins/domains/tumblr.com/tumblr.api.js
@@ -1,7 +1,7 @@
-var $ = require('cheerio');
-var _ = require('underscore');
+import cheerio from 'cheerio';
-module.exports = {
+
+export default {
re: [
/^https?:\/\/([a-z0-9-]+\.tumblr\.com)\/(post|image)\/(\d+)(?:\/[a-z0-9-]+)?/i,
@@ -12,7 +12,7 @@ module.exports = {
getMeta: function(tumblr_post) {
- var caption = tumblr_post.caption ? $('
').html(tumblr_post.caption).text() : "";
+ var caption = tumblr_post.caption ? cheerio('
').html(tumblr_post.caption).text() : "";
if (caption && caption.length > 160) {
caption = caption.split(/[.,!?]/)[0];
}
@@ -23,11 +23,11 @@ module.exports = {
author: tumblr_post.blog_name,
author_url: 'https://' + tumblr_post.blog_name + '.tumblr.com',
canonical: tumblr_post.permalink_url || tumblr_post.post_url,
- tags: _.unique([].concat(tumblr_post.tags, tumblr_post.featured_in_tag || [])).join(', '),
+ tags: tumblr_post.tags && tumblr_post.tags.join(', '),
shortlink: tumblr_post.short_url,
date: tumblr_post.date,
duration: tumblr_post.duration,
- description: tumblr_post.body && /
').html(tumblr_post.body).find('p').first().text() : null
+ description: tumblr_post.body && /
').html(tumblr_post.body).find('p').first().text() : null
};
},
@@ -75,12 +75,10 @@ module.exports = {
id: urlMatch[3]
},
json: true,
- limit: 1,
- timeout: 1000,
prepareResult: function (error, response, body, cb) {
if (error || body.errors) {
- return cb(error || 'There was a Tumblr API error error');
+ return cb(error || body.errors || 'There was a Tumblr API error');
}
if (!body.meta) {
diff --git a/plugins/domains/tumblr.com/tumblr.oembed.js b/plugins/domains/tumblr.com/tumblr.oembed.js
index 08c85c763..640647f80 100644
--- a/plugins/domains/tumblr.com/tumblr.oembed.js
+++ b/plugins/domains/tumblr.com/tumblr.oembed.js
@@ -1,8 +1,10 @@
/* Tumblr embed codes are broken as of Feb 13, 2020 */
-module.exports = {
+import tumblr_api from './tumblr.api.js';
- re: require('./tumblr.api').re,
+export default {
+
+ re: tumblr_api.re,
getLink: function(tumblr_post, oembed, options) {
diff --git a/plugins/domains/tumblr.com/tumblr.photo.js b/plugins/domains/tumblr.com/tumblr.photo.js
index d4eefd06d..914f6ec7b 100644
--- a/plugins/domains/tumblr.com/tumblr.photo.js
+++ b/plugins/domains/tumblr.com/tumblr.photo.js
@@ -1,9 +1,12 @@
-var _ = require('underscore');
-var $ = require('cheerio');
+import * as _ from 'underscore';
+import cheerio from 'cheerio';
-module.exports = {
- re: require('./tumblr.api').re,
+import tumblr_api from './tumblr.api.js';
+
+export default {
+
+ re: tumblr_api.re,
getLinks: function(tumblr_post) {
@@ -27,7 +30,7 @@ module.exports = {
tumblr_post.photos.forEach(function(photo) {
var title = photo.caption || tumblr_post.caption;
- title = $('
').html(title).text();
+ title = cheerio('
').html(title).text();
if (title && title.length > 160) {
title = title.split(/[.,!?]/)[0];
}
diff --git a/plugins/domains/tumblr.com/tumblr.text.js b/plugins/domains/tumblr.com/tumblr.text.js
index aae3a86ef..dc3d59222 100644
--- a/plugins/domains/tumblr.com/tumblr.text.js
+++ b/plugins/domains/tumblr.com/tumblr.text.js
@@ -1,8 +1,10 @@
-var $ = require('cheerio');
+import cheerio from 'cheerio';
-module.exports = {
+import tumblr_api from './tumblr.api.js';
- re: require('./tumblr.api').re,
+export default {
+
+ re: tumblr_api.re,
getMeta: function (tumblr_post) {
if (tumblr_post.type == "text") {
@@ -18,7 +20,7 @@ module.exports = {
return;
}
- var $post = $('
').html(tumblr_post.body);
+ var $post = cheerio('
').html(tumblr_post.body);
var $image = $post.find('img').first(); // Could be more than 1 image, true. But the response time will be unacceptable as post-processing will check all image sizes.
if ($image ) {
diff --git a/plugins/domains/tumblr.com/tumblr.video.js b/plugins/domains/tumblr.com/tumblr.video.js
index 8fca974f5..7a3f02ff6 100644
--- a/plugins/domains/tumblr.com/tumblr.video.js
+++ b/plugins/domains/tumblr.com/tumblr.video.js
@@ -1,8 +1,10 @@
-const $ = require('cheerio');
+import cheerio from 'cheerio';
-module.exports = {
+import tumblr_api from './tumblr.api.js';
- re: require('./tumblr.api').re,
+export default {
+
+ re: tumblr_api.re,
getLink: function(tumblr_post) {
@@ -24,7 +26,7 @@ module.exports = {
var p = tumblr_post.player instanceof Array ? tumblr_post.player[0] : tumblr_post.player;
- var $c = $('
').append(p.embed_code);
+ var $c = cheerio('
').append(p.embed_code);
var $iframe = $c.find('iframe');
if ($iframe.length) {
diff --git a/plugins/domains/twitch.tv/clips.twitch.tv.js b/plugins/domains/twitch.tv/clips.twitch.tv.js
index e76ced53b..21ab7d97c 100644
--- a/plugins/domains/twitch.tv/clips.twitch.tv.js
+++ b/plugins/domains/twitch.tv/clips.twitch.tv.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/clips.twitch\.tv\/([^\?\/]+)(?:\?[^\?]+)?$/i,
diff --git a/plugins/domains/twitch.tv/twitch-live-fallback.js b/plugins/domains/twitch.tv/twitch-live-fallback.js
index 5290ef45f..5100ce205 100644
--- a/plugins/domains/twitch.tv/twitch-live-fallback.js
+++ b/plugins/domains/twitch.tv/twitch-live-fallback.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/(?:www\.|go\.)?twitch\.tv\/([a-zA-Z0-9_]+)(?:\?parent=.*)?$/i,
diff --git a/plugins/domains/twitch.tv/twitch.tv.js b/plugins/domains/twitch.tv/twitch.tv.js
index e2903ad03..19d434855 100644
--- a/plugins/domains/twitch.tv/twitch.tv.js
+++ b/plugins/domains/twitch.tv/twitch.tv.js
@@ -1,6 +1,6 @@
-const URL = require('url');
+import * as URL from 'url';
-module.exports = {
+export default {
re: [
/^https?:\/\/(?:www\.|go\.)?twitch\.tv\/[a-zA-Z0-9_]+\/v\/(\d+)/i,
diff --git a/plugins/domains/twitter.com/twitter.og.js b/plugins/domains/twitter.com/twitter.og.js
index 990e7732d..bdd394715 100644
--- a/plugins/domains/twitter.com/twitter.og.js
+++ b/plugins/domains/twitter.com/twitter.og.js
@@ -1,6 +1,8 @@
-module.exports = {
+import twitter_status from './twitter.status.js';
- re: require('./twitter.status').re,
+export default {
+
+ re: twitter_status.re,
provides: ['twitter_og'],
diff --git a/plugins/domains/twitter.com/twitter.status.js b/plugins/domains/twitter.com/twitter.status.js
index acb3ffd20..b5a7b8f50 100644
--- a/plugins/domains/twitter.com/twitter.status.js
+++ b/plugins/domains/twitter.com/twitter.status.js
@@ -1,182 +1,81 @@
-var async = require('async');
-var cache = require('../../../lib/cache');
-var sysUtils = require('../../../logging');
-var _ = require('underscore');
-var entities = require('entities');
+import log from '../../../logging.js';
+import * as entities from 'entities';
-module.exports = {
+export default {
- re: [
- /^https?:\/\/twitter\.com\/(?:\w+)\/status(?:es)?\/(\d+)/i
- ],
+ re: /^https?:\/\/twitter\.com\/(?:\w+)\/status(?:es)?\/(\d+)/i,
provides: ['twitter_oembed', 'twitter_og', '__allowTwitterOg'],
mixins: ['domain-icon'],
getData: function(urlMatch, request, options, cb) {
- var id = urlMatch[1];
var c = options.getProviderOptions("twitter") || options.getProviderOptions("twitter.status");
if (c.disabled) {
- return cb('Twitter API Disabled');
+ return cb('Twitter API disabled');
}
- var oauth = c.consumer_key
- ? {
- consumer_key: c.consumer_key,
- consumer_secret: c.consumer_secret,
- token: c.access_token,
- token_secret: c.access_token_secret
- } : false;
-
- var blockExpireIn = 0;
- var block_key = 'twbl:' + c.consumer_key;
-
- async.waterfall([
+ request({
+ url: "https://publish.twitter.com/oembed",
+ qs: {
+ hide_media: c.hide_media,
+ hide_thread: true, // c.hide_thread - now handled in getLinks. This is the only reliable way to detect if a tweet has the thread
+ omit_script: c.omit_script,
+ url: urlMatch[0]
+ },
+ json: true,
+ cache_key: 'twitter:oembed:' + urlMatch[1],
+ prepareResult: function(error, response, oembed, cb) {
- function(cb) {
+ if (error) {
+ return cb(error);
+ }
- if (oauth) {
- cache.get(block_key, cb);
- } else {
- cb(null, null);
+ if (response.fromRequestCache) {
+ log(' -- Twitter API cache used.');
}
- },
- function(expireIn, cb) {
+ if (response.statusCode === 404) {
+ return cb({
+ responseStatusCode: 404,
+ message: 'The tweet is no longer available.'
+ })
+
+ } else if (response.statusCode === 403) {
+ return cb({
+ responseStatusCode: 404,
+ message: 'It looks this Twitter account has been suspended.'
+ })
- if (expireIn) {
- var now = Math.round(new Date().getTime() / 1000);
- if (expireIn > now) {
- blockExpireIn = expireIn - now;
- }
+ } else if (response.statusCode !== 200) {
+ return cb('Non-200 response from Twitter API (statuses/oembed.json: ' + response.statusCode);
}
- var usePublicApi = !oauth || blockExpireIn > 0;
+ if (typeof oembed !== 'object') {
+ return cb('Object expected in Twitter API (statuses/oembed.json), got: ' + oembed);
+ }
- var apiUrl;
+ oembed.title = oembed.author_name + ' on Twitter';
+ oembed["min-width"] = c["min-width"];
+ oembed["max-width"] = c["max-width"];
- var qs = {
- hide_media: c.hide_media,
- hide_thread: true, // c.hide_thread - now handled in getLinks. This is the only reliable way to detect if a tweet has the thread
- omit_script: c.omit_script
+ var result = {
+ twitter_oembed: oembed
};
- if (usePublicApi) {
- apiUrl = "https://publish.twitter.com/oembed";
- qs.url = urlMatch[0];
+ if (/pic\.twitter\.com/i.test(oembed.html)) {
+ result.__allowTwitterOg = true;
+ options.followHTTPRedirect = true; // avoid core's re-directs. Use HTTP request redirects instead
+ options.exposeStatusCode = true;
} else {
- apiUrl = "https://api.twitter.com/1.1/statuses/oembed.json";
- qs.id = id;
+ result.twitter_og = false;
}
- request(_.extend({
- url: apiUrl,
- qs: qs,
- json: true,
- cache_key: 'twitter:oembed:' + id,
- prepareResult: function(error, response, data, cb) {
-
- if (error) {
- return cb(error);
- }
-
- if (response.fromRequestCache) {
- if (blockExpireIn > 0) {
- sysUtils.log(' -- Twitter API limit reached (' + blockExpireIn + ' seconds left), but cache used.');
- } else {
- sysUtils.log(' -- Twitter API cache used.');
- }
- }
-
- // Do not block 1.1 api if data from cache.
- if (oauth && !response.fromRequestCache) {
-
- var remaining = parseInt(response.headers['x-rate-limit-remaining']);
-
- if (response.statusCode === 429 || remaining <= 7) {
- var now = Math.round(new Date().getTime() / 1000);
- var limitResetAt = parseInt(response.headers['x-rate-limit-reset']);
- var ttl = limitResetAt - now;
-
- // Do not allow ttl 0.
- // 5 seconds - to cover possible time difference with twitter.
- if (ttl < 5) {
- ttl = 5;
- }
-
- // Block maximum for 15 minutes.
- if (ttl > 15*60) {
- ttl = 15*60
- }
-
- if (response.statusCode === 429) {
- sysUtils.log(' -- Twitter API limit reached by status code 429. Disabling for ' + ttl + ' seconds.');
- } else {
- sysUtils.log(' -- Twitter API limit warning, remaining calls: ' + remaining + '. Disabling for ' + ttl + ' seconds.');
- }
-
- // Store expire date as value to be sure it past.
- var expireIn = now + ttl;
-
- cache.set(block_key, expireIn, {ttl: ttl});
- }
- }
-
- if (response.statusCode === 404) {
- return cb({
- responseStatusCode: 404,
- message: 'The tweet is no longer available.'
- })
- } else if (response.statusCode === 403) {
- return cb({
- responseStatusCode: 404,
- message: 'It looks this Twitter account has been suspended.'
- })
-
- } else if (response.statusCode !== 200) {
- return cb('Non-200 response from Twitter API (statuses/oembed.json: ' + response.statusCode);
- }
-
- if (typeof data !== 'object') {
- return cb('Object expected in Twitter API (statuses/oembed.json), got: ' + data);
- }
-
-
- cb(error, data);
- }
- }, usePublicApi ? null : {oauth: oauth}), cb); // add oauth if 1.1, else skip it
-
- }
-
- ], function(error, oembed) {
-
-
- if (error) {
- return cb(error);
- }
-
- oembed.title = oembed.author_name + ' on Twitter';
-
- oembed["min-width"] = c["min-width"];
- oembed["max-width"] = c["max-width"];
-
- var result = {
- twitter_oembed: oembed
- };
-
- if (/pic\.twitter\.com/i.test(oembed.html)) {
- result.__allowTwitterOg = true;
- options.followHTTPRedirect = true; // avoid core's re-directs. Use HTTP request redirects instead
- options.exposeStatusCode = true;
- } else {
- result.twitter_og = false;
+ return cb(error, result);
}
-
- cb(null, result);
- });
+ }, cb);
},
getMeta: function(twitter_oembed) {
diff --git a/plugins/domains/twitter.com/twitter.throttle.js b/plugins/domains/twitter.com/twitter.throttle.js
index 2e5ee6ca2..70d49b683 100644
--- a/plugins/domains/twitter.com/twitter.throttle.js
+++ b/plugins/domains/twitter.com/twitter.throttle.js
@@ -1,6 +1,9 @@
-module.exports = {
+import twitter_timelines from './twitter.timelines.js';
+import twitter_status from './twitter.status.js';
- re: require('./twitter.timelines').re.concat(require('./twitter.status').re),
+export default {
+
+ re: twitter_timelines.re.concat(twitter_status.re),
provides: ["meta"],
diff --git a/plugins/domains/twitter.com/twitter.timelines.js b/plugins/domains/twitter.com/twitter.timelines.js
index 2ed3fb7fd..561e8f41e 100644
--- a/plugins/domains/twitter.com/twitter.timelines.js
+++ b/plugins/domains/twitter.com/twitter.timelines.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
// Embedded Like, Collection, and Moment Timelines are now retired.
// https://twittercommunity.com/t/removing-support-for-embedded-like-collection-and-moment-timelines/150313
diff --git a/plugins/domains/usatoday-allowEmbedURL.js b/plugins/domains/usatoday-allowEmbedURL.js
index 9692ecfcb..a3528d11e 100644
--- a/plugins/domains/usatoday-allowEmbedURL.js
+++ b/plugins/domains/usatoday-allowEmbedURL.js
@@ -1,6 +1,8 @@
-module.exports = {
+import usatoday_com from './usatoday.com.js';
- re: require('./usatoday.com').re,
+export default {
+
+ re: usatoday_com.re,
provides: '__allowEmbedURL',
diff --git a/plugins/domains/usatoday.com.js b/plugins/domains/usatoday.com.js
index d6caf9a6e..605f52ba5 100644
--- a/plugins/domains/usatoday.com.js
+++ b/plugins/domains/usatoday.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/^https?:\/\/www\.([a-z\-]+)\.com\/media\/cinematic\/video\/(\d{7,12})\/[a-zA-Z0-9\-\_:\.]+\/?(?:[^\/]+)?$/i,
diff --git a/plugins/domains/v.qq.com.js b/plugins/domains/v.qq.com.js
index f56561d83..920b079e3 100644
--- a/plugins/domains/v.qq.com.js
+++ b/plugins/domains/v.qq.com.js
@@ -1,4 +1,4 @@
-var _ = require('underscore');
+import * as _ from 'underscore';
var res = [
/^https?:\/\/v\.qq\.com\/page\/\w\/\w\/\w\/(\w+)\.html$/i,
@@ -8,7 +8,7 @@ var res = [
/^https?:\/\/v\.qq\.com\/\w\/cover\/\w+\/(\w+)\.html/i
];
-module.exports = {
+export default {
re: res,
diff --git a/plugins/domains/vbox7.com.js b/plugins/domains/vbox7.com.js
index 007b67346..3e1ed0334 100644
--- a/plugins/domains/vbox7.com.js
+++ b/plugins/domains/vbox7.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/https?:\/\/(?:www\.)?vbox7\.com\/play:(\w+)/i
diff --git a/plugins/domains/vimeo-moogaloop.js b/plugins/domains/vimeo-moogaloop.js
index 2d43c1f46..edcb01730 100644
--- a/plugins/domains/vimeo-moogaloop.js
+++ b/plugins/domains/vimeo-moogaloop.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: /^https?:\/\/vimeo\.com\/moogaloop\.swf\?clip_id=(\d+)/i,
diff --git a/plugins/domains/vimeo.com.js b/plugins/domains/vimeo.com.js
index cad8493a5..47a0320ac 100644
--- a/plugins/domains/vimeo.com.js
+++ b/plugins/domains/vimeo.com.js
@@ -1,6 +1,6 @@
-const querystring = require('querystring');
+import * as querystring from 'querystring';
-module.exports = {
+export default {
re: [
/^https:\/\/vimeo\.com(?:\/channels?\/\w+)?\/\d+/i, // Includes private reviews like /video/123/ABC.
diff --git a/plugins/domains/washingtonpost.com.js b/plugins/domains/washingtonpost.com.js
index 2ebe6450d..1042f07fc 100644
--- a/plugins/domains/washingtonpost.com.js
+++ b/plugins/domains/washingtonpost.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: /^https:\/\/www\.washingtonpost\.com\/(?:video|posttv)\/\w+\/[a-z0-9-]+\/\d+\/\d+\/\d+\/([a-z0-9-]+)_video\.html/i,
diff --git a/plugins/domains/widgetic.com.js b/plugins/domains/widgetic.com.js
index 9af8e8c5f..78b1b8167 100644
--- a/plugins/domains/widgetic.com.js
+++ b/plugins/domains/widgetic.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: [
/https?:\/\/widgetic\.com\/widgets\//i,
diff --git a/plugins/domains/wistia.com.js b/plugins/domains/wistia.com.js
index 3bf63667b..796489b46 100644
--- a/plugins/domains/wistia.com.js
+++ b/plugins/domains/wistia.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: /^https?:\/\/([a-zA-Z0-9]+).wistia\.com\/medias\/([_a-zA-Z0-9]+)/i,
diff --git a/plugins/domains/xkcd.com.js b/plugins/domains/xkcd.com.js
index a65114092..76ea42fe0 100644
--- a/plugins/domains/xkcd.com.js
+++ b/plugins/domains/xkcd.com.js
@@ -1,6 +1,6 @@
-const decodeHTML5 = require('entities').decodeHTML5;
+import { decodeHTML5 } from 'entities';
-module.exports = {
+export default {
re: /^https?:\/\/(?:www.)?xkcd\.com\/\d+/i,
diff --git a/plugins/domains/youku.com.js b/plugins/domains/youku.com.js
index ff3c36a45..96dd4c3cb 100644
--- a/plugins/domains/youku.com.js
+++ b/plugins/domains/youku.com.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
//http://v.youku.com/v_show/id_XNDkwNjg2NzQw.html?f=18736842
re: [
diff --git a/plugins/domains/youtube.com/youtube.channel.js b/plugins/domains/youtube.com/youtube.channel.js
index c72cfee42..8055eed56 100644
--- a/plugins/domains/youtube.com/youtube.channel.js
+++ b/plugins/domains/youtube.com/youtube.channel.js
@@ -1,6 +1,6 @@
-const sysUtils = require('../../../logging')
+import log from '../../../logging.js'
-module.exports = {
+export default {
re: [
/^https?:\/\/(?:www\.)?youtube\.com\/(channel)\/([a-zA-Z0-9_-]+)/i,
@@ -90,7 +90,7 @@ module.exports = {
* as if no channel found, but it actually exists.
* Ex.: https://www.youtube.com/c/Figmadesign
*/
- sysUtils.log('YoutTube channel fallback for ' + url , data);
+ log('YoutTube channel fallback for ' + url , data);
cb({
message: 'YouTube channel not found via data API...'
// But no response code. Let's fallback to default parsers
diff --git a/plugins/domains/youtube.com/youtube.playlist.js b/plugins/domains/youtube.com/youtube.playlist.js
index 2e6cdde9d..d1bf1c0ec 100644
--- a/plugins/domains/youtube.com/youtube.playlist.js
+++ b/plugins/domains/youtube.com/youtube.playlist.js
@@ -1,6 +1,6 @@
-const querystring = require('querystring');
+import * as querystring from 'querystring';
-module.exports = {
+export default {
re: [
/^https?:\/\/www\.youtube\.com\/playlist\?(?:[=\-_a-zA-Z0-9&]+)?list=([\-_a-zA-Z0-9]+)/i
diff --git a/plugins/domains/youtube.com/youtube.shared.js b/plugins/domains/youtube.com/youtube.shared.js
index 86dd1d5a2..3b8778862 100644
--- a/plugins/domains/youtube.com/youtube.shared.js
+++ b/plugins/domains/youtube.com/youtube.shared.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
re: /^https?:\/\/www\.youtube\.com\/shared\/?\?ci=([a-zA-Z0-9_-]+)/i,
diff --git a/plugins/domains/youtube.com/youtube.video.js b/plugins/domains/youtube.com/youtube.video.js
index d2b266215..26d8d262e 100644
--- a/plugins/domains/youtube.com/youtube.video.js
+++ b/plugins/domains/youtube.com/youtube.video.js
@@ -1,9 +1,10 @@
-const cheerio = require('cheerio');
-const querystring = require('querystring');
-const _ = require('underscore');
-const sysUtils = require('../../../logging')
+import cheerio from 'cheerio';
-module.exports = {
+import * as querystring from 'querystring';
+import * as _ from 'underscore';
+import log from '../../../logging.js'
+
+export default {
re: [
/^https?:\/\/(?:www\.)?youtube\.com\/(?:tv#\/)?watch\/?\?(?:[^&]+&)*v=([a-zA-Z0-9_-]+)/i,
@@ -129,7 +130,7 @@ module.exports = {
} else if (data.items && data.items.length == 0 || data.error && data.error.code == 404) {
cb({responseStatusCode: 404});
} else {
- sysUtils.log('YoutTube fallback for ' + urlMatch[1], data);
+ log('YoutTube fallback for ' + urlMatch[1], data);
cb(null); // silence error for fallback to generic providers. data.error.code == 429 - too many requests; 400 - probably API key is invalid
}
}
diff --git a/plugins/links/article/article.js b/plugins/links/article/article.js
index 72821e6d0..d603f9154 100644
--- a/plugins/links/article/article.js
+++ b/plugins/links/article/article.js
@@ -1,6 +1,6 @@
-var utils = require('../../../lib/utils');
+import * as utils from '../../../lib/utils.js';
-module.exports = {
+export default {
getData: function(readability, meta, __is_general_article) {
diff --git a/plugins/links/article/check-article.js b/plugins/links/article/check-article.js
index 10e77f3d8..11185238e 100644
--- a/plugins/links/article/check-article.js
+++ b/plugins/links/article/check-article.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
provides: '__is_general_article',
diff --git a/plugins/links/canonical-redirect.js b/plugins/links/canonical-redirect.js
index 679260b11..36f8fb4c5 100644
--- a/plugins/links/canonical-redirect.js
+++ b/plugins/links/canonical-redirect.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
getLink: function(url, meta, options, cb) {
diff --git a/plugins/links/embedURL/checkEmbedURL.js b/plugins/links/embedURL/checkEmbedURL.js
index 350793ecc..beb89965e 100644
--- a/plugins/links/embedURL/checkEmbedURL.js
+++ b/plugins/links/embedURL/checkEmbedURL.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
provides: '__allowEmbedURL',
diff --git a/plugins/links/embedURL/embedURL.js b/plugins/links/embedURL/embedURL.js
index 48c747dfc..66a03de4e 100644
--- a/plugins/links/embedURL/embedURL.js
+++ b/plugins/links/embedURL/embedURL.js
@@ -1,7 +1,7 @@
-const decodeHTML5 = require('entities').decodeHTML5;
-const utils = require('../../../lib/utils');
+import { decodeHTML5 } from 'entities';
+import * as utils from '../../../lib/utils.js';
-module.exports = {
+export default {
provides: 'schemaVideoObject',
@@ -12,10 +12,10 @@ module.exports = {
if ($script.length === 1) {
try {
- var json = utils.parseJSONSource($script.text());
+ var json = utils.parseJSONSource($script.html());
if (json['@type']) {
- ld = {};
+ var ld = {};
ld[json['@type'].toLowerCase()] = json;
if (__allowEmbedURL !== 'skip_ld') {
diff --git a/plugins/links/embedURL/ld-video.js b/plugins/links/embedURL/ld-video.js
index a97fd2d69..cc0e978a7 100644
--- a/plugins/links/embedURL/ld-video.js
+++ b/plugins/links/embedURL/ld-video.js
@@ -1,6 +1,7 @@
-const cheerio = require('cheerio');
+import cheerio from 'cheerio';
-module.exports = {
+
+export default {
provides: [
'schemaVideoObject',
diff --git a/plugins/links/favicon.js b/plugins/links/favicon.js
index 5817d3250..367d95aac 100644
--- a/plugins/links/favicon.js
+++ b/plugins/links/favicon.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
getLink: function(meta) {
diff --git a/plugins/links/google-docs-viewer.js b/plugins/links/google-docs-viewer.js
index 17ea34970..e6215fcfb 100644
--- a/plugins/links/google-docs-viewer.js
+++ b/plugins/links/google-docs-viewer.js
@@ -1,6 +1,6 @@
-const utils = require('../../lib/utils');
+import * as utils from '../../lib/utils.js';
-module.exports = {
+export default {
getLink: function(url, __nonHtmlContentData, options) {
diff --git a/plugins/links/hosted/23video-hosted.js b/plugins/links/hosted/23video-hosted.js
index 8a163a59f..9ae4bb470 100644
--- a/plugins/links/hosted/23video-hosted.js
+++ b/plugins/links/hosted/23video-hosted.js
@@ -1,47 +1,18 @@
-var cheerio = require('cheerio');
+export default {
-module.exports = {
+ provides: ["oembed_domain"],
// linked to oembed, so won't run for all URLs
- getLink: function(meta, oembed, whitelistRecord) {
+ getData: function(meta, oembed, iframe, whitelistRecord) {
if (whitelistRecord.isDefault
- && oembed.type == 'video' && oembed.width && oembed.height
- && ((meta.em && meta.em.schema == '23video') || oembed.provider_name == 'TwentyThree')) {
+ && oembed.type == 'video'
+ && /\/v\.ihtml(?:\/player\.html)?/i.test(iframe.src)
+ && ((meta.em && meta.em.schema == '23video') || /^twentythree$/i.test(oembed.provider_name))) {
- var players = [];
-
- if (meta.video_src
- && /https?:\/\/[^.]+\.23video\.com\/\d+\/\d+\/\w+\/[^\?]+\.mp4/i.test(meta.video_src)) {
-
- players.push({
- href: meta.video_src,
- type: CONFIG.T.video_mp4,
- rel: [CONFIG.R.player, CONFIG.R.html5],
- 'aspect-ratio': oembed.width / oembed.height
- });
+ return {
+ oembed_domain: "23video.com"
}
-
- var $container = cheerio('
');
- try {
- $container.html(oembed.html);
- } catch (ex) {}
-
- var $iframe = $container.find('iframe');
-
- if ($iframe.length == 1 && /\/v\.ihtml(?:\/player\.html)?/i.test($iframe.attr('src'))) {
-
- players.push({
- href: $iframe.attr('src'),
- type: CONFIG.T.text_html,
- rel: [CONFIG.R.player, CONFIG.R.html5],
- 'aspect-ratio': oembed.width / oembed.height,
- autoplay: 'autoPlay=1'
- });
-
- }
-
- return players;
}
},
@@ -51,7 +22,7 @@ module.exports = {
"https://video.twentythree.net/intro-to-twentythrees-player-builder",
"http://videos.theconference.se/paul-adams-solving-real-world-problems",
"http://www.fftv.no/skipatruljen-s3e3-voss-resort",
- "https://videos.23video.com/novo-nordisk",
+ // "https://videos.23video.com/novo-nordisk",
"http://video.nextconf.eu/video/1880845/data-without-limits",
"http://stream.umbraco.org/v.ihtml?source=share&photo%5fid=11665495&autoPlay=0"
]
diff --git a/plugins/links/hosted/brightcove-allow-in-page.js b/plugins/links/hosted/brightcove-allow-in-page.js
index 43a4b0b18..97c1b13a1 100644
--- a/plugins/links/hosted/brightcove-allow-in-page.js
+++ b/plugins/links/hosted/brightcove-allow-in-page.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
provides: '__allowBrightcoveInPage',
diff --git a/plugins/links/hosted/brightcove-hosted.js b/plugins/links/hosted/brightcove-hosted.js
index c62629355..11cca8688 100644
--- a/plugins/links/hosted/brightcove-hosted.js
+++ b/plugins/links/hosted/brightcove-hosted.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
provides: '__promoUri',
diff --git a/plugins/links/hosted/brightcove-in-page-promo.js b/plugins/links/hosted/brightcove-in-page-promo.js
index 2165ff3f2..d159ea295 100644
--- a/plugins/links/hosted/brightcove-in-page-promo.js
+++ b/plugins/links/hosted/brightcove-in-page-promo.js
@@ -3,7 +3,7 @@
* http://docs.brightcove.com/en/perform/brightcove-player/guides/embed-in-page.html
*/
-module.exports = {
+export default {
provides: '__promoUri',
diff --git a/plugins/links/hosted/cloudapp-hosted.js b/plugins/links/hosted/cloudapp-hosted.js
index f79d77485..8e16540ca 100644
--- a/plugins/links/hosted/cloudapp-hosted.js
+++ b/plugins/links/hosted/cloudapp-hosted.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
getLink: function(twitter) {
diff --git a/plugins/links/hosted/cnevids-hosted.js b/plugins/links/hosted/cnevids-hosted.js
index 86ae5f9e5..91fda2f30 100644
--- a/plugins/links/hosted/cnevids-hosted.js
+++ b/plugins/links/hosted/cnevids-hosted.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
getData: function(video_src) {
diff --git a/plugins/links/hosted/hosted-via-canonical.js b/plugins/links/hosted/hosted-via-canonical.js
index 343dfb785..4f3385190 100644
--- a/plugins/links/hosted/hosted-via-canonical.js
+++ b/plugins/links/hosted/hosted-via-canonical.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
getLink: function(url, meta, options, cb) {
diff --git a/plugins/links/hosted/known-players.js b/plugins/links/hosted/known-players.js
index b88991a7b..1b1a1fdb5 100644
--- a/plugins/links/hosted/known-players.js
+++ b/plugins/links/hosted/known-players.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
provides: '__promoUri',
diff --git a/plugins/links/hosted/libsyn-hosted.js b/plugins/links/hosted/libsyn-hosted.js
index b65a4cfb4..cb86ac0fe 100644
--- a/plugins/links/hosted/libsyn-hosted.js
+++ b/plugins/links/hosted/libsyn-hosted.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
getData: function(url, video_src, twitter) {
diff --git a/plugins/links/hosted/ooyala.js b/plugins/links/hosted/ooyala.js
index 53f747ec1..5626e229d 100644
--- a/plugins/links/hosted/ooyala.js
+++ b/plugins/links/hosted/ooyala.js
@@ -1,6 +1,6 @@
-var URL = require('url');
+import * as URL from 'url';
-module.exports = {
+export default {
provides: '__ooyalaPlayer',
@@ -38,7 +38,6 @@ module.exports = {
method: 'HEAD',
headers: {
'Accept-Encoding': 'gzip, deflate, sdch', // this is required for head request to return content_length
- 'Connection': 'close'
},
prepareResult: function(error, response, body, cb) {
diff --git a/plugins/links/hosted/podbean-hosted.js b/plugins/links/hosted/podbean-hosted.js
index e17ec1b11..23ff977ce 100644
--- a/plugins/links/hosted/podbean-hosted.js
+++ b/plugins/links/hosted/podbean-hosted.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
getData: function(video_src) {
diff --git a/plugins/links/hosted/promo-link.js b/plugins/links/hosted/promo-link.js
index e32041623..627cd62be 100644
--- a/plugins/links/hosted/promo-link.js
+++ b/plugins/links/hosted/promo-link.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
provides: '__promoUri',
diff --git a/plugins/links/hosted/promo-oembed.js b/plugins/links/hosted/promo-oembed.js
index 034683eb8..5ffbbf58c 100644
--- a/plugins/links/hosted/promo-oembed.js
+++ b/plugins/links/hosted/promo-oembed.js
@@ -1,6 +1,6 @@
-var urlLib = require('url');
+import * as urlLib from 'url';
-module.exports = {
+export default {
provides: '__promoUri',
diff --git a/plugins/links/hosted/promo.js b/plugins/links/hosted/promo.js
index 979f4d028..ee0910de8 100644
--- a/plugins/links/hosted/promo.js
+++ b/plugins/links/hosted/promo.js
@@ -1,11 +1,10 @@
-var core = require('../../../lib/core');
-var _ = require('underscore');
+import * as _ from 'underscore';
-module.exports = {
+export default {
provides: 'self',
- getData: function(url, __promoUri, options, cb) {
+ getData: function(url, __promoUri, iframelyRun, options, cb) {
// __promoUri may be not string if no rel=promo need to be added
// see theplatform plugin for example
@@ -24,7 +23,7 @@ module.exports = {
delete options2.promoUri;
delete options2.jar;
- core.run(promoUri, options2, function(error, data) {
+ iframelyRun(promoUri, options2, function(error, data) {
var wrappedError = null;
diff --git a/plugins/links/hosted/tout-hosted.js b/plugins/links/hosted/tout-hosted.js
index 3104815e3..3a1df1cb9 100644
--- a/plugins/links/hosted/tout-hosted.js
+++ b/plugins/links/hosted/tout-hosted.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
getLink: function(twitter, whitelistRecord) {
diff --git a/plugins/links/hosted/video_src-hosted.js b/plugins/links/hosted/video_src-hosted.js
index fb40678ea..d8feea74c 100644
--- a/plugins/links/hosted/video_src-hosted.js
+++ b/plugins/links/hosted/video_src-hosted.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
provides: 'video_src',
diff --git a/plugins/links/iframely-link.js b/plugins/links/iframely-link.js
index d826b773f..36cc1231d 100644
--- a/plugins/links/iframely-link.js
+++ b/plugins/links/iframely-link.js
@@ -1,7 +1,7 @@
-var utils = require('./utils');
-var _ = require('underscore');
+import utils from './utils.js';
+import * as _ from 'underscore';
-module.exports = {
+export default {
getLinks: function(meta, whitelistRecord) {
return _.flatten(_.keys(meta).map(function(key) {
diff --git a/plugins/links/image_src.js b/plugins/links/image_src.js
index 971d0d72b..af29792bf 100644
--- a/plugins/links/image_src.js
+++ b/plugins/links/image_src.js
@@ -1,6 +1,6 @@
-var utils = require('./utils');
+import utils from './utils.js';
-module.exports = {
+export default {
getLink: function(meta) {
return utils.getImageLink('image_src', meta);
diff --git a/plugins/links/logo.js b/plugins/links/logo.js
index b3d51a834..902cb7ca7 100644
--- a/plugins/links/logo.js
+++ b/plugins/links/logo.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
getLink: function(meta) {
diff --git a/plugins/links/ms-doc-viewer.js b/plugins/links/ms-doc-viewer.js
index f664db77e..77cffa9af 100644
--- a/plugins/links/ms-doc-viewer.js
+++ b/plugins/links/ms-doc-viewer.js
@@ -1,6 +1,6 @@
// https://support.office.com/en-gb/article/View-Office-documents-online-1cc2ea26-0f7b-41f7-8e0e-6461a104544e?ui=en-US&rs=en-GB&ad=GB
-module.exports = {
+export default {
getLink: function(url, __nonHtmlContentData, options) {
diff --git a/plugins/links/oembed-icon.js b/plugins/links/oembed-icon.js
index 5be21e978..34e6e7033 100644
--- a/plugins/links/oembed-icon.js
+++ b/plugins/links/oembed-icon.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
getLink: function(oembed) {
diff --git a/plugins/custom/oembed-iframe.js b/plugins/links/oembed-iframe.js
similarity index 90%
rename from plugins/custom/oembed-iframe.js
rename to plugins/links/oembed-iframe.js
index 464093447..2e997eec5 100644
--- a/plugins/custom/oembed-iframe.js
+++ b/plugins/links/oembed-iframe.js
@@ -1,4 +1,4 @@
-module.exports = {
+export default {
provides: "iframe",
diff --git a/plugins/links/oembed-photo-html.js b/plugins/links/oembed-photo-html.js
index 54e227957..113099be3 100644
--- a/plugins/links/oembed-photo-html.js
+++ b/plugins/links/oembed-photo-html.js
@@ -1,6 +1,4 @@
-var cheerio = require('cheerio');
-
-module.exports = {
+export default {
// this is the case of oembed photo or image, but with the html field
// ex:
@@ -19,17 +17,11 @@ module.exports = {
};
- var $container = cheerio('
');
- try {
- $container.html(oembed.html5 || oembed.html);
- } catch (ex) {}
-
- var $iframe = $container.find('iframe');
-
+ var iframe = oembed.getIframe();
// if embed code contains