Skip to content

Commit

Permalink
Add @uppy/remote-sources preset/plugin (#3676)
Browse files Browse the repository at this point in the history
Co-authored-by: Merlijn Vos <merlijn@soverin.net>
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
3 people committed Jun 7, 2022
1 parent 2c05d51 commit 9a59711
Show file tree
Hide file tree
Showing 14 changed files with 919 additions and 24 deletions.
7 changes: 4 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
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',
'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
21 changes: 21 additions & 0 deletions packages/@uppy/remote-sources/LICENSE
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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).
51 changes: 51 additions & 0 deletions packages/@uppy/remote-sources/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"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",
"type": "module",
"keywords": [
"file uploader",
"instagram",
"google-drive",
"facebook",
"dropbox",
"onedrive",
"zoom",
"unsplash",
"box",
"url"
],
"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"
},
"devDependencies": {
"@jest/globals": "^28.1.0",
"resize-observer-polyfill": "^1.5.1"
}
}
83 changes: 83 additions & 0 deletions packages/@uppy/remote-sources/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
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

#installedPlugins = new Set()

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 }

if (this.opts.companionUrl == null) {
throw new Error('Please specify companionUrl for RemoteSources to work, see https://uppy.io/docs/remote-sources#companionUrl')
}
}

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

install () {
this.opts.sources.forEach((pluginId) => {
const optsForRemoteSourcePlugin = { ...this.opts, sources: undefined }
const plugin = availablePlugins.find(p => p.name === pluginId)
if (plugin == null) {
const pluginNames = availablePlugins.map(p => p.name)
const formatter = new Intl.ListFormat('en', { style: 'long', type: 'disjunction' })
throw new Error(`Invalid plugin: "${pluginId}" is not one of: ${formatter.format(pluginNames)}.`)
}
this.uppy.use(plugin, optsForRemoteSourcePlugin)
this.#installedPlugins.add(plugin)
})
}

uninstall () {
for (const plugin of this.#installedPlugins) {
this.uppy.removePlugin(plugin)
}
this.#installedPlugins.clear()
}
}
42 changes: 42 additions & 0 deletions packages/@uppy/remote-sources/src/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { describe, expect, it } from '@jest/globals'
import resizeObserverPolyfill from 'resize-observer-polyfill'
import Core from '@uppy/core'
import Dashboard from '@uppy/dashboard'
import RemoteSources from './index.js'

describe('RemoteSources', () => {
beforeAll(() => {
globalThis.ResizeObserver = resizeObserverPolyfill.default || resizeObserverPolyfill
})

afterAll(() => {
delete globalThis.ResizeObserver
})

it('should install RemoteSources with default options', () => {
expect(() => {
const core = new Core()
core.use(Dashboard)
core.use(RemoteSources, { companionUrl: 'https://example.com' })
}).not.toThrow()
})

it('should throw when a companionUrl is not specified', () => {
expect(() => {
const core = new Core()
core.use(Dashboard)
core.use(RemoteSources, { sources: ['Webcam'] })
}).toThrow(new Error('Please specify companionUrl for RemoteSources to work, see https://uppy.io/docs/remote-sources#companionUrl'))
})

it('should throw when trying to use a plugin which is not included in RemoteSources', () => {
expect(() => {
const core = new Core()
core.use(Dashboard)
core.use(RemoteSources, {
companionUrl: 'https://example.com',
sources: ['Webcam'],
})
}).toThrow('Invalid plugin: "Webcam" is not one of: Box, Dropbox, Facebook, GoogleDrive, Instagram, OneDrive, Unsplash, Url, or Zoom.')
})
})
13 changes: 13 additions & 0 deletions packages/@uppy/remote-sources/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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
companionUrl: 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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 9a59711

Please sign in to comment.