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).
This commit is contained in:
Renée Kooi 2018-03-22 14:34:23 +01:00
parent 25e4bcfb34
commit 76dc0dc3c8
No known key found for this signature in database
GPG key ID: 8CDD5F0BC448F040
2 changed files with 15 additions and 2 deletions

View file

@ -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({

View file

@ -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)
}
}