mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-26 03:35:19 +00:00
rename serverUrl to companionUrl
and serverPattern to companionAllowedHosts
This commit is contained in:
parent
11cb650401
commit
f4e558bf94
25 changed files with 53 additions and 53 deletions
|
|
@ -18,7 +18,7 @@ const AwsS3Multipart = require('@uppy/aws-s3-multipart')
|
|||
const uppy = Uppy()
|
||||
uppy.use(AwsS3Multipart, {
|
||||
limit: 2,
|
||||
serverUrl: 'https://companion.myapp.com/'
|
||||
companionUrl: 'https://companion.myapp.com/'
|
||||
})
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -86,8 +86,8 @@ module.exports = class AwsS3Multipart extends Plugin {
|
|||
}
|
||||
|
||||
assertHost () {
|
||||
if (!this.opts.serverUrl) {
|
||||
throw new Error('Expected a `serverUrl` option containing a Companion address.')
|
||||
if (!this.opts.companionUrl) {
|
||||
throw new Error('Expected a `companionUrl` option containing a Companion address.')
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -278,7 +278,7 @@ module.exports = class AwsS3Multipart extends Plugin {
|
|||
connectToServerSocket (file) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const token = file.serverToken
|
||||
const host = getSocketHost(file.remote.serverUrl)
|
||||
const host = getSocketHost(file.remote.companionUrl)
|
||||
const socket = new Socket({ target: `${host}/api/${token}` })
|
||||
this.uploaderSockets[socket] = socket
|
||||
this.uploaderEvents[file.id] = createEventTracker(this.uppy)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ declare module AwsS3Multipart {
|
|||
}
|
||||
|
||||
interface AwsS3MultipartOptions extends Uppy.PluginOptions {
|
||||
serverUrl: string;
|
||||
companionUrl: string;
|
||||
createMultipartUpload(file: Uppy.UppyFile): Promise<{ uploadId: string, key: string }>;
|
||||
listParts(file: Uppy.UppyFile, opts: { uploadId: string, key: string }): Promise<AwsS3Part[]>;
|
||||
prepareUploadPart(file: Uppy.UppyFile, partData: { uploadId: string, key: string, body: Blob, number: number }): Promise<{ url: string }>;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ const uppy = Uppy()
|
|||
uppy.use(AwsS3, {
|
||||
limit: 2,
|
||||
timeout: ms('1 minute'),
|
||||
serverUrl: 'https://companion.myapp.com/'
|
||||
companionUrl: 'https://companion.myapp.com/'
|
||||
})
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -66,8 +66,8 @@ module.exports = class AwsS3 extends Plugin {
|
|||
}
|
||||
|
||||
getUploadParameters (file) {
|
||||
if (!this.opts.serverUrl) {
|
||||
throw new Error('Expected a `serverUrl` option containing a Companion address.')
|
||||
if (!this.opts.companionUrl) {
|
||||
throw new Error('Expected a `companionUrl` option containing a Companion address.')
|
||||
}
|
||||
|
||||
const filename = encodeURIComponent(file.meta.name)
|
||||
|
|
|
|||
2
packages/@uppy/aws-s3/types/index.d.ts
vendored
2
packages/@uppy/aws-s3/types/index.d.ts
vendored
|
|
@ -9,7 +9,7 @@ declare module AwsS3 {
|
|||
}
|
||||
|
||||
interface AwsS3Options extends Uppy.PluginOptions {
|
||||
serverUrl: string;
|
||||
companionUrl: string;
|
||||
getUploadParameters(file: Uppy.UppyFile): Promise<AwsS3UploadParameters>;
|
||||
timeout: number;
|
||||
limit: number;
|
||||
|
|
|
|||
|
|
@ -17,11 +17,11 @@ const { Provider, RequestClient, Socket } = require('@uppy/companion-client')
|
|||
|
||||
const uppy = Uppy()
|
||||
|
||||
const client = new RequestClient(uppy, { serverUrl: 'https://uppy.mywebsite.com/' })
|
||||
const client = new RequestClient(uppy, { companionUrl: 'https://uppy.mywebsite.com/' })
|
||||
client.get('/drive/list').then(() => {})
|
||||
|
||||
const provider = new Provider(uppy, {
|
||||
serverUrl: 'https://uppy.mywebsite.com/',
|
||||
companionUrl: 'https://uppy.mywebsite.com/',
|
||||
provider: providerPluginInstance
|
||||
})
|
||||
provider.checkAuth().then(() => {})
|
||||
|
|
|
|||
|
|
@ -74,19 +74,19 @@ module.exports = class Provider extends RequestClient {
|
|||
plugin.opts = Object.assign({}, defaultOpts, opts)
|
||||
}
|
||||
|
||||
if (opts.serverPattern) {
|
||||
const pattern = opts.serverPattern
|
||||
// validate serverPattern param
|
||||
if (opts.companionAllowedHosts) {
|
||||
const pattern = opts.companionAllowedHosts
|
||||
// validate companionAllowedHosts param
|
||||
if (typeof pattern !== 'string' && !Array.isArray(pattern) && !(pattern instanceof RegExp)) {
|
||||
throw new TypeError(`${plugin.id}: the option "serverPattern" must be one of string, Array, RegExp`)
|
||||
throw new TypeError(`${plugin.id}: the option "companionAllowedHosts" must be one of string, Array, RegExp`)
|
||||
}
|
||||
plugin.opts.serverPattern = pattern
|
||||
plugin.opts.companionAllowedHosts = pattern
|
||||
} else {
|
||||
// does not start with https://
|
||||
if (/^(?!https?:\/\/).*$/i.test(opts.serverUrl)) {
|
||||
plugin.opts.serverPattern = `https://${opts.serverUrl.replace(/^\/\//, '')}`
|
||||
if (/^(?!https?:\/\/).*$/i.test(opts.companionUrl)) {
|
||||
plugin.opts.companionAllowedHosts = `https://${opts.companionUrl.replace(/^\/\//, '')}`
|
||||
} else {
|
||||
plugin.opts.serverPattern = opts.serverUrl
|
||||
plugin.opts.companionAllowedHosts = opts.companionUrl
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ module.exports = class RequestClient {
|
|||
|
||||
get hostname () {
|
||||
const { companion } = this.uppy.getState()
|
||||
const host = this.opts.serverUrl
|
||||
const host = this.opts.companionUrl
|
||||
return stripSlash(companion && companion[host] ? companion[host] : host)
|
||||
}
|
||||
|
||||
|
|
@ -44,7 +44,7 @@ module.exports = class RequestClient {
|
|||
onReceiveResponse (response) {
|
||||
const state = this.uppy.getState()
|
||||
const companion = state.companion || {}
|
||||
const host = this.opts.serverUrl
|
||||
const host = this.opts.companionUrl
|
||||
const headers = response.headers
|
||||
// Store the self-identified domain name for the Companion instance we just hit.
|
||||
if (headers.has('i-am') && headers.get('i-am') !== companion[host]) {
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ const RequestClient = require('./RequestClient')
|
|||
describe('RequestClient', () => {
|
||||
it('has a hostname without trailing slash', () => {
|
||||
const mockCore = { getState: () => ({}) }
|
||||
const a = new RequestClient(mockCore, { serverUrl: 'http://companion.uppy.io' })
|
||||
const b = new RequestClient(mockCore, { serverUrl: 'http://companion.uppy.io/' })
|
||||
const a = new RequestClient(mockCore, { companionUrl: 'http://companion.uppy.io' })
|
||||
const b = new RequestClient(mockCore, { companionUrl: 'http://companion.uppy.io/' })
|
||||
|
||||
expect(a.hostname).toBe('http://companion.uppy.io')
|
||||
expect(b.hostname).toBe('http://companion.uppy.io')
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import Uppy = require('@uppy/core');
|
||||
|
||||
export interface RequestClientOptions {
|
||||
serverUrl: string;
|
||||
companionUrl: string;
|
||||
serverHeaders?: object;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ describe('Dashboard', () => {
|
|||
inline: true,
|
||||
target: 'body'
|
||||
})
|
||||
core.use(GoogleDrivePlugin, { target: DashboardPlugin, serverUrl: 'https://fake.uppy.io/' })
|
||||
core.use(GoogleDrivePlugin, { target: DashboardPlugin, companionUrl: 'https://fake.uppy.io/' })
|
||||
}).not.toThrow()
|
||||
|
||||
core.close()
|
||||
|
|
@ -43,7 +43,7 @@ describe('Dashboard', () => {
|
|||
|
||||
it('works when passing plugins in `plugins` array', () => {
|
||||
const core = new Core()
|
||||
core.use(GoogleDrivePlugin, { serverUrl: 'https://fake.uppy.io/' })
|
||||
core.use(GoogleDrivePlugin, { companionUrl: 'https://fake.uppy.io/' })
|
||||
|
||||
expect(() => {
|
||||
core.use(DashboardPlugin, {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ module.exports = class Dropbox extends Plugin {
|
|||
)
|
||||
|
||||
this.provider = new Provider(uppy, {
|
||||
serverUrl: this.opts.serverUrl,
|
||||
companionUrl: this.opts.companionUrl,
|
||||
serverHeaders: this.opts.serverHeaders,
|
||||
storage: this.opts.storage,
|
||||
provider: 'dropbox',
|
||||
|
|
|
|||
4
packages/@uppy/dropbox/types/index.d.ts
vendored
4
packages/@uppy/dropbox/types/index.d.ts
vendored
|
|
@ -3,8 +3,8 @@ import CompanionClient = require('@uppy/companion-client');
|
|||
|
||||
declare module Dropbox {
|
||||
interface DropboxOptions extends Uppy.PluginOptions, CompanionClient.ProviderOptions {
|
||||
serverUrl: string;
|
||||
serverPattern: string | RegExp | Array<string | RegExp>;
|
||||
companionUrl: string;
|
||||
companionAllowedHosts: string | RegExp | Array<string | RegExp>;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ module.exports = class GoogleDrive extends Plugin {
|
|||
)
|
||||
|
||||
this.provider = new Provider(uppy, {
|
||||
serverUrl: this.opts.serverUrl,
|
||||
companionUrl: this.opts.companionUrl,
|
||||
serverHeaders: this.opts.serverHeaders,
|
||||
storage: this.opts.storage,
|
||||
provider: 'drive',
|
||||
|
|
|
|||
4
packages/@uppy/google-drive/types/index.d.ts
vendored
4
packages/@uppy/google-drive/types/index.d.ts
vendored
|
|
@ -3,8 +3,8 @@ import CompanionClient = require('@uppy/companion-client');
|
|||
|
||||
declare module GoogleDrive {
|
||||
interface GoogleDriveOptions extends Uppy.PluginOptions, CompanionClient.ProviderOptions {
|
||||
serverUrl: string;
|
||||
serverPattern: string | RegExp | Array<string | RegExp>;
|
||||
companionUrl: string;
|
||||
companionAllowedHosts: string | RegExp | Array<string | RegExp>;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ module.exports = class Instagram extends Plugin {
|
|||
)
|
||||
|
||||
this.provider = new Provider(uppy, {
|
||||
serverUrl: this.opts.serverUrl,
|
||||
companionUrl: this.opts.companionUrl,
|
||||
serverHeaders: this.opts.serverHeaders,
|
||||
storage: this.opts.storage,
|
||||
provider: 'instagram',
|
||||
|
|
|
|||
4
packages/@uppy/instagram/types/index.d.ts
vendored
4
packages/@uppy/instagram/types/index.d.ts
vendored
|
|
@ -3,8 +3,8 @@ import CompanionClient = require('@uppy/companion-client');
|
|||
|
||||
declare module Instagram {
|
||||
interface InstagramOptions extends Uppy.PluginOptions, CompanionClient.ProviderOptions {
|
||||
serverUrl: string;
|
||||
serverPattern: string | RegExp | Array<string | RegExp>;
|
||||
companionUrl: string;
|
||||
companionAllowedHosts: string | RegExp | Array<string | RegExp>;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ module.exports = class ProviderView {
|
|||
fileId: file.id
|
||||
},
|
||||
remote: {
|
||||
serverUrl: this.plugin.opts.serverUrl,
|
||||
companionUrl: this.plugin.opts.companionUrl,
|
||||
url: `${this.provider.fileUrl(file.requestPath)}`,
|
||||
body: {
|
||||
fileId: file.id
|
||||
|
|
@ -423,8 +423,8 @@ module.exports = class ProviderView {
|
|||
|
||||
const authWindow = window.open(link, '_blank')
|
||||
const handleToken = (e) => {
|
||||
if (!this._isOriginAllowed(e.origin, this.plugin.opts.serverPattern) || e.source !== authWindow) {
|
||||
this.plugin.uppy.log(`rejecting event from ${e.origin} vs allowed pattern ${this.plugin.opts.serverPattern}`)
|
||||
if (!this._isOriginAllowed(e.origin, this.plugin.opts.companionAllowedHosts) || e.source !== authWindow) {
|
||||
this.plugin.uppy.log(`rejecting event from ${e.origin} vs allowed pattern ${this.plugin.opts.companionAllowedHosts}`)
|
||||
return
|
||||
}
|
||||
authWindow.close()
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ const localProviders = {
|
|||
}
|
||||
|
||||
const remoteProviderOptionNames = [
|
||||
'serverUrl',
|
||||
'serverPattern',
|
||||
'companionUrl',
|
||||
'companionAllowedHosts',
|
||||
'serverHeaders',
|
||||
'target'
|
||||
]
|
||||
|
|
@ -27,8 +27,8 @@ function addRemoteProvider (uppy, name, opts) {
|
|||
const Provider = remoteProviders[name]
|
||||
const providerOptions = {
|
||||
// Default to the :tl: Companion servers.
|
||||
serverUrl: Transloadit.COMPANION,
|
||||
serverPattern: Transloadit.COMPANION_PATTERN
|
||||
companionUrl: Transloadit.COMPANION,
|
||||
companionAllowedHosts: Transloadit.COMPANION_PATTERN
|
||||
}
|
||||
|
||||
remoteProviderOptionNames.forEach((name) => {
|
||||
|
|
|
|||
|
|
@ -113,10 +113,10 @@ module.exports = class Transloadit extends Plugin {
|
|||
// We only replace the hostname for Transloadit's companions, so that
|
||||
// people can also self-host them while still using Transloadit for encoding.
|
||||
let remote = file.remote
|
||||
if (file.remote && TL_UPPY_SERVER.test(file.remote.serverUrl)) {
|
||||
if (file.remote && TL_UPPY_SERVER.test(file.remote.companionUrl)) {
|
||||
const err = new Error(
|
||||
'The https://api2.transloadit.com/uppy-server endpoint was renamed to ' +
|
||||
'https://api2.transloadit.com/companion, please update your `serverUrl` ' +
|
||||
'https://api2.transloadit.com/companion, please update your `companionUrl` ' +
|
||||
'options accordingly.')
|
||||
// Explicitly log this error here because it is caught by the `createAssembly`
|
||||
// Promise further along.
|
||||
|
|
@ -126,16 +126,16 @@ module.exports = class Transloadit extends Plugin {
|
|||
throw err
|
||||
}
|
||||
|
||||
if (file.remote && TL_COMPANION.test(file.remote.serverUrl)) {
|
||||
if (file.remote && TL_COMPANION.test(file.remote.companionUrl)) {
|
||||
const newHost = status.companion_url
|
||||
.replace(/\/$/, '')
|
||||
const path = file.remote.url
|
||||
.replace(file.remote.serverUrl, '')
|
||||
.replace(file.remote.companionUrl, '')
|
||||
.replace(/^\//, '')
|
||||
|
||||
remote = {
|
||||
...file.remote,
|
||||
serverUrl: newHost,
|
||||
companionUrl: newHost,
|
||||
url: `${newHost}/${path}`
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -271,7 +271,7 @@ module.exports = class Tus extends Plugin {
|
|||
connectToServerSocket (file) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const token = file.serverToken
|
||||
const host = getSocketHost(file.remote.serverUrl)
|
||||
const host = getSocketHost(file.remote.companionUrl)
|
||||
const socket = new Socket({ target: `${host}/api/${token}` })
|
||||
this.uploaderSockets[file.id] = socket
|
||||
this.uploaderEvents[file.id] = createEventTracker(this.uppy)
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ module.exports = class Url extends Plugin {
|
|||
this.i18n = this.translator.translate.bind(this.translator)
|
||||
this.i18nArray = this.translator.translateArray.bind(this.translator)
|
||||
|
||||
this.hostname = this.opts.serverUrl
|
||||
this.hostname = this.opts.companionUrl
|
||||
|
||||
if (!this.hostname) {
|
||||
throw new Error('Companion hostname is required, please consult https://uppy.io/docs/companion')
|
||||
|
|
@ -56,7 +56,7 @@ module.exports = class Url extends Plugin {
|
|||
this.handlePaste = this.handlePaste.bind(this)
|
||||
|
||||
this.client = new RequestClient(uppy, {
|
||||
serverUrl: this.opts.serverUrl,
|
||||
companionUrl: this.opts.companionUrl,
|
||||
serverHeaders: this.opts.serverHeaders
|
||||
})
|
||||
}
|
||||
|
|
@ -120,7 +120,7 @@ module.exports = class Url extends Plugin {
|
|||
url: url
|
||||
},
|
||||
remote: {
|
||||
serverUrl: this.opts.serverUrl,
|
||||
companionUrl: this.opts.companionUrl,
|
||||
url: `${this.hostname}/url/get`,
|
||||
body: {
|
||||
fileId: url,
|
||||
|
|
|
|||
2
packages/@uppy/url/types/index.d.ts
vendored
2
packages/@uppy/url/types/index.d.ts
vendored
|
|
@ -2,7 +2,7 @@ import Uppy = require('@uppy/core');
|
|||
|
||||
declare module Url {
|
||||
export interface UrlOptions extends Uppy.PluginOptions {
|
||||
serverUrl: string;
|
||||
companionUrl: string;
|
||||
// TODO inherit from ProviderOptions
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -333,7 +333,7 @@ module.exports = class XHRUpload extends Plugin {
|
|||
)
|
||||
.then((res) => {
|
||||
const token = res.token
|
||||
const host = getSocketHost(file.remote.serverUrl)
|
||||
const host = getSocketHost(file.remote.companionUrl)
|
||||
const socket = new Socket({ target: `${host}/api/${token}` })
|
||||
|
||||
socket.on('progress', (progressData) => emitSocketProgress(this, progressData, file))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue