Browse Source

Fix file array issue. Add array flatten util. Wrote multipart test. Add GoogleDrive to Modal.

Harry Hedger 9 năm trước cách đây
mục cha
commit
6ec338f416

+ 4 - 6
src/core/Core.js

@@ -137,7 +137,7 @@ export default class Core {
  */
  */
   runType (type, method, files) {
   runType (type, method, files) {
     const methods = this.plugins[type].map(
     const methods = this.plugins[type].map(
-      plugin => plugin[method](files)
+      plugin => plugin[method](Utils.flatten(files))
     )
     )
 
 
     return Promise.all(methods)
     return Promise.all(methods)
@@ -165,13 +165,11 @@ export default class Core {
     ['install', 'run'].forEach(method => {
     ['install', 'run'].forEach(method => {
       // First we select only plugins of current type,
       // First we select only plugins of current type,
       // then create an array of runType methods of this plugins
       // then create an array of runType methods of this plugins
-      const typeMethods = this.types.filter(type => {
-        return this.plugins[type]
-      }).map(type => this.runType.bind(this, type, method))
-
+      const typeMethods = this.types.filter(type => this.plugins[type])
+        .map(type => this.runType.bind(this, type, method))
       // Run waterfall of typeMethods
       // Run waterfall of typeMethods
       return Utils.promiseWaterfall(typeMethods)
       return Utils.promiseWaterfall(typeMethods)
-        .then(result => { return result })
+        .then(result => result)
         .catch(error => console.error(error))
         .catch(error => console.error(error))
     })
     })
   }
   }

+ 8 - 0
src/core/Utils.js

@@ -98,6 +98,13 @@ function addListenerMulti (el, events, cb) {
   }
   }
 }
 }
 
 
+/**
+ * Shallow flatten nested arrays.
+ */
+function flatten (arr) {
+  return [].concat.apply([], arr)
+}
+
 function qsa (selector, context) {
 function qsa (selector, context) {
   return Array.prototype.slice.call((context || document).querySelectorAll(selector) || [])
   return Array.prototype.slice.call((context || document).querySelectorAll(selector) || [])
 }
 }
@@ -108,5 +115,6 @@ export default {
   addClass,
   addClass,
   removeClass,
   removeClass,
   addListenerMulti,
   addListenerMulti,
+  flatten,
   qsa
   qsa
 }
 }

+ 5 - 7
src/plugins/Formtag.js

@@ -13,7 +13,7 @@ export default class Formtag extends Plugin {
       results: results
       results: results
     })
     })
 
 
-    this.setProgress(0)
+    // this.setProgress(0)
 
 
     // form FormData
     // form FormData
     // const formData = new FormData(this.dropzone)
     // const formData = new FormData(this.dropzone)
@@ -32,11 +32,9 @@ export default class Formtag extends Plugin {
         var selected = [];
         var selected = [];
 
 
         [].forEach.call(fields, (field, i) => {
         [].forEach.call(fields, (field, i) => {
-          [].forEach.call(field.files, (file, j) => {
-            selected.push({
-              from: 'Formtag',
-              file: file
-            })
+          selected.push({
+            from: 'Formtag',
+            files: field.files
           })
           })
         })
         })
 
 
@@ -57,7 +55,7 @@ export default class Formtag extends Plugin {
         //     }
         //     }
         //   }
         //   }
         // }
         // }
-        self.setProgress(100)
+        // self.setProgress(100)
         console.log({
         console.log({
           selected: selected,
           selected: selected,
           fields: fields
           fields: fields

+ 0 - 1
src/plugins/GoogleDrive.js

@@ -148,7 +148,6 @@ export default class Google extends Plugin {
     this.getFolder(folder)
     this.getFolder(folder)
     .then(data => {
     .then(data => {
       this.target.innerHTML = this.renderBrowser(data)
       this.target.innerHTML = this.renderBrowser(data)
-      console.log(data)
       const folders = Utils.qsa('.GoogleDriveFolder')
       const folders = Utils.qsa('.GoogleDriveFolder')
       const files = Utils.qsa('.GoogleDriveFile')
       const files = Utils.qsa('.GoogleDriveFile')
 
 

+ 2 - 2
src/plugins/Multipart.js

@@ -21,7 +21,7 @@ export default class Multipart extends Plugin {
 
 
     const files = this.extractFiles(results)
     const files = this.extractFiles(results)
 
 
-    this.setProgress(0)
+    // this.setProgress(0)
     var uploaders = []
     var uploaders = []
 
 
     if (this.opts.bundle) {
     if (this.opts.bundle) {
@@ -52,7 +52,7 @@ export default class Multipart extends Plugin {
 
 
     xhr.addEventListener('progress', (e) => {
     xhr.addEventListener('progress', (e) => {
       var percentage = (e.loaded / e.total * 100).toFixed(2)
       var percentage = (e.loaded / e.total * 100).toFixed(2)
-      this.setProgress(percentage, current, total)
+      // this.setProgress(percentage, current, total)
     })
     })
 
 
     xhr.addEventListener('load', () => {
     xhr.addEventListener('load', () => {

+ 2 - 0
src/plugins/index.js

@@ -9,6 +9,7 @@ import Dummy from './Dummy'
 import DragDrop from './DragDrop'
 import DragDrop from './DragDrop'
 import Dropbox from './Dropbox'
 import Dropbox from './Dropbox'
 import Formtag from './Formtag'
 import Formtag from './Formtag'
+import GoogleDrive from './GoogleDrive'
 
 
 // Progressindicators
 // Progressindicators
 import ProgressBar from './ProgressBar'
 import ProgressBar from './ProgressBar'
@@ -32,6 +33,7 @@ export default {
   Present,
   Present,
   DragDrop,
   DragDrop,
   Dropbox,
   Dropbox,
+  GoogleDrive,
   Formtag,
   Formtag,
   Tus10,
   Tus10,
   Multipart,
   Multipart,

+ 18 - 0
test/multipart.spec.js

@@ -0,0 +1,18 @@
+var test = require('tape')
+var webdriver = require('selenium-webdriver')
+
+test('upload two files', function (t) {
+  var driver = new webdriver.Builder()
+  .withCapabilities(webdriver.Capabilities.chrome())
+  .build()
+
+  driver.get('http://www.uppy.io/examples/multipart/')
+  driver.findElement(webdriver.By.id('file1')).sendKeys('./dummyFile')
+  driver.findElement(webdriver.By.id('file2')).sendKeys('./dummyFile2')
+  driver.findElement(webdriver.By.id('myupload')).click()
+  // driver.wait
+  // check for success
+  driver.quit()
+
+  t.end()
+})

+ 0 - 16
test/tus10.spec.js

@@ -1,16 +0,0 @@
-var test = require('tape')
-var Core = require('../src/core/index.js')
-var DragDrop = require('../src/plugins/DragDrop.js')
-var Tus10 = require('../src/plugins/Tus10.js')
-
-test('uploadSomePizza', function (t) {
-  const core = new Core()
-  core
-    .use(DragDrop, {target: '??'})
-    .use(Tus10, {endpoint: 'http://master.tus.io:8080/files/'})
-    .run()
-
-  // trigger an upload with a fake blob
-  // somehow test the resume? or just see if it's successful?
-  // test the expected/actual results to pass/fail
-})

+ 2 - 1
website/src/examples/modal/app.es6

@@ -1,5 +1,5 @@
 import Uppy from 'uppy/core'
 import Uppy from 'uppy/core'
-import { Dummy, DragDrop, Modal, ProgressBar, Present, Tus10 } from 'uppy/plugins'
+import { Dummy, DragDrop, GoogleDrive, Modal, ProgressBar, Present, Tus10 } from 'uppy/plugins'
 // GoogleDrive,
 // GoogleDrive,
 
 
 const uppy = new Uppy({debug: true})
 const uppy = new Uppy({debug: true})
@@ -9,6 +9,7 @@ uppy
   // .use(GoogleDrive, {target: Modal})
   // .use(GoogleDrive, {target: Modal})
   .use(ProgressBar, {target: Modal})
   .use(ProgressBar, {target: Modal})
   .use(DragDrop, {target: Modal})
   .use(DragDrop, {target: Modal})
+  .use(GoogleDrive, {target: Modal})
   .use(Present, {target: Modal})
   .use(Present, {target: Modal})
   .use(Tus10, {endpoint: 'http://master.tus.io:8080/files/'})
   .use(Tus10, {endpoint: 'http://master.tus.io:8080/files/'})
   .run()
   .run()