Warn about unset prefetchTimeout, default to 5000 ms

This commit is contained in:
Emily Strickland 2022-04-09 00:19:08 +00:00
parent b2a363f099
commit ff886846a8
No known key found for this signature in database
GPG Key ID: 6526B8035DD3DD32

View File

@ -10,6 +10,8 @@ const storage = require("../storage");
const currentFetchPromises = new Map(); const currentFetchPromises = new Map();
const imageTypeRegex = /^image\/.+/; const imageTypeRegex = /^image\/.+/;
const mediaTypeRegex = /^(audio|video)\/.+/; const mediaTypeRegex = /^(audio|video)\/.+/;
const log = require("../../log");
module.exports = function (client, chan, msg, cleanText) { module.exports = function (client, chan, msg, cleanText) {
if (!Helper.config.prefetch) { if (!Helper.config.prefetch) {
@ -381,6 +383,12 @@ function fetch(uri, headers) {
return promise; 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) => { promise = new Promise((resolve, reject) => {
let buffer = Buffer.from(""); let buffer = Buffer.from("");
let contentLength = 0; let contentLength = 0;
@ -390,7 +398,7 @@ function fetch(uri, headers) {
try { try {
const gotStream = got.stream(uri, { const gotStream = got.stream(uri, {
retry: 0, retry: 0,
timeout: Helper.config.prefetchTimeout, // milliseconds timeout: prefetchTimeout || 5000, // milliseconds
headers: getRequestHeaders(headers), headers: getRequestHeaders(headers),
https: { https: {
rejectUnauthorized: false, rejectUnauthorized: false,