Преглед на файлове

Merge pull request #1550 from transloadit/remove-default-protocol

companion: remove default upload protocol
Ifedapo .A. Olarewaju преди 6 години
родител
ревизия
3dd930d658

+ 1 - 0
CHANGELOG.md

@@ -107,6 +107,7 @@ PRs are welcome! Please do open an issue to discuss first if it's a big feature,
 - [x] @uppy/companion: investigate 423 and 500 issues with React Native + Url plugin when pause/resuming an upload
 - [x] dashboard: Bring back "Drop Here" screen for dragged URLs without introducing flickering (tricky! see PR #1400)
 - [x] companion: remove deprecated "authorized" endpoint
+- [x] companion: remove default upload protocol
 
 ## 1.0 Goals
 

+ 6 - 2
packages/@uppy/companion/src/server/Uploader.js

@@ -93,6 +93,11 @@ class Uploader {
    * @returns {boolean}
    */
   validateOptions (options) {
+    if (!Object.keys(PROTOCOLS).some((key) => PROTOCOLS[key] === options.protocol)) {
+      this._errRespMessage = 'Invalid upload protocol'
+      return false
+    }
+
     // s3 uploads don't require upload destination
     // validation, because the destination is determined
     // by the server's s3 config
@@ -157,8 +162,7 @@ class Uploader {
    * @param {Buffer | Buffer[]} chunk
    */
   handleChunk (chunk) {
-    // @todo a default protocol should not be set. We should ensure that the user specifies her protocol.
-    const protocol = this.options.protocol || PROTOCOLS.multipart
+    const protocol = this.options.protocol
 
     // The download has completed; close the file and start an upload if necessary.
     if (chunk === null) {

+ 11 - 0
packages/@uppy/companion/test/__tests__/companion.js

@@ -63,6 +63,17 @@ describe('download provdier file', () => {
       .expect(200)
       .then((res) => expect(res.body.token).toBeTruthy())
   })
+
+  test('download should fail if protocol is not specified', () => {
+    return request(authServer)
+      .post('/drive/get/README.md')
+      .set('uppy-auth-token', token)
+      .set('Content-Type', 'application/json')
+      .send({
+        endpoint: 'http://master.tus.com/files'
+      })
+      .expect(400)
+  })
 })
 
 describe('test authentication', () => {

+ 1 - 0
packages/@uppy/xhr-upload/src/index.js

@@ -324,6 +324,7 @@ module.exports = class XHRUpload extends Plugin {
         file.remote.url,
         Object.assign({}, file.remote.body, {
           endpoint: opts.endpoint,
+          protocol: 'multipart',
           size: file.data.size,
           fieldname: opts.fieldName,
           metadata: fields,