Jelajahi Sumber

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).
Renée Kooi 7 tahun lalu
induk
melakukan
76dc0dc3c8

+ 0 - 2
src/plugins/GoldenRetriever/index.js

@@ -170,8 +170,6 @@ module.exports = class GoldenRetriever extends Plugin {
       }
       }
       const updatedFile = Object.assign({}, originalFile, updatedFileData)
       const updatedFile = Object.assign({}, originalFile, updatedFileData)
       updatedFiles[fileID] = updatedFile
       updatedFiles[fileID] = updatedFile
-
-      this.uppy.generatePreview(updatedFile)
     })
     })
 
 
     this.uppy.setState({
     this.uppy.setState({

+ 15 - 0
src/plugins/ThumbnailGenerator/index.js

@@ -21,6 +21,7 @@ module.exports = class ThumbnailGenerator extends Plugin {
     this.opts = Object.assign({}, defaultOptions, opts)
     this.opts = Object.assign({}, defaultOptions, opts)
 
 
     this.addToQueue = this.addToQueue.bind(this)
     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()
     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 () {
   install () {
     this.uppy.on('file-added', this.addToQueue)
     this.uppy.on('file-added', this.addToQueue)
+    this.uppy.on('restored', this.onRestored)
   }
   }
   uninstall () {
   uninstall () {
     this.uppy.off('file-added', this.addToQueue)
     this.uppy.off('file-added', this.addToQueue)
+    this.uppy.off('restored', this.onRestored)
   }
   }
 }
 }