Forráskód Böngészése

Merge branch 'master' of github.com:transloadit/uppy into set-real-versions

Ifedapo Olarewaju 5 éve
szülő
commit
3d547ef706

+ 9 - 2
packages/@uppy/aws-s3/src/index.js

@@ -171,7 +171,7 @@ module.exports = class AwsS3 extends Plugin {
     this.uppy.addPreProcessor(this.prepareUpload)
 
     let warnedSuccessActionStatus = false
-    this.uppy.use(XHRUpload, {
+    let xhrUploadOpts = {
       fieldName: 'file',
       responseUrlFieldName: 'location',
       timeout: this.opts.timeout,
@@ -227,7 +227,14 @@ module.exports = class AwsS3 extends Plugin {
         const error = getXmlValue(content, 'Message')
         return new Error(error)
       }
-    })
+    }
+
+    // Replace getResponseData() with overwritten version.
+    if (this.opts.getResponseData) {
+      xhrUploadOpts.getResponseData = this.opts.getResponseData
+    }
+
+    this.uppy.use(XHRUpload, xhrUploadOpts)
   }
 
   uninstall () {

+ 1 - 1
packages/@uppy/core/src/Plugin.js

@@ -92,7 +92,7 @@ module.exports = class Plugin {
    * If it’s an object — target is a plugin, and we search `plugins`
    * for a plugin with same name and return its target.
    *
-   * @param {String|Object} target
+   * @param {string|Object} target
    *
    */
   mount (target, plugin) {

+ 3 - 3
packages/@uppy/dashboard/src/utils/copyToClipboard.js

@@ -4,9 +4,9 @@
  * Falls back to prompt() when the easy way fails (hello, Safari!)
  * From http://stackoverflow.com/a/30810322
  *
- * @param {String} textToCopy
- * @param {String} fallbackString
- * @return {Promise}
+ * @param {string} textToCopy
+ * @param {string} fallbackString
+ * @returns {Promise}
  */
 module.exports = function copyToClipboard (textToCopy, fallbackString) {
   fallbackString = fallbackString || 'Copy the URL below'

+ 2 - 2
packages/@uppy/thumbnail-generator/src/index.js

@@ -41,7 +41,7 @@ module.exports = class ThumbnailGenerator extends Plugin {
    *
    * @param {{data: Blob}} file
    * @param {number} width
-   * @return {Promise}
+   * @returns {Promise}
    */
   createThumbnail (file, targetWidth, targetHeight) {
     const originalUrl = URL.createObjectURL(file.data)
@@ -208,7 +208,7 @@ module.exports = class ThumbnailGenerator extends Plugin {
    * Save a <canvas> element's content to a Blob object.
    *
    * @param {HTMLCanvasElement} canvas
-   * @return {Promise}
+   * @returns {Promise}
    */
   canvasToBlob (canvas, type, quality) {
     try {

+ 4 - 4
packages/@uppy/transloadit/src/Client.js

@@ -11,7 +11,7 @@ module.exports = class Client {
   /**
    * Create a new assembly.
    *
-   * @param {object} options
+   * @param {Object} options
    */
   createAssembly ({
     templateId,
@@ -52,7 +52,7 @@ module.exports = class Client {
   /**
    * Reserve resources for a file in an Assembly. Then addFile can be used later.
    *
-   * @param {object} assembly
+   * @param {Object} assembly
    * @param {UppyFile} file
    */
   reserveFile (assembly, file) {
@@ -66,7 +66,7 @@ module.exports = class Client {
   /**
    * Import a remote file to an Assembly.
    *
-   * @param {object} assembly
+   * @param {Object} assembly
    * @param {UppyFile} file
    */
   addFile (assembly, file) {
@@ -88,7 +88,7 @@ module.exports = class Client {
   /**
    * Cancel a running Assembly.
    *
-   * @param {object} assembly
+   * @param {Object} assembly
    */
   cancelAssembly (assembly) {
     const url = assembly.assembly_ssl_url

+ 1 - 1
packages/@uppy/transloadit/src/index.js

@@ -361,7 +361,7 @@ module.exports = class Transloadit extends Plugin {
    * Custom state serialization for the Golden Retriever plugin.
    * It will pass this back to the `_onRestored` function.
    *
-   * @param {function} setData
+   * @param {Function} setData
    */
   _getPersistentData (setData) {
     const state = this.getPluginState()

+ 1 - 1
packages/@uppy/tus/src/index.js

@@ -119,7 +119,7 @@ module.exports = class Tus extends Plugin {
   /**
    * Create a new Tus upload
    *
-   * @param {object} file for use with 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}

+ 7 - 6
packages/@uppy/utils/src/Translator.js

@@ -50,8 +50,8 @@ module.exports = class Translator {
    * taken from https://github.com/airbnb/polyglot.js/blob/master/lib/polyglot.js#L299
    *
    * @param {string} phrase that needs interpolation, with placeholders
-   * @param {object} options with values that will be used to replace placeholders
-   * @return {string} interpolated
+   * @param {Object} options with values that will be used to replace placeholders
+   * @returns {string} interpolated
    */
   interpolate (phrase, options) {
     const { split, replace } = String.prototype
@@ -99,8 +99,8 @@ module.exports = class Translator {
    * Public translate method
    *
    * @param {string} key
-   * @param {object} options with values that will be used later to replace placeholders in string
-   * @return {string} translated (and interpolated)
+   * @param {Object} options with values that will be used later to replace placeholders in string
+   * @returns {string} translated (and interpolated)
    */
   translate (key, options) {
     return this.translateArray(key, options).join('')
@@ -108,9 +108,10 @@ module.exports = class Translator {
 
   /**
    * Get a translation and return the translated and interpolated parts as an array.
+   *
    * @param {string} key
-   * @param {object} options with values that will be used to replace placeholders
-   * @return {Array} The translated and interpolated parts, in order.
+   * @param {Object} options with values that will be used to replace placeholders
+   * @returns {Array} The translated and interpolated parts, in order.
    */
   translateArray (key, options) {
     if (options && typeof options.smart_count !== 'undefined') {

+ 1 - 1
packages/@uppy/utils/src/canvasToBlob.js

@@ -4,7 +4,7 @@ const dataURItoBlob = require('./dataURItoBlob')
  * Save a <canvas> element's content to a Blob object.
  *
  * @param {HTMLCanvasElement} canvas
- * @return {Promise}
+ * @returns {Promise}
  */
 module.exports = function canvasToBlob (canvas, type, quality) {
   if (canvas.toBlob) {

+ 1 - 1
packages/@uppy/utils/src/findAllDOMElements.js

@@ -4,7 +4,7 @@ const isDOMElement = require('./isDOMElement')
  * Find one or more DOM elements.
  *
  * @param {string} element
- * @return {Array|null}
+ * @returns {Array|null}
  */
 module.exports = function findAllDOMElements (element) {
   if (typeof element === 'string') {

+ 1 - 1
packages/@uppy/utils/src/findDOMElement.js

@@ -4,7 +4,7 @@ const isDOMElement = require('./isDOMElement')
  * Find a DOM element.
  *
  * @param {Node|string} element
- * @return {Node|null}
+ * @returns {Node|null}
  */
 module.exports = function findDOMElement (element, context = document) {
   if (typeof element === 'string') {

+ 1 - 1
packages/@uppy/utils/src/generateFileID.js

@@ -3,7 +3,7 @@
  * removing extra characters and adding type, size and lastModified
  *
  * @param {Object} file
- * @return {String} the fileID
+ * @returns {string} the fileID
  *
  */
 module.exports = function generateFileID (file) {

+ 1 - 1
packages/@uppy/utils/src/getFileNameAndExtension.js

@@ -2,7 +2,7 @@
 * Takes a full filename string and returns an object {name, extension}
 *
 * @param {string} fullFileName
-* @return {object} {name, extension}
+* @returns {Object} {name, extension}
 */
 module.exports = function getFileNameAndExtension (fullFileName) {
   var re = /(?:\.([^.]+))?$/

+ 1 - 1
packages/@uppy/utils/src/isDragDropSupported.js

@@ -1,7 +1,7 @@
 /**
  * Checks if the browser supports Drag & Drop (not supported on mobile devices, for example).
  *
- * @return {Boolean}
+ * @returns {boolean}
  */
 module.exports = function isDragDropSupported () {
   const div = document.createElement('div')

+ 1 - 1
packages/@uppy/utils/src/isObjectURL.js

@@ -2,7 +2,7 @@
  * Check if a URL string is an object URL from `URL.createObjectURL`.
  *
  * @param {string} url
- * @return {boolean}
+ * @returns {boolean}
  */
 module.exports = function isObjectURL (url) {
   return url.indexOf('blob:') === 0

+ 1 - 1
packages/@uppy/utils/src/limitPromises.js

@@ -4,7 +4,7 @@
  * will make sure that at most `limit` calls to `fn` are pending.
  *
  * @param {number} limit
- * @return {function()}
+ * @returns {function()}
  */
 module.exports = function limitPromises (limit) {
   let pending = 0

+ 21 - 4
packages/@uppy/xhr-upload/src/index.js

@@ -21,6 +21,19 @@ function buildResponseError (xhr, error) {
   return error
 }
 
+/**
+ * Set `data.type` in the blob to `file.meta.type`,
+ * because we might have detected a more accurate file type in Uppy
+ * https://stackoverflow.com/a/50875615
+ *
+ * @param {Object} file File object with `data`, `size` and `meta` properties
+ * @return {Object} blob updated with the new `type` set from `file.meta.type`
+ */
+function setTypeInBlob (file) {
+  const dataWithUpdatedType = file.data.slice(0, file.data.size, file.meta.type)
+  return dataWithUpdatedType
+}
+
 module.exports = class XHRUpload extends Plugin {
   static VERSION = require('../package.json').version
 
@@ -182,10 +195,12 @@ module.exports = class XHRUpload extends Plugin {
       formPost.append(item, file.meta[item])
     })
 
+    const dataWithUpdatedType = setTypeInBlob(file)
+
     if (file.name) {
-      formPost.append(opts.fieldName, file.data, file.name)
+      formPost.append(opts.fieldName, dataWithUpdatedType, file.meta.name)
     } else {
-      formPost.append(opts.fieldName, file.data)
+      formPost.append(opts.fieldName, dataWithUpdatedType)
     }
 
     return formPost
@@ -372,10 +387,12 @@ module.exports = class XHRUpload extends Plugin {
       files.forEach((file, i) => {
         const opts = this.getOptions(file)
 
+        const dataWithUpdatedType = setTypeInBlob(file)
+
         if (file.name) {
-          formData.append(opts.fieldName, file.data, file.name)
+          formData.append(opts.fieldName, dataWithUpdatedType, file.meta.name)
         } else {
-          formData.append(opts.fieldName, file.data)
+          formData.append(opts.fieldName, dataWithUpdatedType)
         }
       })
 

+ 4 - 2
website/build-examples.js

@@ -111,8 +111,9 @@ glob(srcPattern, (err, files) => {
     /**
      * Creates bundle and writes it to static and public folders.
      * Changes to
+     *
      * @param  {[type]} ids [description]
-     * @return {[type]}     [description]
+     * @returns {[type]}     [description]
      */
     function bundle (ids = []) {
       ids.forEach((id) => {
@@ -144,7 +145,8 @@ glob(srcPattern, (err, files) => {
 /**
  * Logs to console and shows desktop notification on error.
  * Calls `this.emit(end)` to stop bundling.
- * @param  {object} err Error object
+ *
+ * @param  {Object} err Error object
  */
 function onError (err) {
   console.error(chalk.red('✗ error:'), chalk.red(err.message))

+ 8 - 0
website/src/docs/aws-s3.md

@@ -96,6 +96,14 @@ The default is 30 seconds.
 Limit the amount of uploads going on at the same time. This is passed through to [XHRUpload](/docs/xhrupload#limit-0); see its documentation page for details.
 Set to `0` to disable limiting.
 
+### `getResponseData(responseText, response)`
+
+> This is an advanced option intended for use with _almost_ S3-compatible storage solutions.
+
+Customize response handling once an upload is completed. This passes the function through to @uppy/xhr-upload, see its [documentation](https://uppy.io/docs/xhr-upload/#getResponseData-responseText-response) for API details.
+
+This option is useful when uploading to an S3-like service that doesn't reply with an XML document, but with something else such as JSON.
+
 ### `locale: {}`
 
 Localize text that is shown to the user.