From 96fcc852d6c45e0e58159fe1c06e6db3d94d8fae Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 25 May 2020 15:29:18 +0200 Subject: [PATCH] Add a timeout for file upload if we can't make a thumbnail --- www/common/common-thumbnail.js | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/www/common/common-thumbnail.js b/www/common/common-thumbnail.js index 19b6713da..3f359d425 100644 --- a/www/common/common-thumbnail.js +++ b/www/common/common-thumbnail.js @@ -197,17 +197,27 @@ define([ }; Thumb.fromBlob = function (blob, _cb) { var cb = Util.once(_cb); - if (blob.type.indexOf('video/') !== -1) { - return void Thumb.fromVideoBlob(blob, cb); - } - if (blob.type.indexOf('application/pdf') !== -1) { - return void Thumb.fromPdfBlob(blob, cb); - } - if (Util.isPlainTextFile(blob.type, blob.name)) { - return void Thumb.fromPlainTextBlob(blob, cb); - } - if (blob.type.indexOf('image/') !== -1) { - return void Thumb.fromImageBlob(blob, cb); + // The blob is already in memory, it should be super-fast to make a thumbnail + // ==> 1s timeout + setTimeout(function () { + console.error("Thumbnail timeout"); + cb('TIMEOUT'); + }, 1000); + try { + if (blob.type.indexOf('video/') !== -1) { + return void Thumb.fromVideoBlob(blob, cb); + } + if (blob.type.indexOf('application/pdf') !== -1) { + return void Thumb.fromPdfBlob(blob, cb); + } + if (Util.isPlainTextFile(blob.type, blob.name)) { + return void Thumb.fromPlainTextBlob(blob, cb); + } + if (blob.type.indexOf('image/') !== -1) { + return void Thumb.fromImageBlob(blob, cb); + } + } catch (e) { + return void cb('THUMBNAIL_ERROR'); } return void cb('NO_THUMBNAIL'); };