Browse Source

Generate previews when an event is emitted

Renée Kooi 7 years ago
parent
commit
326918136e
2 changed files with 6 additions and 4 deletions
  1. 4 0
      src/core/Core.js
  2. 2 4
      src/plugins/RestoreFiles/index.js

+ 4 - 0
src/core/Core.js

@@ -438,6 +438,10 @@ class Uppy {
     })
 
     this.on('core:file-added', (file) => {
+      this.emit('core:generate-preview', file)
+    })
+
+    this.on('core:generate-preview', (file) => {
       if (Utils.isPreviewSupported(file.type.specific) && !file.isRemote) {
         Utils.createThumbnail(file, 200).then((thumbnail) => {
           this.setPreviewURL(file.id, thumbnail)

+ 2 - 4
src/plugins/RestoreFiles/index.js

@@ -1,5 +1,4 @@
 const Plugin = require('../Plugin')
-const Utils = require('../../core/Utils')
 const ServiceWorkerStore = require('./ServiceWorkerStore')
 const IndexedDBStore = require('./IndexedDBStore')
 
@@ -91,13 +90,12 @@ module.exports = class RestoreFiles extends Plugin {
         data: cachedData,
         isRestored: true
       }
-      if (this.core.state.files[fileID] && Utils.isPreviewSupported(this.core.state.files[fileID].type.specific)) {
-        updatedFileData.preview = Utils.getThumbnail(cachedData)
-      }
       const updatedFile = Object.assign({}, updatedFiles[fileID],
         Object.assign({}, updatedFileData)
       )
       updatedFiles[fileID] = updatedFile
+
+      this.core.emit('core:generate-preview', updatedFile)
     })
     this.core.setState({
       files: updatedFiles