Sfoglia il codice sorgente

multipart/tus: Remove unused plugins from uppy-base.

René Kooi 8 anni fa
parent
commit
46706c1fa3
2 ha cambiato i file con 0 aggiunte e 306 eliminazioni
  1. 0 111
      src/uppy-base/src/plugins/Multipart.js
  2. 0 195
      src/uppy-base/src/plugins/Tus10.js

+ 0 - 111
src/uppy-base/src/plugins/Multipart.js

@@ -1,111 +0,0 @@
-'use strict'
-
-const EventEmitter = require('events')
-
-module.exports = class Multipart extends EventEmitter {
-  constructor (core, opts) {
-    super()
-
-    // Default options
-    const defaultOptions = {
-      fieldName: 'files[]',
-      responseUrlFieldName: 'url',
-      bundle: true
-    }
-
-    // Merge default options with the ones set by user
-    this.opts = Object.assign({}, defaultOptions, opts)
-  }
-
-  upload (file, current, total) {
-    this.core.log(`uploading ${current} of ${total}`)
-    return new Promise((resolve, reject) => {
-      // turn file into an array so we can use bundle
-      // if (!this.opts.bundle) {
-      //   files = [files[current]]
-      // }
-
-      // for (let i in files) {
-      //   formPost.append(this.opts.fieldName, files[i])
-      // }
-
-      const formPost = new FormData()
-      formPost.append(this.opts.fieldName, file.data)
-
-      Object.keys(file.meta).forEach((item) => {
-        console.log(file.meta, file.meta[item])
-        formPost.append(file.meta, file.meta[item])
-      })
-
-      const xhr = new XMLHttpRequest()
-
-      xhr.upload.addEventListener('progress', (ev) => {
-        if (ev.lengthComputable) {
-          // Dispatch progress event
-          this.emit('upload-progress', {
-            uploader: this,
-            id: file.id,
-            bytesUploaded: ev.loaded,
-            bytesTotal: ev.total
-          })
-        }
-      })
-
-      xhr.addEventListener('load', (ev) => {
-        if (ev.target.status === 200) {
-          const resp = JSON.parse(xhr.response)
-          const uploadURL = resp[this.opts.responseUrlFieldName]
-
-          this.emit('upload-success', file.id, uploadURL)
-
-          this.core.log(`Download ${file.name} from ${file.uploadURL}`)
-          return resolve(file)
-        }
-
-        // var upload = {}
-        //
-        // if (this.opts.bundle) {
-        //   upload = {files: files}
-        // } else {
-        //   upload = {file: files[current]}
-        // }
-      })
-
-      xhr.addEventListener('error', (ev) => {
-        return reject('Upload error')
-      })
-
-      xhr.open('POST', this.opts.endpoint, true)
-      xhr.send(formPost)
-      this.emit('core:file-upload-started', file.id)
-    })
-  }
-
-  selectForUpload (files) {
-    const filesForUpload = []
-    Object.keys(files).forEach((file) => {
-      if (files[file].progress.percentage === 0) {
-        filesForUpload.push(files[file])
-      }
-    })
-
-    const uploaders = []
-    filesForUpload.forEach((file, i) => {
-      const current = parseInt(i, 10) + 1
-      const total = filesForUpload.length
-      uploaders.push(this.upload(file, current, total))
-    })
-
-    return Promise.all(uploaders).then((result) => {
-      this.core.log('Multipart has finished uploading!')
-    })
-
-    //   if (this.opts.bundle) {
-    //     uploaders.push(this.upload(files, 0, files.length))
-    //   } else {
-    //     for (let i in files) {
-    //       uploaders.push(this.upload(files, i, files.length))
-    //     }
-    //   }
-  }
-}

+ 0 - 195
src/uppy-base/src/plugins/Tus10.js

