From 3908c8faa7815cebd51bcfa9d2a82d998cb89b0b Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Thu, 6 Jul 2023 16:21:21 +0200 Subject: [PATCH 1/6] @uppy/companion-client,@uppy/provider-views: make authentication optional in ProviderView --- packages/@uppy/companion-client/src/Provider.js | 4 ++++ .../@uppy/provider-views/src/ProviderView/ProviderView.jsx | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/packages/@uppy/companion-client/src/Provider.js b/packages/@uppy/companion-client/src/Provider.js index 081f3cdc65..e09e1147af 100644 --- a/packages/@uppy/companion-client/src/Provider.js +++ b/packages/@uppy/companion-client/src/Provider.js @@ -19,6 +19,7 @@ export default class Provider extends RequestClient { this.tokenKey = `companion-${this.pluginId}-auth-token` this.companionKeysParams = this.opts.companionKeysParams this.preAuthToken = null + this.authentication = opts.authentication ?? true } async headers () { @@ -136,6 +137,9 @@ export default class Provider extends RequestClient { } async logout (options) { + if (!this.authentication) { + return Promise.resolve({ ok: true, revoked: true }) + } const response = await this.get(`${this.id}/logout`, options) await this.#removeAuthToken() return response diff --git a/packages/@uppy/provider-views/src/ProviderView/ProviderView.jsx b/packages/@uppy/provider-views/src/ProviderView/ProviderView.jsx index c4ccfccbf6..c1c8df4741 100644 --- a/packages/@uppy/provider-views/src/ProviderView/ProviderView.jsx +++ b/packages/@uppy/provider-views/src/ProviderView/ProviderView.jsx @@ -254,6 +254,12 @@ export default class ProviderView extends View { } async handleAuth () { + if (!this.provider.authentication) { + this.plugin.setPluginState({ authenticated: true }) + this.preFirstRender() + return + } + await this.provider.ensurePreAuth() const authState = btoa(JSON.stringify({ origin: getOrigin() })) From c5a43718eee401e57b17eb0cd9988c6e14c3748e Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Wed, 12 Jul 2023 00:27:16 +0200 Subject: [PATCH 2/6] try different approach --- .../@uppy/companion-client/src/Provider.js | 69 +++++++++++++++++-- .../src/ProviderView/ProviderView.jsx | 66 ++---------------- 2 files changed, 69 insertions(+), 66 deletions(-) diff --git a/packages/@uppy/companion-client/src/Provider.js b/packages/@uppy/companion-client/src/Provider.js index e09e1147af..3fa017ff57 100644 --- a/packages/@uppy/companion-client/src/Provider.js +++ b/packages/@uppy/companion-client/src/Provider.js @@ -7,6 +7,26 @@ const getName = (id) => { return id.split('-').map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join(' ') } +function getOrigin () { + // eslint-disable-next-line no-restricted-globals + return location.origin +} + +function getRegex (value) { + if (typeof value === 'string') { + return new RegExp(`^${value}$`) + } if (value instanceof RegExp) { + return value + } + return undefined +} + +function isOriginAllowed (origin, allowedOrigin) { + const patterns = Array.isArray(allowedOrigin) ? allowedOrigin.map(getRegex) : [getRegex(allowedOrigin)] + return patterns + .some((pattern) => pattern?.test(origin) || pattern?.test(`${origin}/`)) // allowing for trailing '/' +} + export default class Provider extends RequestClient { #refreshingTokenPromise @@ -19,7 +39,6 @@ export default class Provider extends RequestClient { this.tokenKey = `companion-${this.pluginId}-auth-token` this.companionKeysParams = this.opts.companionKeysParams this.preAuthToken = null - this.authentication = opts.authentication ?? true } async headers () { @@ -73,7 +92,10 @@ export default class Provider extends RequestClient { } authUrl (queries = {}) { - const params = new URLSearchParams(queries) + const params = new URLSearchParams({ + state: btoa(JSON.stringify({ origin: getOrigin() })), + ...queries, + }) if (this.preAuthToken) { params.set('uppyPreAuthToken', this.preAuthToken) } @@ -81,6 +103,46 @@ export default class Provider extends RequestClient { return `${this.hostname}/${this.id}/connect?${params}` } + async login (queries) { + await this.ensurePreAuth() + + return new Promise((resolve, reject) => { + const link = this.authUrl(queries) + const authWindow = window.open(link, '_blank') + const handleToken = (e) => { + if (e.source !== authWindow) { + reject(new Error('rejecting event from unknown source')) + } + + const { companionAllowedHosts } = this.uppy.getPlugin(this.pluginId).opts + if (!isOriginAllowed(e.origin, companionAllowedHosts) || e.source !== authWindow) { + reject(new Error(`rejecting event from ${e.origin} vs allowed pattern ${companionAllowedHosts}`)) + } + + // Check if it's a string before doing the JSON.parse to maintain support + // for older Companion versions that used object references + const data = typeof e.data === 'string' ? JSON.parse(e.data) : e.data + + if (data.error) { + const { uppy } = this + const message = uppy.i18n('authAborted') + uppy.info({ message }, 'warning', 5000) + reject(new Error('auth aborted')) + } + + if (!data.token) { + reject(new Error('did not receive token from auth window')) + } + + authWindow.close() + window.removeEventListener('message', handleToken) + this.setAuthToken(data.token) + resolve() + } + window.addEventListener('message', handleToken) + }) + } + refreshTokenUrl () { return `${this.hostname}/${this.id}/refresh-token` } @@ -137,9 +199,6 @@ export default class Provider extends RequestClient { } async logout (options) { - if (!this.authentication) { - return Promise.resolve({ ok: true, revoked: true }) - } const response = await this.get(`${this.id}/logout`, options) await this.#removeAuthToken() return response diff --git a/packages/@uppy/provider-views/src/ProviderView/ProviderView.jsx b/packages/@uppy/provider-views/src/ProviderView/ProviderView.jsx index c1c8df4741..5a96f893fd 100644 --- a/packages/@uppy/provider-views/src/ProviderView/ProviderView.jsx +++ b/packages/@uppy/provider-views/src/ProviderView/ProviderView.jsx @@ -13,25 +13,6 @@ import View from '../View.js' import packageJson from '../../package.json' -function getOrigin () { - // eslint-disable-next-line no-restricted-globals - return location.origin -} - -function getRegex (value) { - if (typeof value === 'string') { - return new RegExp(`^${value}$`) - } if (value instanceof RegExp) { - return value - } - return undefined -} -function isOriginAllowed (origin, allowedOrigin) { - const patterns = Array.isArray(allowedOrigin) ? allowedOrigin.map(getRegex) : [getRegex(allowedOrigin)] - return patterns - .some((pattern) => pattern?.test(origin) || pattern?.test(`${origin}/`)) // allowing for trailing '/' -} - function formatBreadcrumbs (breadcrumbs) { return breadcrumbs.slice(1).map((directory) => directory.name).join('/') } @@ -254,51 +235,14 @@ export default class ProviderView extends View { } async handleAuth () { - if (!this.provider.authentication) { - this.plugin.setPluginState({ authenticated: true }) - this.preFirstRender() - return - } - - await this.provider.ensurePreAuth() - - const authState = btoa(JSON.stringify({ origin: getOrigin() })) const clientVersion = `@uppy/provider-views=${ProviderView.VERSION}` - const link = this.provider.authUrl({ state: authState, uppyVersions: clientVersion }) - - const authWindow = window.open(link, '_blank') - const handleToken = (e) => { - if (e.source !== authWindow) { - this.plugin.uppy.log('rejecting event from unknown source') - return - } - if (!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}`) - } - - // Check if it's a string before doing the JSON.parse to maintain support - // for older Companion versions that used object references - const data = typeof e.data === 'string' ? JSON.parse(e.data) : e.data - - if (data.error) { - this.plugin.uppy.log('auth aborted', 'warning') - const { uppy } = this.plugin - const message = uppy.i18n('authAborted') - uppy.info({ message }, 'warning', 5000) - return - } - - if (!data.token) { - this.plugin.uppy.log('did not receive token from auth window', 'error') - return - } - - authWindow.close() - window.removeEventListener('message', handleToken) - this.provider.setAuthToken(data.token) + try { + await this.provider.login({ uppyVersions: clientVersion }) + this.plugin.setPluginState({ authenticated: true }) this.preFirstRender() + } catch (e) { + this.plugin.uppy.log(`login failed: ${e.message}`) } - window.addEventListener('message', handleToken) } async handleScroll (event) { From ce7f90e455847c4d16a50dd0b07d2b70d47a3e7c Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Tue, 1 Aug 2023 12:22:33 +0200 Subject: [PATCH 3/6] Move authAborted translation to companion-client --- packages/@uppy/box/src/Box.jsx | 2 +- packages/@uppy/companion-client/src/Provider.js | 9 ++++++--- packages/@uppy/companion-client/src/locale.js | 5 +++++ packages/@uppy/core/src/BasePlugin.js | 6 +++++- packages/@uppy/core/src/Uppy.js | 5 ++++- packages/@uppy/core/src/locale.js | 1 - packages/@uppy/dropbox/src/Dropbox.jsx | 2 +- packages/@uppy/facebook/src/Facebook.jsx | 2 +- packages/@uppy/google-drive/src/GoogleDrive.jsx | 2 +- packages/@uppy/instagram/src/Instagram.jsx | 10 +++++----- packages/@uppy/onedrive/src/OneDrive.jsx | 2 +- packages/@uppy/zoom/src/Zoom.jsx | 2 +- 12 files changed, 31 insertions(+), 17 deletions(-) create mode 100644 packages/@uppy/companion-client/src/locale.js diff --git a/packages/@uppy/box/src/Box.jsx b/packages/@uppy/box/src/Box.jsx index 93a202a1db..087ba8ade9 100644 --- a/packages/@uppy/box/src/Box.jsx +++ b/packages/@uppy/box/src/Box.jsx @@ -32,7 +32,7 @@ export default class Box extends UIPlugin { pluginId: this.id, }) - this.defaultLocale = locale + this.defaultLocale = [this.provider.defaultLocale, locale] this.i18nInit() this.title = this.i18n('pluginNameBox') diff --git a/packages/@uppy/companion-client/src/Provider.js b/packages/@uppy/companion-client/src/Provider.js index 3fa017ff57..2d109b5ea7 100644 --- a/packages/@uppy/companion-client/src/Provider.js +++ b/packages/@uppy/companion-client/src/Provider.js @@ -2,6 +2,7 @@ import RequestClient from './RequestClient.js' import * as tokenStorage from './tokenStorage.js' +import locale from './locale.js' const getName = (id) => { return id.split('-').map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join(' ') @@ -39,6 +40,8 @@ export default class Provider extends RequestClient { this.tokenKey = `companion-${this.pluginId}-auth-token` this.companionKeysParams = this.opts.companionKeysParams this.preAuthToken = null + + this.defaultLocale = locale } async headers () { @@ -124,9 +127,9 @@ export default class Provider extends RequestClient { const data = typeof e.data === 'string' ? JSON.parse(e.data) : e.data if (data.error) { - const { uppy } = this - const message = uppy.i18n('authAborted') - uppy.info({ message }, 'warning', 5000) + const { i18n } = this.uppy.getPlugin(this.pluginId) + const message = i18n('authAborted') + this.uppy.info({ message }, 'warning', 5000) reject(new Error('auth aborted')) } diff --git a/packages/@uppy/companion-client/src/locale.js b/packages/@uppy/companion-client/src/locale.js new file mode 100644 index 0000000000..23392e5469 --- /dev/null +++ b/packages/@uppy/companion-client/src/locale.js @@ -0,0 +1,5 @@ +export default { + strings: { + authAborted: 'Authentication aborted', + }, +} diff --git a/packages/@uppy/core/src/BasePlugin.js b/packages/@uppy/core/src/BasePlugin.js index c802f97b74..e03b1450f4 100644 --- a/packages/@uppy/core/src/BasePlugin.js +++ b/packages/@uppy/core/src/BasePlugin.js @@ -41,7 +41,11 @@ export default class BasePlugin { } i18nInit () { - const translator = new Translator([this.defaultLocale, this.uppy.locale, this.opts.locale]) + const translator = new Translator([ + ...(Array.isArray(this.defaultLocale) ? this.defaultLocale : [this.defaultLocale]), + this.uppy.locale, + this.opts.locale, + ]) this.i18n = translator.translate.bind(translator) this.i18nArray = translator.translateArray.bind(translator) this.setPluginState() // so that UI re-renders and we see the updated locale diff --git a/packages/@uppy/core/src/Uppy.js b/packages/@uppy/core/src/Uppy.js index c597c97efb..fdc26ceaf1 100644 --- a/packages/@uppy/core/src/Uppy.js +++ b/packages/@uppy/core/src/Uppy.js @@ -198,7 +198,10 @@ class Uppy { } i18nInit () { - const translator = new Translator([this.defaultLocale, this.opts.locale]) + const translator = new Translator([ + ...(Array.isArray(this.defaultLocale) ? this.defaultLocale : [this.defaultLocale]), + this.opts.locale, + ]) this.i18n = translator.translate.bind(translator) this.i18nArray = translator.translateArray.bind(translator) this.locale = translator.locale diff --git a/packages/@uppy/core/src/locale.js b/packages/@uppy/core/src/locale.js index 16a18cf3a4..9a43be62fa 100644 --- a/packages/@uppy/core/src/locale.js +++ b/packages/@uppy/core/src/locale.js @@ -22,7 +22,6 @@ export default { noDuplicates: "Cannot add the duplicate file '%{fileName}', it already exists", companionError: 'Connection with Companion failed', - authAborted: 'Authentication aborted', companionUnauthorizeHint: 'To unauthorize to your %{provider} account, please go to %{url}', failedToUpload: 'Failed to upload %{file}', diff --git a/packages/@uppy/dropbox/src/Dropbox.jsx b/packages/@uppy/dropbox/src/Dropbox.jsx index c591933087..fad309939f 100644 --- a/packages/@uppy/dropbox/src/Dropbox.jsx +++ b/packages/@uppy/dropbox/src/Dropbox.jsx @@ -29,7 +29,7 @@ export default class Dropbox extends UIPlugin { pluginId: this.id, }) - this.defaultLocale = locale + this.defaultLocale = [this.provider.defaultLocale, locale] this.i18nInit() this.title = this.i18n('pluginNameDropbox') diff --git a/packages/@uppy/facebook/src/Facebook.jsx b/packages/@uppy/facebook/src/Facebook.jsx index f8ceac492e..e0eeaf0f23 100644 --- a/packages/@uppy/facebook/src/Facebook.jsx +++ b/packages/@uppy/facebook/src/Facebook.jsx @@ -32,7 +32,7 @@ export default class Facebook extends UIPlugin { pluginId: this.id, }) - this.defaultLocale = locale + this.defaultLocale = [this.provider.defaultLocale, locale] this.i18nInit() this.title = this.i18n('pluginNameFacebook') diff --git a/packages/@uppy/google-drive/src/GoogleDrive.jsx b/packages/@uppy/google-drive/src/GoogleDrive.jsx index 96433c33ef..381dca7c28 100644 --- a/packages/@uppy/google-drive/src/GoogleDrive.jsx +++ b/packages/@uppy/google-drive/src/GoogleDrive.jsx @@ -43,7 +43,7 @@ export default class GoogleDrive extends UIPlugin { pluginId: this.id, }) - this.defaultLocale = locale + this.defaultLocale = [this.provider.defaultLocale, locale] this.i18nInit() this.title = this.i18n('pluginNameGoogleDrive') diff --git a/packages/@uppy/instagram/src/Instagram.jsx b/packages/@uppy/instagram/src/Instagram.jsx index 7ba14fd33e..850b987ba4 100644 --- a/packages/@uppy/instagram/src/Instagram.jsx +++ b/packages/@uppy/instagram/src/Instagram.jsx @@ -28,11 +28,6 @@ export default class Instagram extends UIPlugin { ) - this.defaultLocale = locale - - this.i18nInit() - this.title = this.i18n('pluginNameInstagram') - this.provider = new Provider(uppy, { companionUrl: this.opts.companionUrl, companionHeaders: this.opts.companionHeaders, @@ -42,6 +37,11 @@ export default class Instagram extends UIPlugin { pluginId: this.id, }) + this.defaultLocale = [this.provider.defaultLocale, locale] + + this.i18nInit() + this.title = this.i18n('pluginNameInstagram') + this.onFirstRender = this.onFirstRender.bind(this) this.render = this.render.bind(this) } diff --git a/packages/@uppy/onedrive/src/OneDrive.jsx b/packages/@uppy/onedrive/src/OneDrive.jsx index 6f4b939f56..d8548aceb2 100644 --- a/packages/@uppy/onedrive/src/OneDrive.jsx +++ b/packages/@uppy/onedrive/src/OneDrive.jsx @@ -34,7 +34,7 @@ export default class OneDrive extends UIPlugin { pluginId: this.id, }) - this.defaultLocale = locale + this.defaultLocale = [this.provider.defaultLocale, locale] this.i18nInit() this.title = this.i18n('pluginNameOneDrive') diff --git a/packages/@uppy/zoom/src/Zoom.jsx b/packages/@uppy/zoom/src/Zoom.jsx index c7c3d392ba..2b0af4bb70 100644 --- a/packages/@uppy/zoom/src/Zoom.jsx +++ b/packages/@uppy/zoom/src/Zoom.jsx @@ -30,7 +30,7 @@ export default class Zoom extends UIPlugin { pluginId: this.id, }) - this.defaultLocale = locale + this.defaultLocale = [this.provider.defaultLocale, locale] this.i18nInit() this.title = this.i18n('pluginNameZoom') From 28888473822b46d2b68d83acd40e6b6f538505ce Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Wed, 2 Aug 2023 09:55:37 +0200 Subject: [PATCH 4/6] @uppy/companion-client: do not reject login promise on events from incorrect source, but always return after rejections While these events should be ignored they might be unrelated and should not reject the whole login --- packages/@uppy/companion-client/src/Provider.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/@uppy/companion-client/src/Provider.js b/packages/@uppy/companion-client/src/Provider.js index 2d109b5ea7..fd0dc18094 100644 --- a/packages/@uppy/companion-client/src/Provider.js +++ b/packages/@uppy/companion-client/src/Provider.js @@ -114,12 +114,14 @@ export default class Provider extends RequestClient { const authWindow = window.open(link, '_blank') const handleToken = (e) => { if (e.source !== authWindow) { - reject(new Error('rejecting event from unknown source')) + this.uppy.log.warn('ignoring event from unknown source', e) + return } const { companionAllowedHosts } = this.uppy.getPlugin(this.pluginId).opts - if (!isOriginAllowed(e.origin, companionAllowedHosts) || e.source !== authWindow) { + if (!isOriginAllowed(e.origin, companionAllowedHosts)) { reject(new Error(`rejecting event from ${e.origin} vs allowed pattern ${companionAllowedHosts}`)) + return } // Check if it's a string before doing the JSON.parse to maintain support @@ -131,10 +133,12 @@ export default class Provider extends RequestClient { const message = i18n('authAborted') this.uppy.info({ message }, 'warning', 5000) reject(new Error('auth aborted')) + return } if (!data.token) { reject(new Error('did not receive token from auth window')) + return } authWindow.close() From 5f24e5cda7a95401f1362c145a2a5b9f7f481937 Mon Sep 17 00:00:00 2001 From: Murderlon Date: Thu, 3 Aug 2023 15:27:20 +0200 Subject: [PATCH 5/6] Revert "Move authAborted translation to companion-client" This reverts commit ce7f90e455847c4d16a50dd0b07d2b70d47a3e7c. --- packages/@uppy/box/src/Box.jsx | 2 +- packages/@uppy/companion-client/src/Provider.js | 9 +++------ packages/@uppy/companion-client/src/locale.js | 5 ----- packages/@uppy/core/src/BasePlugin.js | 6 +----- packages/@uppy/core/src/Uppy.js | 5 +---- packages/@uppy/core/src/locale.js | 1 + packages/@uppy/dropbox/src/Dropbox.jsx | 2 +- packages/@uppy/facebook/src/Facebook.jsx | 2 +- packages/@uppy/google-drive/src/GoogleDrive.jsx | 2 +- packages/@uppy/instagram/src/Instagram.jsx | 10 +++++----- packages/@uppy/onedrive/src/OneDrive.jsx | 2 +- packages/@uppy/zoom/src/Zoom.jsx | 2 +- 12 files changed, 17 insertions(+), 31 deletions(-) delete mode 100644 packages/@uppy/companion-client/src/locale.js diff --git a/packages/@uppy/box/src/Box.jsx b/packages/@uppy/box/src/Box.jsx index 087ba8ade9..93a202a1db 100644 --- a/packages/@uppy/box/src/Box.jsx +++ b/packages/@uppy/box/src/Box.jsx @@ -32,7 +32,7 @@ export default class Box extends UIPlugin { pluginId: this.id, }) - this.defaultLocale = [this.provider.defaultLocale, locale] + this.defaultLocale = locale this.i18nInit() this.title = this.i18n('pluginNameBox') diff --git a/packages/@uppy/companion-client/src/Provider.js b/packages/@uppy/companion-client/src/Provider.js index fd0dc18094..41790b13f3 100644 --- a/packages/@uppy/companion-client/src/Provider.js +++ b/packages/@uppy/companion-client/src/Provider.js @@ -2,7 +2,6 @@ import RequestClient from './RequestClient.js' import * as tokenStorage from './tokenStorage.js' -import locale from './locale.js' const getName = (id) => { return id.split('-').map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join(' ') @@ -40,8 +39,6 @@ export default class Provider extends RequestClient { this.tokenKey = `companion-${this.pluginId}-auth-token` this.companionKeysParams = this.opts.companionKeysParams this.preAuthToken = null - - this.defaultLocale = locale } async headers () { @@ -129,9 +126,9 @@ export default class Provider extends RequestClient { const data = typeof e.data === 'string' ? JSON.parse(e.data) : e.data if (data.error) { - const { i18n } = this.uppy.getPlugin(this.pluginId) - const message = i18n('authAborted') - this.uppy.info({ message }, 'warning', 5000) + const { uppy } = this + const message = uppy.i18n('authAborted') + uppy.info({ message }, 'warning', 5000) reject(new Error('auth aborted')) return } diff --git a/packages/@uppy/companion-client/src/locale.js b/packages/@uppy/companion-client/src/locale.js deleted file mode 100644 index 23392e5469..0000000000 --- a/packages/@uppy/companion-client/src/locale.js +++ /dev/null @@ -1,5 +0,0 @@ -export default { - strings: { - authAborted: 'Authentication aborted', - }, -} diff --git a/packages/@uppy/core/src/BasePlugin.js b/packages/@uppy/core/src/BasePlugin.js index e03b1450f4..c802f97b74 100644 --- a/packages/@uppy/core/src/BasePlugin.js +++ b/packages/@uppy/core/src/BasePlugin.js @@ -41,11 +41,7 @@ export default class BasePlugin { } i18nInit () { - const translator = new Translator([ - ...(Array.isArray(this.defaultLocale) ? this.defaultLocale : [this.defaultLocale]), - this.uppy.locale, - this.opts.locale, - ]) + const translator = new Translator([this.defaultLocale, this.uppy.locale, this.opts.locale]) this.i18n = translator.translate.bind(translator) this.i18nArray = translator.translateArray.bind(translator) this.setPluginState() // so that UI re-renders and we see the updated locale diff --git a/packages/@uppy/core/src/Uppy.js b/packages/@uppy/core/src/Uppy.js index fdc26ceaf1..c597c97efb 100644 --- a/packages/@uppy/core/src/Uppy.js +++ b/packages/@uppy/core/src/Uppy.js @@ -198,10 +198,7 @@ class Uppy { } i18nInit () { - const translator = new Translator([ - ...(Array.isArray(this.defaultLocale) ? this.defaultLocale : [this.defaultLocale]), - this.opts.locale, - ]) + const translator = new Translator([this.defaultLocale, this.opts.locale]) this.i18n = translator.translate.bind(translator) this.i18nArray = translator.translateArray.bind(translator) this.locale = translator.locale diff --git a/packages/@uppy/core/src/locale.js b/packages/@uppy/core/src/locale.js index 9a43be62fa..16a18cf3a4 100644 --- a/packages/@uppy/core/src/locale.js +++ b/packages/@uppy/core/src/locale.js @@ -22,6 +22,7 @@ export default { noDuplicates: "Cannot add the duplicate file '%{fileName}', it already exists", companionError: 'Connection with Companion failed', + authAborted: 'Authentication aborted', companionUnauthorizeHint: 'To unauthorize to your %{provider} account, please go to %{url}', failedToUpload: 'Failed to upload %{file}', diff --git a/packages/@uppy/dropbox/src/Dropbox.jsx b/packages/@uppy/dropbox/src/Dropbox.jsx index fad309939f..c591933087 100644 --- a/packages/@uppy/dropbox/src/Dropbox.jsx +++ b/packages/@uppy/dropbox/src/Dropbox.jsx @@ -29,7 +29,7 @@ export default class Dropbox extends UIPlugin { pluginId: this.id, }) - this.defaultLocale = [this.provider.defaultLocale, locale] + this.defaultLocale = locale this.i18nInit() this.title = this.i18n('pluginNameDropbox') diff --git a/packages/@uppy/facebook/src/Facebook.jsx b/packages/@uppy/facebook/src/Facebook.jsx index e0eeaf0f23..f8ceac492e 100644 --- a/packages/@uppy/facebook/src/Facebook.jsx +++ b/packages/@uppy/facebook/src/Facebook.jsx @@ -32,7 +32,7 @@ export default class Facebook extends UIPlugin { pluginId: this.id, }) - this.defaultLocale = [this.provider.defaultLocale, locale] + this.defaultLocale = locale this.i18nInit() this.title = this.i18n('pluginNameFacebook') diff --git a/packages/@uppy/google-drive/src/GoogleDrive.jsx b/packages/@uppy/google-drive/src/GoogleDrive.jsx index 381dca7c28..96433c33ef 100644 --- a/packages/@uppy/google-drive/src/GoogleDrive.jsx +++ b/packages/@uppy/google-drive/src/GoogleDrive.jsx @@ -43,7 +43,7 @@ export default class GoogleDrive extends UIPlugin { pluginId: this.id, }) - this.defaultLocale = [this.provider.defaultLocale, locale] + this.defaultLocale = locale this.i18nInit() this.title = this.i18n('pluginNameGoogleDrive') diff --git a/packages/@uppy/instagram/src/Instagram.jsx b/packages/@uppy/instagram/src/Instagram.jsx index 850b987ba4..7ba14fd33e 100644 --- a/packages/@uppy/instagram/src/Instagram.jsx +++ b/packages/@uppy/instagram/src/Instagram.jsx @@ -28,6 +28,11 @@ export default class Instagram extends UIPlugin { ) + this.defaultLocale = locale + + this.i18nInit() + this.title = this.i18n('pluginNameInstagram') + this.provider = new Provider(uppy, { companionUrl: this.opts.companionUrl, companionHeaders: this.opts.companionHeaders, @@ -37,11 +42,6 @@ export default class Instagram extends UIPlugin { pluginId: this.id, }) - this.defaultLocale = [this.provider.defaultLocale, locale] - - this.i18nInit() - this.title = this.i18n('pluginNameInstagram') - this.onFirstRender = this.onFirstRender.bind(this) this.render = this.render.bind(this) } diff --git a/packages/@uppy/onedrive/src/OneDrive.jsx b/packages/@uppy/onedrive/src/OneDrive.jsx index d8548aceb2..6f4b939f56 100644 --- a/packages/@uppy/onedrive/src/OneDrive.jsx +++ b/packages/@uppy/onedrive/src/OneDrive.jsx @@ -34,7 +34,7 @@ export default class OneDrive extends UIPlugin { pluginId: this.id, }) - this.defaultLocale = [this.provider.defaultLocale, locale] + this.defaultLocale = locale this.i18nInit() this.title = this.i18n('pluginNameOneDrive') diff --git a/packages/@uppy/zoom/src/Zoom.jsx b/packages/@uppy/zoom/src/Zoom.jsx index 2b0af4bb70..c7c3d392ba 100644 --- a/packages/@uppy/zoom/src/Zoom.jsx +++ b/packages/@uppy/zoom/src/Zoom.jsx @@ -30,7 +30,7 @@ export default class Zoom extends UIPlugin { pluginId: this.id, }) - this.defaultLocale = [this.provider.defaultLocale, locale] + this.defaultLocale = locale this.i18nInit() this.title = this.i18n('pluginNameZoom') From 993cedb41605f5389dbb81718eba8524ca63118b Mon Sep 17 00:00:00 2001 From: Murderlon Date: Thu, 3 Aug 2023 15:35:34 +0200 Subject: [PATCH 6/6] Check unused core locale strings in companion-client --- packages/@uppy/locales/src/en_US.js | 1 + private/locale-pack/test.mjs | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/@uppy/locales/src/en_US.js b/packages/@uppy/locales/src/en_US.js index 0970e6dede..b7a16db1cd 100644 --- a/packages/@uppy/locales/src/en_US.js +++ b/packages/@uppy/locales/src/en_US.js @@ -89,6 +89,7 @@ en_US.strings = { importFiles: 'Import files from:', importFrom: 'Import from %{name}', inferiorSize: 'This file is smaller than the allowed size of %{size}', + loadedXFiles: 'Loaded %{numFiles} files', loading: 'Loading...', logOut: 'Log out', micDisabled: 'Microphone access denied by user', diff --git a/private/locale-pack/test.mjs b/private/locale-pack/test.mjs index e525d824f5..885e4fb56e 100644 --- a/private/locale-pack/test.mjs +++ b/private/locale-pack/test.mjs @@ -13,7 +13,7 @@ const root = fileURLToPath(new URL('../../', import.meta.url)) const leadingLocaleName = 'en_US' const mode = process.argv[2] const pluginLocaleDependencies = { - core: 'provider-views', + core: ['provider-views', 'companion-client'], } function getAllFilesPerPlugin (pluginNames) { @@ -30,9 +30,9 @@ function getAllFilesPerPlugin (pluginNames) { filesPerPlugin[name] = getFiles(name) if (name in pluginLocaleDependencies) { - filesPerPlugin[name].push( - getFiles(pluginLocaleDependencies[name]), - ) + for (const subDeb of pluginLocaleDependencies[name]) { + filesPerPlugin[name].push(...getFiles(subDeb)) + } } }