Prechádzať zdrojové kódy

tus: implement `metaFields` (#1644)

A quick copy-paste hackjob from XHRUpload.
Renée Kooi 5 rokov pred
rodič
commit
2faa3a1d1d
2 zmenil súbory, kde vykonal 18 pridanie a 1 odobranie
  1. 10 1
      packages/@uppy/tus/src/index.js
  2. 8 0
      website/src/docs/tus.md

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

@@ -179,10 +179,19 @@ module.exports = class Tus extends Plugin {
         }
         }
       }
       }
 
 
+      const meta = {}
+      const metaFields = Array.isArray(optsTus.metaFields)
+        ? optsTus.metaFields
+        // Send along all fields by default.
+        : Object.keys(file.meta)
+      metaFields.forEach((item) => {
+        meta[item] = file.meta[item]
+      })
+
       // tusd uses metadata fields 'filetype' and 'filename'
       // tusd uses metadata fields 'filetype' and 'filename'
-      const meta = Object.assign({}, file.meta)
       copyProp(meta, 'type', 'filetype')
       copyProp(meta, 'type', 'filetype')
       copyProp(meta, 'name', 'filename')
       copyProp(meta, 'name', 'filename')
+
       optsTus.metadata = meta
       optsTus.metadata = meta
 
 
       const upload = new tus.Upload(file.data, optsTus)
       const upload = new tus.Upload(file.data, optsTus)

+ 8 - 0
website/src/docs/tus.md

@@ -56,6 +56,14 @@ In most cases you should leave this option as is, relax, and enjoy resumable upl
 
 
 Destination URL for your uploads. This should be where your tus.io server is running.
 Destination URL for your uploads. This should be where your tus.io server is running.
 
 
+### `metaFields: null`
+
+Pass an array of field names to limit the metadata fields that will be added to uploads as [Tus Metadata](https://tus.io/protocols/resumable-upload.html#upload-metadata).
+
+* Set this to `['name']` to only send the `name` field.
+* Set this to `null` (the default) to send *all* metadata fields.
+* Set this to an empty array `[]` to not send any fields.
+
 ### `autoRetry: true`
 ### `autoRetry: true`
 
 
 Configures whether or not to auto-retry the upload when the user's internet connection is back online after an outage.
 Configures whether or not to auto-retry the upload when the user's internet connection is back online after an outage.