-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add @uppy/remote-sources preset/plugin (#3676)
Co-authored-by: Merlijn Vos <merlijn@soverin.net> Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
- Loading branch information
1 parent
2c05d51
commit 9a59711
Showing
14 changed files
with
919 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.