From 3bc076f6aa9f55933d43d7845db47eeba21b5598 Mon Sep 17 00:00:00 2001 From: Brad Edelman Date: Wed, 25 May 2022 20:13:13 -0700 Subject: [PATCH 1/8] Update Url.jsx Uppy Url is great! Thank you. For my use case, I need to be able to pass thru some meta data with the File, in addition to the URL. Harmless to make it optional, but very useful to have it. Without it, I had to copy/paste the code in addFile to add it externally, since there's no intermediate opportunity to add data before uppy.addFile gets called. --- packages/@uppy/url/src/Url.jsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/@uppy/url/src/Url.jsx b/packages/@uppy/url/src/Url.jsx index c5551123f6..821fe769e3 100644 --- a/packages/@uppy/url/src/Url.jsx +++ b/packages/@uppy/url/src/Url.jsx @@ -104,7 +104,7 @@ export default class Url extends UIPlugin { }) } - async addFile (protocollessUrl) { + async addFile (protocollessUrl, optionalMeta = undefined) { const url = this.addProtocolToURL(protocollessUrl) if (!this.checkIfCorrectURL(url)) { this.uppy.log(`[URL] Incorrect URL entered: ${url}`) @@ -116,6 +116,7 @@ export default class Url extends UIPlugin { const meta = await this.getMeta(url) const tagFile = { + meta: optionalMeta, source: this.id, name: this.getFileNameFromUrl(url), type: meta.type, From ee58342ece8bc31990629cc854807c7b0d61b902 Mon Sep 17 00:00:00 2001 From: Brad Edelman Date: Wed, 25 May 2022 20:30:49 -0700 Subject: [PATCH 2/8] Update Url.jsx one more change - filenames need to have the query string/args stripped from the URL, if present --- packages/@uppy/url/src/Url.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@uppy/url/src/Url.jsx b/packages/@uppy/url/src/Url.jsx index 821fe769e3..1cd1017dc6 100644 --- a/packages/@uppy/url/src/Url.jsx +++ b/packages/@uppy/url/src/Url.jsx @@ -48,7 +48,7 @@ function checkIfCorrectURL (url) { } function getFileNameFromUrl (url) { - return url.substring(url.lastIndexOf('/') + 1) + return url.substring(url.lastIndexOf('/') + 1).split('?')[0], // make sure filename does not have query params in it } /** * Url From 3333ac81bf2e244d6252104bcbedbbe95817467c Mon Sep 17 00:00:00 2001 From: Brad Edelman Date: Thu, 26 May 2022 08:05:09 -0700 Subject: [PATCH 3/8] Update packages/@uppy/url/src/Url.jsx Co-authored-by: Antoine du Hamel --- packages/@uppy/url/src/Url.jsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/@uppy/url/src/Url.jsx b/packages/@uppy/url/src/Url.jsx index 1cd1017dc6..89e7fb73db 100644 --- a/packages/@uppy/url/src/Url.jsx +++ b/packages/@uppy/url/src/Url.jsx @@ -48,7 +48,9 @@ function checkIfCorrectURL (url) { } function getFileNameFromUrl (url) { - return url.substring(url.lastIndexOf('/') + 1).split('?')[0], // make sure filename does not have query params in it + const queryParamsIndexOf = url.indexOf('?') + const queryParamsStart = queryParamsIndexOf === -1 ? undefined : queryParamsIndexOf + return url.substring(url.lastIndexOf('/', queryParamsStart) + 1, queryParamsStart) } /** * Url From 4cd0a1e7c0acceb4228ed17e34d48b43e242821d Mon Sep 17 00:00:00 2001 From: Brad Edelman Date: Tue, 31 May 2022 09:26:37 -0700 Subject: [PATCH 4/8] Update packages/@uppy/url/src/Url.jsx Co-authored-by: Merlijn Vos --- packages/@uppy/url/src/Url.jsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/@uppy/url/src/Url.jsx b/packages/@uppy/url/src/Url.jsx index 89e7fb73db..00a4c84044 100644 --- a/packages/@uppy/url/src/Url.jsx +++ b/packages/@uppy/url/src/Url.jsx @@ -48,9 +48,8 @@ function checkIfCorrectURL (url) { } function getFileNameFromUrl (url) { - const queryParamsIndexOf = url.indexOf('?') - const queryParamsStart = queryParamsIndexOf === -1 ? undefined : queryParamsIndexOf - return url.substring(url.lastIndexOf('/', queryParamsStart) + 1, queryParamsStart) + const { pathname } = new URL(url) + return pathname.substring(pathname.lastIndexOf('/') + 1) } /** * Url From 3b6b75f9051161ad9fd4b144f2ae61d110c7ee5a Mon Sep 17 00:00:00 2001 From: Brad Edelman Date: Tue, 31 May 2022 20:17:43 -0700 Subject: [PATCH 5/8] Update Url.jsx getFileNameFromUrl change is now part of separate PR --- packages/@uppy/url/src/Url.jsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/@uppy/url/src/Url.jsx b/packages/@uppy/url/src/Url.jsx index 00a4c84044..821fe769e3 100644 --- a/packages/@uppy/url/src/Url.jsx +++ b/packages/@uppy/url/src/Url.jsx @@ -48,8 +48,7 @@ function checkIfCorrectURL (url) { } function getFileNameFromUrl (url) { - const { pathname } = new URL(url) - return pathname.substring(pathname.lastIndexOf('/') + 1) + return url.substring(url.lastIndexOf('/') + 1) } /** * Url From 633a033f306d506936818f621371a89142cb1383 Mon Sep 17 00:00:00 2001 From: Brad Edelman Date: Tue, 31 May 2022 20:20:57 -0700 Subject: [PATCH 6/8] Update index.d.ts --- packages/@uppy/url/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@uppy/url/types/index.d.ts b/packages/@uppy/url/types/index.d.ts index 5494abe291..8077511803 100644 --- a/packages/@uppy/url/types/index.d.ts +++ b/packages/@uppy/url/types/index.d.ts @@ -9,7 +9,7 @@ export interface UrlOptions extends PluginOptions, RequestClientOptions { } declare class Url extends UIPlugin { - public addFile(url: string): undefined | string | never + public addFile(url: string, optionalMeta: any = undefined): undefined | string | never } export default Url From 497f7bc1ae90519e695a7fdeb88c06d1bb07b730 Mon Sep 17 00:00:00 2001 From: Brad Edelman Date: Thu, 2 Jun 2022 09:22:34 -0700 Subject: [PATCH 7/8] Update index.d.ts per PR review suggestion, improve the type of the new optional argument --- packages/@uppy/url/types/index.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/@uppy/url/types/index.d.ts b/packages/@uppy/url/types/index.d.ts index 8077511803..0173807302 100644 --- a/packages/@uppy/url/types/index.d.ts +++ b/packages/@uppy/url/types/index.d.ts @@ -1,6 +1,7 @@ import type { PluginOptions, UIPlugin, PluginTarget } from '@uppy/core' import type { RequestClientOptions } from '@uppy/companion-client' import UrlLocale from './generatedLocale' +import type { IndexedObject } from '@uppy/core' export interface UrlOptions extends PluginOptions, RequestClientOptions { target?: PluginTarget @@ -9,7 +10,7 @@ export interface UrlOptions extends PluginOptions, RequestClientOptions { } declare class Url extends UIPlugin { - public addFile(url: string, optionalMeta: any = undefined): undefined | string | never + public addFile(url: string, meta?: IndexedObject): undefined | string | never } export default Url From bd2351370395d2586c9113ef3054e2abe7c0f580 Mon Sep 17 00:00:00 2001 From: Merlijn Vos Date: Thu, 2 Jun 2022 18:26:43 +0200 Subject: [PATCH 8/8] Import IndexedObject from already existing import --- packages/@uppy/url/types/index.d.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/@uppy/url/types/index.d.ts b/packages/@uppy/url/types/index.d.ts index 0173807302..c923bf0f8f 100644 --- a/packages/@uppy/url/types/index.d.ts +++ b/packages/@uppy/url/types/index.d.ts @@ -1,7 +1,6 @@ -import type { PluginOptions, UIPlugin, PluginTarget } from '@uppy/core' +import type { PluginOptions, UIPlugin, PluginTarget, IndexedObject } from '@uppy/core' import type { RequestClientOptions } from '@uppy/companion-client' import UrlLocale from './generatedLocale' -import type { IndexedObject } from '@uppy/core' export interface UrlOptions extends PluginOptions, RequestClientOptions { target?: PluginTarget