mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-19 09:34:02 +00:00
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:
parent
25e4bcfb34
commit
76dc0dc3c8
2 changed files with 15 additions and 2 deletions
|
|
@ -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({
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue