Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- constructor(opts) {
- ...
- this.queue = []
- this.queueProcessing = false
- ...
- }
- actions () {
- ...
- this.on('core:file-added', (file) => {
- this.addToPreviewQueue(file)
- })
- ...
- }
- addToPreviewQueue (file) {
- this.queue.push(file)
- if (this.queueProcessing === false) {
- this.processPreviewQueue()
- }
- }
- generatePreview (file) {
- return new Promise((resolve, reject) => {
- if (Utils.isPreviewSupported(file.type) && !file.isRemote) {
- Utils.createThumbnail(file, 200).then((thumbnail) => {
- this.setPreviewURL(file.id, thumbnail)
- resolve()
- }).catch(function (err) {
- console.warn(err.stack || err.message)
- reject(err)
- })
- } else {
- reject(new Error('no preview'))
- }
- })
- }
- processPreviewQueue () {
- if (this.queue.length > 0) {
- this.queueProcessing = true
- const currentFile = this.queue.shift()
- this.generatePreview(currentFile).catch(() => {
- }).then(() => {
- if (this.queue.length > 0) {
- this.processPreviewQueue()
- } else {
- this.queueProcessing = false
- }
- })
- }
- }
Add Comment
Please, Sign In to add comment