From 76dc0dc3c8df314e80c0cb3161c6ee03535f7ccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Thu, 22 Mar 2018 14:34:23 +0100 Subject: [PATCH] Regenerate thumbnails after restore. The `generatePreview()` method that GoldenRetriever used to create new thumbnails after restoring files no longer exists. This patch makes the ThumbnailGenerator go through all files after a restore, and tries to generate a thumbnail for all blob URLs (http:// URLs from remote sources don't need to be regenerated). --- src/plugins/GoldenRetriever/index.js | 2 -- src/plugins/ThumbnailGenerator/index.js | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/plugins/GoldenRetriever/index.js b/src/plugins/GoldenRetriever/index.js index c82b190e2..547b3249c 100644 --- a/src/plugins/GoldenRetriever/index.js +++ b/src/plugins/GoldenRetriever/index.js @@ -170,8 +170,6 @@ module.exports = class GoldenRetriever extends Plugin { } const updatedFile = Object.assign({}, originalFile, updatedFileData) updatedFiles[fileID] = updatedFile - - this.uppy.generatePreview(updatedFile) }) this.uppy.setState({ diff --git a/src/plugins/ThumbnailGenerator/index.js b/src/plugins/ThumbnailGenerator/index.js index 8222be90e..774b9306e 100644 --- a/src/plugins/ThumbnailGenerator/index.js +++ b/src/plugins/ThumbnailGenerator/index.js @@ -21,6 +21,7 @@ module.exports = class ThumbnailGenerator extends Plugin { this.opts = Object.assign({}, defaultOptions, opts) this.addToQueue = this.addToQueue.bind(this) + this.onRestored = this.onRestored.bind(this) } /** @@ -194,10 +195,24 @@ module.exports = class ThumbnailGenerator extends Plugin { return Promise.resolve() } + onRestored () { + const fileIDs = Object.keys(this.uppy.getState().files) + fileIDs.forEach((fileID) => { + const file = this.uppy.getFile(fileID) + if (!file.isRestored) return + // Only add blob URLs; they are likely invalid after being restored. + if (!file.preview || /^blob:/.test(file.preview)) { + this.addToQueue(file) + } + }) + } + install () { this.uppy.on('file-added', this.addToQueue) + this.uppy.on('restored', this.onRestored) } uninstall () { this.uppy.off('file-added', this.addToQueue) + this.uppy.off('restored', this.onRestored) } }