Merge pull/4524: Add prefetchTimeout
This commit is contained in:
commit
aa7db1e7f7
@ -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.
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user