From a08fed1add957703d32ae08c5675e079c822f25c Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sat, 20 Oct 2018 12:40:08 +0200 Subject: [PATCH] ensure promises can be collected --- js/privatebin.js | 20 +++++++++++++------- tpl/bootstrap.php | 2 +- tpl/page.php | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index 1650195..6c11dc2 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -4166,14 +4166,16 @@ jQuery.PrivateBin = (function($, sjcl, RawDeflate) { * * @name PasteDecrypter.decryptPaste * @private + * @async * @function * @param {object} paste - paste data in object form * @param {string} key * @param {string} password * @param {bool} ignoreError - ignore decryption errors iof set to true * @throws {string} + * @return {Promise} */ - function decryptPaste(paste, key, password, ignoreError) + async function decryptPaste(paste, key, password, ignoreError) { let decyptionPromise; if (ignoreError === true) { @@ -4182,7 +4184,7 @@ jQuery.PrivateBin = (function($, sjcl, RawDeflate) { decyptionPromise = decryptOrPromptPassword(key, password, paste.data); } - decyptionPromise.then((plaintext) => { + return decyptionPromise.then((plaintext) => { if (plaintext !== false) { // on success show paste PasteViewer.setFormat(paste.meta.formatter); @@ -4200,13 +4202,15 @@ jQuery.PrivateBin = (function($, sjcl, RawDeflate) { * * @name PasteDecrypter.decryptAttachment * @private + * @async * @function * @param {object} paste - paste data in object form * @param {string} key * @param {string} password * @throws {string} + * @return {Promise} */ - function decryptAttachment(paste, key, password) + async function decryptAttachment(paste, key, password) { let attachmentPromise = decryptOrPromptPassword(key, password, paste.attachment); let attachmentNamePromise = decryptOrPromptPassword(key, password, paste.attachmentname); @@ -4216,7 +4220,7 @@ jQuery.PrivateBin = (function($, sjcl, RawDeflate) { attachmentNamePromise.catch((err) => { displayDecryptionError('failed to decipher attachment name: ' + err); }) - Promise.all([attachmentPromise, attachmentNamePromise]).then((results) => { + return Promise.all([attachmentPromise, attachmentNamePromise]).then((results) => { if (!results.some((result) => { return result === false; })) { @@ -4231,12 +4235,14 @@ jQuery.PrivateBin = (function($, sjcl, RawDeflate) { * * @name PasteDecrypter.decryptComments * @private + * @async * @function * @param {object} paste - paste data in object form * @param {string} key * @param {string} password + * @return {Promise} */ - function decryptComments(paste, key, password) + async function decryptComments(paste, key, password) { // remove potential previous discussion DiscussionViewer.prepareNewDiscussion(); @@ -4248,7 +4254,7 @@ jQuery.PrivateBin = (function($, sjcl, RawDeflate) { CryptTool.decipher(key, password, paste.comments[i].data) ); } - Promise.all(commentDecryptionPromises).then((plaintexts) => { + return Promise.all(commentDecryptionPromises).then((plaintexts) => { for (var i = 0; i < paste.comments.length; ++i) { if (plaintexts[i] === false) { continue; @@ -4333,7 +4339,7 @@ jQuery.PrivateBin = (function($, sjcl, RawDeflate) { // if the discussion is opened on this paste, display it if (paste.meta.opendiscussion) { - decrytionPromises(decryptComments(paste, key, password)); + decrytionPromises.push(decryptComments(paste, key, password)); } Promise.all(decrytionPromises).then(() => { diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index 78c6b08..9067c57 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -71,7 +71,7 @@ if ($MARKDOWN): endif; ?> - + diff --git a/tpl/page.php b/tpl/page.php index d8e3d4d..c3f406f 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -49,7 +49,7 @@ if ($MARKDOWN): endif; ?> - +