Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @uppy/remote-sources preset/plugin #3676

Merged
merged 24 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ac1f5df
Add @uppy/remote-sources preset/plugin
arturi Apr 29, 2022
04dd8c7
yarn.lock
arturi Apr 29, 2022
3fd0002
Update packages/@uppy/remote-sources/README.md
arturi May 3, 2022
3af5fe9
Allow configuring sources, use Dashboard as default target
arturi May 26, 2022
c6cd1bb
Merge branch 'main' into remote-sources
arturi May 26, 2022
54e51e7
Add remote-sources to the CDN bundle
arturi May 26, 2022
d3eb0c0
Added docs, readme, types
arturi May 26, 2022
f65e456
Update yarn.lock
arturi May 26, 2022
d2fe057
Merge branch 'main' of https://github.com/transloadit/uppy into remot…
arturi May 26, 2022
c1bfc95
update readme, dev example, don't expose defaultOptions
arturi May 27, 2022
d249bea
Merge branch 'main' into remote-sources
arturi May 27, 2022
fba2ffe
Alphabetical order
arturi May 27, 2022
76a760c
Increase retryDelays to hopefully make the exponential backoff test m…
arturi May 27, 2022
9bf0d67
Update packages/@uppy/remote-sources/package.json
arturi May 30, 2022
f4ba2aa
Update packages/@uppy/remote-sources/src/index.js
arturi May 30, 2022
8106fda
Update packages/@uppy/remote-sources/src/index.js
arturi May 30, 2022
18b1172
Store installedPlugins in a Set
arturi Jun 1, 2022
d686ebb
Revert "Increase retryDelays to hopefully make the exponential backof…
arturi Jun 1, 2022
454ad85
Require companionUrl and plugins stricly from the included, add tests
arturi Jun 7, 2022
a455bf8
Update packages/@uppy/remote-sources/src/index.js
arturi Jun 7, 2022
15e715d
Update private/dev/Dashboard.js
arturi Jun 7, 2022
e57111e
Update doc option type format
arturi Jun 7, 2022
b498178
Better intro from Merlijn
arturi Jun 7, 2022
fa53fbc
Apply suggestions from code review
aduh95 Jun 7, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions .eslintrc.js
Expand Up @@ -197,8 +197,8 @@ module.exports = {

// Packages that have switched to ESM sources:
'packages/@uppy/audio/src/**/*.js',
'packages/@uppy/aws-s3/src/**/*.js',
'packages/@uppy/aws-s3-multipart/src/**/*.js',
'packages/@uppy/aws-s3/src/**/*.js',
aduh95 marked this conversation as resolved.
Show resolved Hide resolved
'packages/@uppy/box/src/**/*.js',
'packages/@uppy/companion-client/src/**/*.js',
'packages/@uppy/compressor/src/**/*.js',
Expand All @@ -221,16 +221,17 @@ module.exports = {
'packages/@uppy/progress-bar/src/**/*.js',
'packages/@uppy/provider-views/src/**/*.js',
'packages/@uppy/redux-dev-tools/src/**/*.js',
'packages/@uppy/remote-sources/src/**/*.js',
'packages/@uppy/screen-capture/src/**/*.js',
'packages/@uppy/status-bar/src/**/*.js',
'packages/@uppy/store-default/src/**/*.js',
'packages/@uppy/store-redux/src/**/*.js',
'packages/@uppy/svelte/src/**/*.js',
'packages/@uppy/svelte/rollup.config.js',
'packages/@uppy/svelte/src/**/*.js',
'packages/@uppy/thumbnail-generator/src/**/*.js',
'packages/@uppy/transloadit/src/**/*.js',
'packages/@uppy/tus/src/**/*.js',
'packages/@uppy/unsplash/src/**/*.js',
'packages/@uppy/transloadit/src/**/*.js',
'packages/@uppy/url/src/**/*.js',
'packages/@uppy/utils/src/**/*.js',
'packages/@uppy/vue/src/**/*.js',
Expand Down
6 changes: 5 additions & 1 deletion e2e/clients/dashboard-tus/app.js
Expand Up @@ -17,7 +17,11 @@ function onShouldRetry (err, retryAttempt, options, next) {
const companionUrl = 'http://localhost:3020'
const uppy = new Uppy()
.use(Dashboard, { target: '#app', inline: true })
.use(Tus, { endpoint: 'https://tusd.tusdemo.net/files', onShouldRetry })
.use(Tus, {
endpoint: 'https://tusd.tusdemo.net/files',
onShouldRetry,
retryDelays: [2000, 3000, 4000],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks unrelated, can we put it in its own PR (or remove it)

})
.use(Url, { target: Dashboard, companionUrl })
.use(Unsplash, { target: Dashboard, companionUrl })

Expand Down
3 changes: 1 addition & 2 deletions e2e/cypress/integration/dashboard-tus.spec.ts
Expand Up @@ -30,11 +30,10 @@ describe('Dashboard with Tus', () => {
cy.get('.uppy-StatusBar-actionBtn--upload').click()

cy.intercept(
{ method: 'PATCH', pathname: '/files/*', times: 2 },
{ method: 'PATCH', pathname: '/files/*', times: 1 },
{ statusCode: 429, body: {} },
).as('patch')

cy.wait('@patch')
cy.wait('@patch')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here


cy.window().then(({ uppy }) => {
Expand Down
21 changes: 21 additions & 0 deletions packages/@uppy/remote-sources/LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2022 Transloadit

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
35 changes: 35 additions & 0 deletions packages/@uppy/remote-sources/README.md
@@ -0,0 +1,35 @@
# @uppy/remote-sources

<img src="https://uppy.io/images/logos/uppy-dog-head-arrow.svg" width="120" alt="Uppy logo: a superman puppy in a pink suit" align="right">

<a href="https://www.npmjs.com/package/@uppy/remote-sources"><img src="https://img.shields.io/npm/v/@uppy/compressor.svg?style=flat-square"></a> <img src="https://github.com/transloadit/uppy/workflows/Tests/badge.svg" alt="CI status for Uppy tests"> <img src="https://github.com/transloadit/uppy/workflows/Companion/badge.svg" alt="CI status for Companion tests"> <img src="https://github.com/transloadit/uppy/workflows/End-to-end%20tests/badge.svg" alt="CI status for browser tests">

## Example

```js
import Uppy from '@uppy/core'
import RemoteSources from '@uppy/remote-sources'

const uppy = new Uppy()
uppy.use(RemoteSources, {
companionUrl: 'https://your-companion-url',
})
```

## Installation

```bash
npm install @uppy/remote-sources
# or
yarn add @uppy/remote-sources
```

Alternatively, you can also use this plugin in a pre-built bundle from Transloadit’s CDN: Edgly. In that case `Uppy.RemoteSources` will attach itself to the global `window.Uppy` object. See the [main Uppy documentation](https://uppy.io/docs/#Installation) for instructions.

## Documentation

Documentation for this plugin can be found on the [Uppy website](https://uppy.io/docs/remote-sources).

## License

[The MIT License](./LICENSE).
47 changes: 47 additions & 0 deletions packages/@uppy/remote-sources/package.json
@@ -0,0 +1,47 @@
{
"name": "@uppy/remote-sources",
"description": "Uppy plugin that includes all remote sources that Uppy+Companion offer, like Instagram, Google Drive, Dropox, Box, Unsplash, Url etc",
"version": "0.1.0",
"license": "MIT",
"main": "lib/index.js",
"types": "types/index.d.ts",
arturi marked this conversation as resolved.
Show resolved Hide resolved
"keywords": [
"file uploader",
"instagram",
"google-drive",
"facebook",
"dropbox",
"onedrive",
"zoom",
"unsplash",
"box",
"url"
],
"type": "module",
"homepage": "https://uppy.io",
"bugs": {
"url": "https://github.com/transloadit/uppy/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/transloadit/uppy.git"
},
"dependencies": {
"@uppy/box": "workspace:^",
"@uppy/dashboard": "workspace:^",
"@uppy/dropbox": "workspace:^",
"@uppy/facebook": "workspace:^",
"@uppy/google-drive": "workspace:^",
"@uppy/instagram": "workspace:^",
"@uppy/onedrive": "workspace:^",
"@uppy/unsplash": "workspace:^",
"@uppy/url": "workspace:^",
"@uppy/zoom": "workspace:^"
},
"peerDependencies": {
"@uppy/core": "workspace:^"
},
"publishConfig": {
"access": "public"
}
}
72 changes: 72 additions & 0 deletions packages/@uppy/remote-sources/src/index.js
@@ -0,0 +1,72 @@
import { BasePlugin } from '@uppy/core'
import Dashboard from '@uppy/dashboard'
import Dropbox from '@uppy/dropbox'
import GoogleDrive from '@uppy/google-drive'
import Instagram from '@uppy/instagram'
import Facebook from '@uppy/facebook'
import OneDrive from '@uppy/onedrive'
import Box from '@uppy/box'
import Unsplash from '@uppy/unsplash'
import Url from '@uppy/url'
import Zoom from '@uppy/zoom'

import packageJson from '../package.json'

const availablePlugins = [
Box,
Dropbox,
Facebook,
GoogleDrive,
Instagram,
OneDrive,
Unsplash,
Url,
Zoom,
]

export default class RemoteSources extends BasePlugin {
static VERSION = packageJson.version

constructor (uppy, opts) {
super(uppy, opts)
this.id = this.opts.id || 'RemoteSources'
this.type = 'acquirer'

const defaultOptions = {
sources: [
'Box',
'Dropbox',
'Facebook',
'GoogleDrive',
'Instagram',
'OneDrive',
'Unsplash',
'Url',
],
target: Dashboard,
}
this.opts = { ...defaultOptions, ...opts }
}

setOptions (newOpts) {
this.uninstall()
super.setOptions(newOpts)
this.install()
}

install () {
this.opts.sources.forEach((pluginName) => {
const optsForRemoteSourcePlugin = { ...this.opts }
delete optsForRemoteSourcePlugin.sources
arturi marked this conversation as resolved.
Show resolved Hide resolved
const plugin = availablePlugins.filter(p => p.name === pluginName)[0]
arturi marked this conversation as resolved.
Show resolved Hide resolved
this.uppy.use(plugin, optsForRemoteSourcePlugin)
})
}

uninstall () {
this.opts.sources.forEach((pluginName) => {
const plugin = this.uppy.getPlugin(pluginName)
this.uppy.removePlugin(plugin)
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be worried that this.opts.sources can be modified by the user and the uninstall would not work correctly? Another (better?) way of handling it would be to have a private Set on the instance that caches all the plugins that were installed.

Suggested change
this.opts.sources.forEach((pluginName) => {
const plugin = this.uppy.getPlugin(pluginName)
this.uppy.removePlugin(plugin)
})
this.#installedPlugins.forEach(plugin => this.uppy.removePlugin(plugin))
this.#installedPlugins.clear()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it sounds better, not sure if Set is required or just a private array. But I did think of this, if you modify options the correct way via uppy.getPlugin('RemoteSources').setOptions({ sources: ['Instagram'] }), the plugin will first uninstall everything, then update options and install back: https://github.com/transloadit/uppy/pull/3676/files#diff-3b90938b025125a702e11b69f66acdd0c6985a892f64f4a28b06f0dcdb24e873R51-R55

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should not assume that users will always use the correct way.

const sources = ['Instagram']
uppy.use(RemoteSources, { sources })

sources.pop() // The user mutates the array for some reason

uppy.getPlugin('RemoteSources').uninstall() // The Instagram plugin is still installed

I think Set is more suited for our use case, but I suppose an array would also work.

}
}
12 changes: 12 additions & 0 deletions packages/@uppy/remote-sources/types/index.d.ts
@@ -0,0 +1,12 @@
import type { PluginOptions, BasePlugin, PluginTarget } from '@uppy/core'
import type { RequestClientOptions } from '@uppy/companion-client'

interface RemoteTargetOptions extends PluginOptions, RequestClientOptions {
target?: PluginTarget
sources?: Array<string>
title?: string
}

declare class RemoteTarget extends BasePlugin<RemoteTargetOptions> {}

export default RemoteTarget
11 changes: 11 additions & 0 deletions packages/@uppy/remote-sources/types/index.test-d.ts
@@ -0,0 +1,11 @@
import Uppy from '@uppy/core'
import RemoteSources from '..'

{
const uppy = new Uppy()
uppy.use(RemoteSources, {
sources: ['Instagram', 'Url'],
companionUrl: '',
companionCookiesRule: 'same-origin',
})
}
1 change: 1 addition & 0 deletions packages/uppy/index.js
Expand Up @@ -33,6 +33,7 @@ exports.Facebook = require('@uppy/facebook')
exports.GoogleDrive = require('@uppy/google-drive')
exports.Instagram = require('@uppy/instagram')
exports.OneDrive = require('@uppy/onedrive')
exports.RemoteSources = require('@uppy/remote-sources')
exports.ScreenCapture = require('@uppy/screen-capture')
exports.Unsplash = require('@uppy/unsplash')
exports.Url = require('@uppy/url')
Expand Down
1 change: 1 addition & 0 deletions packages/uppy/index.mjs
Expand Up @@ -30,6 +30,7 @@ export { default as Facebook } from '@uppy/facebook'
export { default as GoogleDrive } from '@uppy/google-drive'
export { default as Instagram } from '@uppy/instagram'
export { default as OneDrive } from '@uppy/onedrive'
export { default as RemoteSources } from '@uppy/remote-sources'
export { default as ScreenCapture } from '@uppy/screen-capture'
export { default as Unsplash } from '@uppy/unsplash'
export { default as Url } from '@uppy/url'
Expand Down
4 changes: 4 additions & 0 deletions packages/uppy/package.json
Expand Up @@ -54,6 +54,7 @@
"@uppy/progress-bar": "workspace:^",
"@uppy/provider-views": "workspace:^",
"@uppy/redux-dev-tools": "workspace:^",
"@uppy/remote-sources": "workspace:^",
"@uppy/screen-capture": "workspace:^",
"@uppy/status-bar": "workspace:^",
"@uppy/store-default": "workspace:^",
Expand All @@ -74,5 +75,8 @@
"regenerator-runtime": "0.13.9",
"resize-observer-polyfill": "^1.5.1",
"whatwg-fetch": "^3.6.2"
},
"publishConfig": {
"access": "public"
}
}
32 changes: 14 additions & 18 deletions private/dev/Dashboard.js
Expand Up @@ -2,15 +2,7 @@
/* eslint-disable import/no-extraneous-dependencies */
import Uppy from '@uppy/core'
import Dashboard from '@uppy/dashboard'
import Instagram from '@uppy/instagram'
import Facebook from '@uppy/facebook'
import OneDrive from '@uppy/onedrive'
import Dropbox from '@uppy/dropbox'
import Box from '@uppy/box'
import GoogleDrive from '@uppy/google-drive'
import Unsplash from '@uppy/unsplash'
import Zoom from '@uppy/zoom'
import Url from '@uppy/url'
import RemoteSources from '@uppy/remote-sources'
import Webcam from '@uppy/webcam'
import ScreenCapture from '@uppy/screen-capture'
import GoldenRetriever from '@uppy/golden-retriever'
Expand Down Expand Up @@ -83,15 +75,19 @@ export default () => {
proudlyDisplayPoweredByUppy: true,
note: '2 files, images and video only',
})
.use(GoogleDrive, { target: Dashboard, companionUrl: COMPANION_URL })
.use(Instagram, { target: Dashboard, companionUrl: COMPANION_URL })
.use(Dropbox, { target: Dashboard, companionUrl: COMPANION_URL })
.use(Box, { target: Dashboard, companionUrl: COMPANION_URL })
.use(Facebook, { target: Dashboard, companionUrl: COMPANION_URL })
.use(OneDrive, { target: Dashboard, companionUrl: COMPANION_URL })
.use(Zoom, { target: Dashboard, companionUrl: COMPANION_URL })
.use(Url, { target: Dashboard, companionUrl: COMPANION_URL })
.use(Unsplash, { target: Dashboard, companionUrl: COMPANION_URL })
// .use(GoogleDrive, { target: Dashboard, companionUrl: COMPANION_URL })
// .use(Instagram, { target: Dashboard, companionUrl: COMPANION_URL })
// .use(Dropbox, { target: Dashboard, companionUrl: COMPANION_URL })
// .use(Box, { target: Dashboard, companionUrl: COMPANION_URL })
// .use(Facebook, { target: Dashboard, companionUrl: COMPANION_URL })
// .use(OneDrive, { target: Dashboard, companionUrl: COMPANION_URL })
// .use(Zoom, { target: Dashboard, companionUrl: COMPANION_URL })
// .use(Url, { target: Dashboard, companionUrl: COMPANION_URL })
// .use(Unsplash, { target: Dashboard, companionUrl: COMPANION_URL })
.use(RemoteSources, {
companionUrl: COMPANION_URL,
sources: ['Box', 'Dropbox', 'Facebook', 'GoogleDrive', 'Instagram', 'OneDrive', 'Unsplash', 'Url'],
})
.use(Webcam, {
target: Dashboard,
showVideoSourceDropdown: true,
Expand Down