@@ -1,195 +0,0 @@
-'use strict'
-
-const tus = require('tus-js-client')
-const UppySocket = require('../utils/UppySocket')
-const EventEmitter = require('events')
-
-/**
- * Tus resumable file uploader
- */
-module.exports = class Tus10 extends EventEmitter {
-  constructor (opts) {
-    super()
-
-    // set default options
-    const defaultOptions = {
-      resume: true,
-      allowPause: true
-    }
-
-    // merge default options with the ones set by user
-    this.opts = Object.assign({}, defaultOptions, opts)
-  }
-
-/**
- * Start uploading for batch of files.
- * @param  {Array} files Files to upload
- * @return {Promise}       Resolves when all uploads succeed/fail
- */
-  start (files) {
-    const total = files.length
-
-    const uploaders = files.map((file, index) => {
-      const current = parseInt(index, 10) + 1
-
-      if (file.isRemote) {
-        return this.uploadRemote(file, current, total)
-      }
-
-      return this.upload(file, current, total)
-    })
-
-    return Promise.all(uploaders).then(() => {
-      return {
-        uploadedCount: files.length
-      }
-    })
-  }
-
-/**
- * Create a new Tus upload
- *
- * @param {object} file for use with upload
- * @param {integer} current file in a queue
- * @param {integer} total number of files in a queue
- * @returns {Promise}
- */
-  upload (file, current, total) {
-    // Create a new tus upload
-    return new Promise((resolve, reject) => {
-      const upload = new tus.Upload(file.data, {
-
-        // TODO merge this.opts or this.opts.tus here
-        metadata: file.meta,
-        resume: this.opts.resume,
-        endpoint: this.opts.endpoint,
-
-        onError: (err) => {
-          reject('Failed because: ' + err)
-        },
-        onProgress: (bytesUploaded, bytesTotal) => {
-          console.log('progress:')
-          console.log(bytesUploaded / bytesTotal)
-          // Dispatch progress event
-          this.emit('progress', {
-            uploader: this,
-            id: file.id,
-            bytesUploaded: bytesUploaded,
-            bytesTotal: bytesTotal
-          })
-        },
-        onSuccess: () => {
-          console.log('success!')
-          this.emit('success', file.id, upload.url)
-          resolve(upload)
-        }
-      })
-
-      this.on('abort', (fileID) => {
-        // If no fileID provided, abort all uploads
-        if (fileID === file.id || !fileID) {
-          console.log('aborting file upload: ', fileID)
-          upload.abort()
-          resolve(`upload ${fileID} was aborted`)
-        }
-      })
-
-      this.on('pause', (fileID) => {
-        // If no fileID provided, pause all uploads
-        if (fileID === file.id || !fileID) {
-          upload.abort()
-        }
-      })
-
-      this.on('resume', (fileID) => {
-        // If no fileID provided, resume all uploads
-        if (fileID === file.id || !fileID) {
-          upload.start()
-        }
-      })
-
-      upload.start()
-      this.emit('file-upload-started', file.id, upload)
-    })
-  }
-
-  uploadRemote (file, current, total) {
-    return new Promise((resolve, reject) => {
-      const remoteHost = this.opts.remoteHost ? this.opts.remoteHost : file.remote.host
-      fetch(`${remoteHost}/${file.remote.provider}/get`, {
-        method: 'post',
-        credentials: 'include',
-        headers: {
-          'Accept': 'application/json',
-          'Content-Type': 'application/json'
-        },
-        body: JSON.stringify(Object.assign({}, file.remote.body, {
-          target: this.opts.endpoint,
-          protocol: 'tus'
-        }))
-      })
-      .then((res) => {
-        if (res.status < 200 && res.status > 300) {
-          return reject(res.statusText)
-        }
-
-        res.json()
-        .then((data) => {
-          // get the host domain
-          // var regex = /^(?:https?:\/\/|\/\/)?(?:[^@\/\n]+@)?(?:www\.)?([^\/\n]+)/
-          var regex = /^(?:https?:\/\/|\/\/)?(?:[^@\n]+@)?(?:www\.)?([^\n]+)/
-          var host = regex.exec(remoteHost)[1]
-
-          var token = data.token
-          var socket = new UppySocket({
-            target: `ws://${host}:3020/api/${token}`
-          })
-
-          socket.on('progress', (progressData) => {
-            const {progress, bytesUploaded, bytesTotal} = progressData
-
-            if (progress) {
-              console.log(progress)
-              // Dispatch progress event
-              this.emit('progress', {
-                uploader: this,
-                id: file.id,
-                bytesUploaded: bytesUploaded,
-                bytesTotal: bytesTotal
-              })
-
-              if (progress === '100.00') {
-                socket.close()
-                return resolve()
-              }
-            }
-          })
-        })
-      })
-    })
-  }
-
-  abort (fileID) {
-    this.emit('abort', fileID)
-  }
-
-  pause (fileID) {
-    this.emit('pause', fileID)
-  }
-
-  resume (fileID) {
-    this.emit('resume', fileID)
-  }
-
-  abortAll () {
-    this.abort()
-  }
-
-  pauseAll () {
-    this.pause()
-  }
-
-  resumeAll () {
-    this.resume()
-  }
-}