Explorar el Código

Resolve or remove miscellaneous todos (#2967)

Merlijn Vos hace 3 años
padre
commit
f0f1105ef0

+ 0 - 2
bin/locale-packs.js

@@ -68,8 +68,6 @@ function buildPluginsList () {
 
     // A few hacks to emulate browser environment because e.g.:
     // GoldenRetrieves calls upon MetaDataStore in the constructor, which uses localStorage
-    // @TODO Consider rewriting constructors so they don't make imperative calls that rely on
-    // browser environment (OR: just keep this browser mocking, if it's only causing issues for this script, it doesn't matter)
     global.location = { protocol: 'https' }
     global.navigator = { userAgent: '' }
     global.localStorage = {

+ 0 - 1
packages/@uppy/companion-client/src/Provider.js

@@ -46,7 +46,6 @@ module.exports = class Provider extends RequestClient {
     return response
   }
 
-  // @todo(i.olarewaju) consider whether or not this method should be exposed
   setAuthToken (token) {
     return this.uppy.getPlugin(this.pluginId).storage.setItem(this.tokenKey, token)
   }

+ 1 - 1
packages/@uppy/companion/src/companion.js

@@ -54,7 +54,7 @@ module.exports.app = (options = {}) => {
   validateConfig(options)
 
   options = merge({}, defaultOptions, options)
-  const providers = providerManager.getDefaultProviders(options)
+  const providers = providerManager.getDefaultProviders()
   const searchProviders = providerManager.getSearchProviders()
   providerManager.addProviderOptions(options, grantConfig)
 

+ 0 - 1
packages/@uppy/companion/src/server/controllers/connect.js

@@ -11,7 +11,6 @@ module.exports = function connect (req, res) {
   const { secret } = req.companion.options
   let state = oAuthState.generateState(secret)
   if (req.query.state) {
-    // todo change this query from state to "origin"
     const origin = JSON.parse(atob(req.query.state))
     state = oAuthState.addToState(state, origin, secret)
   }

+ 21 - 47
packages/@uppy/companion/src/server/controllers/send-token.js

@@ -1,12 +1,27 @@
-/**
- *
- * sends auth token to uppy client
- */
 const { URL } = require('url')
 const tokenService = require('../helpers/jwt')
 const { hasMatch, sanitizeHtml } = require('../helpers/utils')
 const oAuthState = require('../helpers/oauth-state')
-const versionCmp = require('../helpers/version')
+
+/**
+ *
+ * @param {string} token uppy auth token
+ * @param {string} origin url string
+ */
+const htmlContent = (token, origin) => {
+  return `
+    <!DOCTYPE html>
+    <html>
+    <head>
+        <meta charset="utf-8" />
+        <script>
+          window.opener.postMessage(${sanitizeHtml(JSON.stringify({ token }))}, ${sanitizeHtml(JSON.stringify(origin))})
+          window.close()
+        </script>
+    </head>
+    <body></body>
+    </html>`
+}
 
 /**
  *
@@ -33,49 +48,8 @@ module.exports = function sendToken (req, res, next) {
     const allowedClients = req.companion.options.clients
     // if no preset clients then allow any client
     if (!allowedClients || hasMatch(origin, allowedClients) || hasMatch((new URL(origin)).host, allowedClients)) {
-      const allowsStringMessage = versionCmp.gte(clientVersion, '1.0.2')
-      return res.send(allowsStringMessage ? htmlContent(uppyAuthToken, origin) : oldHtmlContent(uppyAuthToken, origin))
+      return res.send(htmlContent(uppyAuthToken, origin))
     }
   }
   next()
 }
-
-/**
- *
- * @param {string} token uppy auth token
- * @param {string} origin url string
- */
-const htmlContent = (token, origin) => {
-  return `
-    <!DOCTYPE html>
-    <html>
-    <head>
-        <meta charset="utf-8" />
-        <script>
-          window.opener.postMessage(JSON.stringify({token: "${token}"}), "${sanitizeHtml(origin)}")
-          window.close()
-        </script>
-    </head>
-    <body></body>
-    </html>`
-}
-
-/**
- * @todo remove this function in next major release
- * @param {string} token uppy auth token
- * @param {string} origin url string
- */
-const oldHtmlContent = (token, origin) => {
-  return `
-    <!DOCTYPE html>
-    <html>
-    <head>
-        <meta charset="utf-8" />
-        <script>
-          window.opener.postMessage({token: "${token}"}, "${sanitizeHtml(origin)}")
-          window.close()
-        </script>
-    </head>
-    <body></body>
-    </html>`
-}

+ 0 - 3
packages/@uppy/companion/src/server/provider/drive/index.js

@@ -43,9 +43,6 @@ function adaptData (listFilesResp, sharedDrivesResp, directory, query, showShare
     modifiedDate: adapter.getItemModifiedDate(item),
     size: adapter.getItemSize(item),
     custom: {
-      // @todo isTeamDrive is left for backward compatibility. We should remove it in the next
-      // major release.
-      isTeamDrive: adapter.isSharedDrive(item),
       isSharedDrive: adapter.isSharedDrive(item),
       imageHeight: adapter.getImageHeight(item),
       imageWidth: adapter.getImageWidth(item),

+ 3 - 5
packages/@uppy/companion/src/server/provider/index.js

@@ -75,11 +75,9 @@ module.exports.getProviderMiddleware = (providers, needsProviderCredentials) =>
 }
 
 /**
- * @param {{server: object, providerOptions: object}} companionOptions
  * @returns {Object.<string, typeof Provider>}
  */
-module.exports.getDefaultProviders = (companionOptions) => {
-  // @todo: we should rename drive to googledrive or google-drive or google
+module.exports.getDefaultProviders = () => {
   const providers = { dropbox, box, drive, facebook, onedrive, zoom, instagram }
 
   return providers
@@ -143,7 +141,7 @@ module.exports.addProviderOptions = (companionOptions, grantConfig) => {
         grantConfig[authProvider].dynamic = ['key', 'secret', 'redirect_uri']
       }
 
-      const provider = exports.getDefaultProviders(companionOptions)[providerName]
+      const provider = exports.getDefaultProviders()[providerName]
       Object.assign(grantConfig[authProvider], provider.getExtraConfig())
 
       // override grant.js redirect uri with companion's custom redirect url
@@ -174,7 +172,7 @@ module.exports.addProviderOptions = (companionOptions, grantConfig) => {
  * @returns {string} the authProvider for this provider
  */
 const providerNameToAuthName = (name, options) => {
-  const providers = exports.getDefaultProviders(options)
+  const providers = exports.getDefaultProviders()
   return (providers[name] || {}).authProvider
 }
 

+ 1 - 2
packages/@uppy/companion/src/standalone/helper.js

@@ -99,8 +99,7 @@ const getConfigFromEnv = () => {
     secret: getSecret('COMPANION_SECRET') || generateSecret(),
     preAuthSecret: getSecret('COMPANION_PREAUTH_SECRET') || generateSecret(),
     debug: process.env.NODE_ENV && process.env.NODE_ENV !== 'production',
-    // TODO: this is a temporary hack to support distributed systems.
-    // it is not documented, because it should be changed soon.
+    // cookieDomain is kind of a hack to support distributed systems. This should be improved but we never got so far.
     cookieDomain: process.env.COMPANION_COOKIE_DOMAIN,
     multipleInstances: true,
   }

+ 1 - 45
packages/@uppy/companion/test/__tests__/callback.js

@@ -37,51 +37,7 @@ describe('test authentication callback', () => {
     <head>
         <meta charset="utf-8" />
         <script>
-          window.opener.postMessage(JSON.stringify({token: "${token}"}), "http://localhost:3020")
-          window.close()
-        </script>
-    </head>
-    <body></body>
-    </html>`
-        expect(res.text).toBe(body)
-      })
-  })
-
-  test('the token gets to older clients without stringify', () => {
-    // see mock ../../src/server/helpers/oauth-state above for state values
-    return request(authServer)
-      .get(`/drive/send-token?uppyAuthToken=${token}&state=state-with-older-version`)
-      .expect(200)
-      .expect((res) => {
-        const body = `
-    <!DOCTYPE html>
-    <html>
-    <head>
-        <meta charset="utf-8" />
-        <script>
-          window.opener.postMessage({token: "${token}"}, "http://localhost:3020")
-          window.close()
-        </script>
-    </head>
-    <body></body>
-    </html>`
-        expect(res.text).toBe(body)
-      })
-  })
-
-  test('the token gets sent to newer clients with old version style', () => {
-    // see mock ../../src/server/helpers/oauth-state above for state values
-    return request(authServer)
-      .get(`/drive/send-token?uppyAuthToken=${token}&state=state-with-newer-version-old-style`)
-      .expect(200)
-      .expect((res) => {
-        const body = `
-    <!DOCTYPE html>
-    <html>
-    <head>
-        <meta charset="utf-8" />
-        <script>
-          window.opener.postMessage(JSON.stringify({token: "${token}"}), "http://localhost:3020")
+          window.opener.postMessage({"token":"${token}"}, "http://localhost:3020")
           window.close()
         </script>
     </head>

+ 0 - 5
packages/@uppy/core/src/index.js

@@ -1032,8 +1032,6 @@ class Uppy {
         bytesUploaded: data.bytesUploaded,
         bytesTotal: data.bytesTotal,
         percentage: canHavePercentage
-          // TODO(goto-bus-stop) flooring this should probably be the choice of the UI?
-          // we get more accurate calculations if we don't round this at all.
           ? Math.round((data.bytesUploaded / data.bytesTotal) * 100)
           : 0,
       },
@@ -1242,9 +1240,6 @@ class Uppy {
         },
       }
       delete files[file.id].progress.postprocess
-      // TODO should we set some kind of `fullyComplete` property on the file object
-      // so it's easier to see that the file is upload…fully complete…rather than
-      // what we have to do now (`uploadComplete && !postprocess`)
 
       this.setState({ files })
     })

+ 1 - 1
packages/@uppy/dashboard/src/components/Slide.js

@@ -23,7 +23,7 @@ class Slide extends Component {
     }
   }
 
-  // TODO: refactor this component to not use componentWillUpdate
+  // TODO: refactor to stable lifecycle method
   // eslint-disable-next-line
   componentWillUpdate (nextProps) {
     const { cachedChildren } = this.state

+ 1 - 1
packages/@uppy/dashboard/src/components/VirtualList.js

@@ -70,7 +70,7 @@ class VirtualList extends Component {
     window.addEventListener('resize', this.handleResize)
   }
 
-  // TODO: can we use a different method here?
+  // TODO: refactor to stable lifecycle method
   // eslint-disable-next-line
   componentWillUpdate () {
     if (this.base.contains(document.activeElement)) {

+ 1 - 3
packages/@uppy/google-drive/src/DriveProviderViews.js

@@ -6,9 +6,7 @@ module.exports = class DriveProviderViews extends ProviderViews {
     e.preventDefault()
 
     // Shared Drives aren't selectable; for all else, defer to the base ProviderView.
-    // @todo isTeamDrive is left for backward compatibility. We should remove it in the next
-    // major release.
-    if (!file.custom.isTeamDrive && !file.custom.isSharedDrive) {
+    if (!file.custom.isSharedDrive) {
       super.toggleCheckbox(e, file)
     }
   }

+ 3 - 4
packages/@uppy/provider-views/src/Breadcrumbs.js

@@ -1,9 +1,8 @@
-const { h } = require('preact')
+const { h, Fragment } = require('preact')
 
-// TODO use Fragment when upgrading to preact X
 const Breadcrumb = (props) => {
   return (
-    <span>
+    <Fragment>
       <button
         type="button"
         className="uppy-u-reset"
@@ -12,7 +11,7 @@ const Breadcrumb = (props) => {
         {props.title}
       </button>
       {!props.isLast ? ' / ' : ''}
-    </span>
+    </Fragment>
   )
 }
 

+ 0 - 10
packages/@uppy/transloadit/src/index.js

@@ -597,16 +597,6 @@ module.exports = class Transloadit extends BasePlugin {
       return assembly
     }
 
-    // TODO Do we still need this for anything…?
-    // eslint-disable-next-line no-unused-vars
-    const connected = new Promise((resolve, reject) => {
-      assembly.once('connect', resolve)
-      assembly.once('status', resolve)
-      assembly.once('error', reject)
-    }).then(() => {
-      this.uppy.log('[Transloadit] Socket is ready')
-    })
-
     assembly.connect()
     return assembly
   }

+ 13 - 38
packages/@uppy/tus/src/index.js

@@ -42,7 +42,6 @@ const tusDefaultOptions = {
   chunkSize: Infinity,
   retryDelays: [0, 1000, 3000, 5000],
   parallelUploads: 1,
-  storeFingerprintForResuming: true,
   removeFingerprintOnSuccess: false,
   uploadLengthDeferred: false,
   uploadDataDuringCreation: false,
@@ -66,7 +65,6 @@ module.exports = class Tus extends BasePlugin {
 
     // set default options
     const defaultOptions = {
-      resume: true,
       useFastRemoteRetry: true,
       limit: 0,
       retryDelays: [0, 1000, 3000, 5000],
@@ -119,13 +117,13 @@ module.exports = class Tus extends BasePlugin {
   resetUploaderReferences (fileID, opts = {}) {
     if (this.uploaders[fileID]) {
       const uploader = this.uploaders[fileID]
+
       uploader.abort()
+
       if (opts.abort) {
-        // to avoid 423 error from tus server, we wait
-        // to be sure the previous request has been aborted before terminating the upload
-        // @todo remove the timeout when this "wait" is handled in tus-js-client internally
-        setTimeout(() => uploader.abort(true), 1000)
+        uploader.abort(true)
       }
+
       this.uploaders[fileID] = null
     }
     if (this.uploaderEvents[fileID]) {
@@ -184,18 +182,9 @@ module.exports = class Tus extends BasePlugin {
       /** @type {RawTusOptions} */
       const uploadOptions = {
         ...tusDefaultOptions,
-        // TODO only put tus-specific options in?
         ...opts,
       }
 
-      delete uploadOptions.resume
-
-      // Make `resume: true` work like it did in tus-js-client v1.
-      // TODO: Remove in @uppy/tus v2
-      if (opts.resume) {
-        uploadOptions.storeFingerprintForResuming = true
-      }
-
       // We override tus fingerprint to uppy’s `file.id`, since the `file.id`
       // now also includes `relativePath` for files added from folders.
       // This means you can add 2 identical files, if one is in folder a,
@@ -279,25 +268,17 @@ module.exports = class Tus extends BasePlugin {
       this.uploaders[file.id] = upload
       this.uploaderEvents[file.id] = new EventTracker(this.uppy)
 
-      // Make `resume: true` work like it did in tus-js-client v1.
-      // TODO: Remove in @uppy/tus v2.
-      if (opts.resume) {
-        upload.findPreviousUploads().then((previousUploads) => {
-          const previousUpload = previousUploads[0]
-          if (previousUpload) {
-            this.uppy.log(`[Tus] Resuming upload of ${file.id} started at ${previousUpload.creationTime}`)
-            upload.resumeFromPreviousUpload(previousUpload)
-          }
-        })
-      }
+      upload.findPreviousUploads().then((previousUploads) => {
+        const previousUpload = previousUploads[0]
+        if (previousUpload) {
+          this.uppy.log(`[Tus] Resuming upload of ${file.id} started at ${previousUpload.creationTime}`)
+          upload.resumeFromPreviousUpload(previousUpload)
+        }
+      })
 
       let queuedRequest = this.requests.run(() => {
         if (!file.isPaused) {
-          // Ensure this gets scheduled to run _after_ `findPreviousUploads()` returns.
-          // TODO: Remove in @uppy/tus v2.
-          Promise.resolve().then(() => {
-            upload.start()
-          })
+          upload.start()
         }
         // Don't do anything here, the caller will take care of cancelling the upload itself
         // using resetUploaderReferences(). This is because resetUploaderReferences() has to be
@@ -362,7 +343,7 @@ module.exports = class Tus extends BasePlugin {
    * @param {number} total number of files in a queue
    * @returns {Promise<void>}
    */
-  uploadRemote (file, current, total) {
+  uploadRemote (file) {
     this.resetUploaderReferences(file.id)
 
     const opts = { ...this.opts }
@@ -421,9 +402,6 @@ module.exports = class Tus extends BasePlugin {
 
       this.onFileRemove(file.id, () => {
         queuedRequest.abort()
-        // still send pause event in case we are dealing with older version of companion
-        // @todo don't send pause event in the next major release.
-        socket.send('pause', {})
         socket.send('cancel', {})
         this.resetUploaderReferences(file.id)
         resolve(`upload ${file.id} was removed`)
@@ -451,9 +429,6 @@ module.exports = class Tus extends BasePlugin {
 
       this.onCancelAll(file.id, () => {
         queuedRequest.abort()
-        // still send pause event in case we are dealing with older version of companion
-        // @todo don't send pause event in the next major release.
-        socket.send('pause', {})
         socket.send('cancel', {})
         this.resetUploaderReferences(file.id)
         resolve(`upload ${file.id} was canceled`)

+ 0 - 4
packages/@uppy/utils/src/getFileTypeExtension.js

@@ -1,7 +1,3 @@
-// TODO Check which types are actually supported in browsers. Chrome likes webm
-// from my testing, but we may need more.
-// We could use a library but they tend to contain dozens of KBs of mappings,
-// most of which will go unused, so not sure if that's worth it.
 const mimeToExtensions = {
   'audio/mp3': 'mp3',
   'audio/mp4': 'mp4',

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

@@ -15,7 +15,6 @@ import Tus from '@uppy/tus'
 
 uppy.use(Tus, {
   endpoint: 'https://tusd.tusdemo.net/files/', // use your tus endpoint here
-  resume: true,
   retryDelays: [0, 1000, 3000, 5000]
 })
 ```
@@ -42,18 +41,6 @@ const Tus = Uppy.Tus
 
 A unique identifier for this plugin. It defaults to `'Tus'`.
 
-### `resume: true`
-
-A boolean indicating whether Tus should attempt to resume the upload if the upload has been started in the past. This includes storing the file’s upload URL. Set to false to force an entire reupload.
-
-Note that this option is about resuming when you start an upload again with the same file, or when using the [GoldenRetriever](/docs/golden-retriever/) plugin, which will attempt to restore upload state to what it was before page refresh / browser crash. Even if you set `resume: false` when using the Tus uploader, users will still be able to pause/resume an ongoing upload.
-
-In most cases you should leave this option as is, relax, and enjoy resumable uploads.
-
-### `removeFingerprintOnSuccess: false`
-
-If the `resume` option is enabled, it will store some data in localStorage for each upload. With `removeFingerprintOnSuccess`, this data is removed once an upload has completed. The effect is that if the same file is uploaded again, it will create an entirely new upload.
-
 ### `endpoint: ''`
 
 Destination URL for your uploads. This should be where your tus.io server is running.

+ 0 - 7
website/themes/uppy/source/css/_page.scss

@@ -297,13 +297,6 @@ table tr:last-child td {
     margin-bottom: 0.8em;
   }
 
-  .post li,
-  > ul li,
-  > li {
-    // @TODO can this safely be removed artur?
-    // margin-bottom: 0.5em;
-  }
-
   .post p, .post ul, .post ol,
   > p, > ul, > ol {
     line-height: 1.5em;

+ 0 - 22
website/themes/uppy/source/js/common.js

@@ -289,26 +289,4 @@
     loopTaglines()
     setInterval(loopTaglines, 4000)
   }
-
-  // Search with SwiftType
-  // @todo get our own swifttype
-
-  // (function(w,d,t,u,n,s,e){w['SwiftypeObject']=n;w[n]=w[n]||function(){
-  // (w[n].q=w[n].q||[]).push(arguments);};s=d.createElement(t);
-  // e=d.getElementsByTagName(t)[0];s.async=1;s.src=u;e.parentNode.insertBefore(s,e);
-  // })(window,document,'script','//s.swiftypecdn.com/install/v2/st.js','_st');
-
-  // _st('install','HgpxvBc7pUaPUWmG9sgv','2.0.0');
-
-  // version select
-  // document.querySelector('.version-select').addEventListener('change', function (e) {
-  //   var version = e.target.value
-  //   if (version.indexOf('1.') !== 0) {
-  //     version = version.replace('.', '')
-  //     var section = window.location.pathname.match(/\/(\w+?)\//)[1]
-  //     window.location.assign('http://' + version + '.uppy.io/' + section + '/')
-  //   } else {
-  //     // TODO when 1.x is out
-  //   }
-  // })
 }())