From 7c17662fea1672166ef2e5ac8589170ea7021887 Mon Sep 17 00:00:00 2001 From: Reto Brunner Date: Wed, 30 Dec 2020 11:52:12 +0100 Subject: [PATCH 1/2] Add prefetchMaxSearchSize to override limit for link previews YouTube puts the opengraph tags needed for the preview after ~300KB in the body instead of the beginning of the tag. Instead of hardcoding the value, allow the server admin to set the policy as they prefer. --- defaults/config.js | 8 ++++++++ src/plugins/irc-events/link.js | 11 ++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/defaults/config.js b/defaults/config.js index 9f8a5493..dbd18ed7 100644 --- a/defaults/config.js +++ b/defaults/config.js @@ -150,6 +150,14 @@ module.exports = { // This value is set to `2048` kilobytes by default. prefetchMaxImageSize: 2048, + // ### prefetchMaxSearchSize + // + // This value controls the maximum request size made to find the link preview + // Open Graph tags. For some sites like YouTube this can easily exceed 300 kilobytes. + // + // This value is set to 50 kilobytes by default. + prefetchMaxSearchSize: 50, + // ### `fileUpload` // // Allow uploading files to the server hosting The Lounge. diff --git a/src/plugins/irc-events/link.js b/src/plugins/irc-events/link.js index 4a73c620..e268d9ef 100644 --- a/src/plugins/irc-events/link.js +++ b/src/plugins/irc-events/link.js @@ -407,9 +407,14 @@ function fetch(uri, headers) { // We don't need to download the file any further after we received content-type header gotStream.destroy(); } else { - // if not image, limit download to 50kb, since we need only meta tags - // twitter.com sends opengraph meta tags within ~20kb of data for individual tweets - limit = 1024 * 50; + // if not image, limit download to the max search size, since we need only meta tags + // twitter.com sends opengraph meta tags within ~20kb of data for individual tweets, the default is set to 50. + // for sites like Youtube the og tags are in the first 300K and hence this is configurable by the admin + limit = + "prefetchMaxSearchSize" in Helper.config + ? Helper.config.prefetchMaxSearchSize * 1024 + : // set to the previous size if config option is unset + 50 * 1024; } }) .on("error", (e) => reject(e)) From c94ace5843a0d2f6008fd526e8c37d7f73ca5fd8 Mon Sep 17 00:00:00 2001 From: Max Leiter Date: Tue, 2 Mar 2021 15:03:39 -0800 Subject: [PATCH 2/2] Slightly adjust config option wording --- defaults/config.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/defaults/config.js b/defaults/config.js index dbd18ed7..9b21cc84 100644 --- a/defaults/config.js +++ b/defaults/config.js @@ -152,10 +152,11 @@ module.exports = { // ### prefetchMaxSearchSize // - // This value controls the maximum request size made to find the link preview - // Open Graph tags. For some sites like YouTube this can easily exceed 300 kilobytes. + // This value sets the maximum request size made to find the Open Graph tags + // for link previews. For some sites like YouTube this can easily exceed 300 + // kilobytes. // - // This value is set to 50 kilobytes by default. + // This value is set to `50` kilobytes by default. prefetchMaxSearchSize: 50, // ### `fileUpload`