diff --git a/defaults/config.js b/defaults/config.js index 89212c39..25afdd2c 100644 --- a/defaults/config.js +++ b/defaults/config.js @@ -160,6 +160,20 @@ module.exports = { // This value is set to `50` kilobytes by default. prefetchMaxSearchSize: 50, + // ### `prefetchTimeout` + // + // When `prefetch` is enabled, this value sets the number of milliseconds + // before The Lounge gives up attempting to fetch a link. This can be useful + // if you've increased the `prefetchMaxImageSize`. + // + // Take caution, however, that an inordinately large value may lead to + // performance issues or even a denial of service, since The Lounge will not + // be able to clean up outgoing connections as quickly. Usually the default + // value is appropriate, so only change it if necessary. + // + // This value is set to `5000` milliseconds by default. + prefetchTimeout: 5000, + // ### `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 00236def..0d7a5061 100644 --- a/src/plugins/irc-events/link.js +++ b/src/plugins/irc-events/link.js @@ -10,6 +10,7 @@ const storage = require("../storage"); const currentFetchPromises = new Map(); const imageTypeRegex = /^image\/.+/; const mediaTypeRegex = /^(audio|video)\/.+/; +const log = require("../../log"); module.exports = function (client, chan, msg, cleanText) { if (!Helper.config.prefetch) { @@ -381,6 +382,14 @@ function fetch(uri, headers) { return promise; } + const prefetchTimeout = Helper.config.prefetchTimeout; + + if (!prefetchTimeout) { + log.warn( + "prefetchTimeout is missing from your The Lounge configuration, defaulting to 5000 ms" + ); + } + promise = new Promise((resolve, reject) => { let buffer = Buffer.from(""); let contentLength = 0; @@ -390,7 +399,7 @@ function fetch(uri, headers) { try { const gotStream = got.stream(uri, { retry: 0, - timeout: 5000, + timeout: prefetchTimeout || 5000, // milliseconds headers: getRequestHeaders(headers), https: { rejectUnauthorized: false,