all files / model/ DefaultFileProxy.js

0% Statements 0/14
0% Branches 0/8
0% Functions 0/3
0% Lines 0/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42                                                                                   
import FileProxy from './FileProxy'
 
/*
  Generic implementation of a file proxy that works with
  any file type
*/
class DefaultFileProxy extends FileProxy {
 
  constructor(fileNode, context) {
    super(fileNode, context)
 
    // used locally e.g. after drop or file dialog
    this.file = fileNode.sourceFile
    if (this.file) {
      this._fileUrl = URL.createObjectURL(this.file)
    }
    this.url = fileNode.url
  }
 
  getUrl() {
    // if we have fetched the url already, just serve it here
    if (this.url) {
      return this.url
    }
    // if we have a local file, use it's data URL
    if (this._fileUrl) {
      return this._fileUrl
    }
    // no URL available
    return ''
  }
 
  sync() {
    if (!this.url) {
      console.info('Simulating file upload. Creating blob url instead.', this._fileUrl)
      this.url = this._fileUrl
    }
    return Promise.resolve()
  }
}
 
export default DefaultFileProxy