Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@

T: {
text_html: "text/html",
text_markdown: "text/markdown",
text_plain: "text/plain",
maybe_text_html: "maybe_text_html",
javascript: "application/javascript",
application_pdf: "application/pdf",
safe_html: "text/x-safe-html",
image_jpeg: "image/jpeg",
flash: "application/x-shockwave-flash", // Adobe Flash Player is no longer supported
Expand Down
7 changes: 3 additions & 4 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1242,10 +1242,6 @@

var links = result.links;

if (!result.meta.canonical) {
result.meta.canonical = uri;
}

// Remove canonical links.
// Remove _meta data.
var canonical = result.meta.canonical;
Expand Down Expand Up @@ -2176,6 +2172,9 @@
options.domainOptions = options.getDomainOptionsByUrl(uri);
}

// Reset `acceptHeaders` as empty array for each call.
options.acceptHeaders = [];

asyncMethodCb('initial');
};

Expand Down
3 changes: 2 additions & 1 deletion lib/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export function skipLoggingFetchError(error) {
|| error?.code === 'ERR_HTTP2_STREAM_ERROR'
|| error?.code === 'ERR_HTTP2_SESSION_ERROR'
|| error?.code === 'Z_DATA_ERROR'
|| error?.code === 'Z_BUF_ERROR';
|| error?.code === 'Z_BUF_ERROR'
|| error?.code === 'ETIMEDOUT';
}

function doFetch(fetch_func, h1_fetch_func, options) {
Expand Down
3 changes: 2 additions & 1 deletion lib/plugins/system/htmlparser/htmlparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ export default {

if ('content-type' in headers && !/text\/html|application\/xhtml\+xml/gi.test(headers['content-type'])) {

if (options.requestHeaders?.['Accept']?.indexOf(headers['content-type'].split(';')[0]) > -1) {
if (options.acceptHeaders?.indexOf
&& options.acceptHeaders.indexOf(headers['content-type'].split(';')[0]) > -1) {
return cb(null, {
__nonHtmlContentResponse: resp
});
Expand Down
6 changes: 5 additions & 1 deletion lib/plugins/system/htmlparser/nonHtmlContentData.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ export default {
],

getLink: function(url, __nonHtmlContentData, options, cb) {

var nonHtmlContentType = __nonHtmlContentData.type;
var nonHtmlContentLength = __nonHtmlContentData.content_length;

if (options.dataMode && !/video|image/i.test(nonHtmlContentType)) {
return cb();
}

// 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)) {
Expand All @@ -30,5 +35,4 @@ export default {
});
}
}

};
2 changes: 1 addition & 1 deletion lib/plugins/system/meta/cachedMeta.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default {
var record_age_sec = (new Date().getTime() / 1000) - data._sys_created_at;
if (record_age_sec > ttl) {
// Ignore cache older then requested ttl.
log(' -- Disable using old cache for: ' + url);
log(' -- Disable using old cache for: ' + url + '. Seconds old: ' + (record_age_sec - ttl));
return noCacheFound();
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export function getMaxCacheTTLOverride(url, options) {
};

export function getMaxCacheTTL(url, options, default_min_ttl) {
default_min_ttl = default_min_ttl || CONFIG.CACHE_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);
Expand Down Expand Up @@ -971,7 +972,7 @@ export function getContentType(uriForCache, uriOriginal, options, cb) {
}, {
// Ignore proxy.cache_ttl, if options.cache_ttl === 0 - do not read from cache.
refresh: options.refresh || options.cache_ttl === 0,
ttl: getMaxCacheTTL(uriOriginal, options, CONFIG.CACHE_TTL),
ttl: getMaxCacheTTL(uriOriginal, options),
}, cb);
};

Expand Down
5 changes: 3 additions & 2 deletions plugins/domains/ted.com/ted.com.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export default {
provides: [
"oembedLinks",
"tedLangs",
"__allowEmbedURL"
"__allowEmbedURL",
"__isYouTube"
],

mixins: [
Expand Down Expand Up @@ -189,4 +190,4 @@ export default {
// Should work, but let's skip from tests not to avoid all oembed-* mixins
// "https://www.ted.com/talks/su_santidad_el_papa_francisco_nuestro_imperativo_moral_para_actuar_sobre_el_cambio_climatico_y_3_pasos_que_podemos_dar",
]
};
};
4 changes: 2 additions & 2 deletions plugins/domains/youtube.com/youtube.video.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export default {

var api_key = options.getProviderOptions('youtube.api_key');

if (!api_key) {
return cb (new Error ("No youtube.api_key configured"));
if (!api_key || options.dataMode) {
return cb('YouTube Data API is disabled');
}

var parts = options.getProviderOptions('youtube.parts') || [
Expand Down
2 changes: 1 addition & 1 deletion plugins/links/google-docs-viewer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default {

getLink: function(url, __nonHtmlContentData, utils, headers, options, iframelyRun, cb) {
getLink: function(__nonDataMode, url, __nonHtmlContentData, utils, headers, options, iframelyRun, cb) {

if (!options.getProviderOptions('disableDocViewers', false) &&
/application\/pdf|text\/rtf/.test(__nonHtmlContentData.type)) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/links/ms-doc-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

export default {

getLink: function(url, __nonHtmlContentData, options) {
getLink: function(__nonDataMode, url, __nonHtmlContentData, options) {

if (!options.getProviderOptions('disableDocViewers', false)
&& /application\/vnd\.openxmlformats\-officedocument|ms\-powerpoint|msword|ms\-excel|ms\-office/.test(__nonHtmlContentData.type)
Expand Down
9 changes: 5 additions & 4 deletions plugins/meta/canonical.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
export default {

highestPriority: true,

getMeta: function(url, meta) {
getMeta: function(url, meta, options) {

var canonical = (meta.canonical && meta.canonical.href || meta.canonical) || (meta.og && meta.og.url) || (meta.twitter && meta.twitter.url);

if (canonical && typeof canonical === 'string' && /^https?:\/\//i.test(canonical)) {
if ((!canonical || /^https?:\/\//i.test(canonical)) && !options.dataMode) {
canonical = url;
}

if (typeof canonical === 'string') {
return {
canonical: canonical
};
Expand Down
13 changes: 13 additions & 0 deletions plugins/meta/non-data-mode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default {

provides: "__nonDataMode",

getData: function(options) {

if (!options.dataMode) {
return {
__nonDataMode: true
}
}
}
}
Loading