Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/transloadit/uppy
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Mar 19, 2024
2 parents 785fa3f + c306d6c commit dcd4e5c
Show file tree
Hide file tree
Showing 40 changed files with 1,747 additions and 886 deletions.
19 changes: 19 additions & 0 deletions .yarn/patches/resize-observer-polyfill-npm-1.5.1-603120e8a0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
diff --git a/src/index.d.ts b/src/index.d.ts
index 74aacc0526ff554e9248c3f6fb44c353b5465efc..1b236d215a9db4cbc1c83f4d8bce24add202483e 100644
--- a/src/index.d.ts
+++ b/src/index.d.ts
@@ -1,14 +1,3 @@
-interface DOMRectReadOnly {
- readonly x: number;
- readonly y: number;
- readonly width: number;
- readonly height: number;
- readonly top: number;
- readonly right: number;
- readonly bottom: number;
- readonly left: number;
-}
-
declare global {
interface ResizeObserverCallback {
(entries: ResizeObserverEntry[], observer: ResizeObserver): void
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
"start-server-and-test": "patch:start-server-and-test@npm:1.14.0#.yarn/patches/start-server-and-test-npm-1.14.0-841aa34fdf.patch",
"stylelint-config-rational-order": "patch:stylelint-config-rational-order@npm%3A0.1.2#./.yarn/patches/stylelint-config-rational-order-npm-0.1.2-d8336e84ed.patch",
"uuid@^8.3.2": "patch:uuid@npm:8.3.2#.yarn/patches/uuid-npm-8.3.2-eca0baba53.patch",
"tus-js-client": "patch:tus-js-client@npm%3A3.1.3#./.yarn/patches/tus-js-client-npm-3.1.3-dc57874d23.patch"
"tus-js-client": "patch:tus-js-client@npm%3A3.1.3#./.yarn/patches/tus-js-client-npm-3.1.3-dc57874d23.patch",
"resize-observer-polyfill": "patch:resize-observer-polyfill@npm%3A1.5.1#./.yarn/patches/resize-observer-polyfill-npm-1.5.1-603120e8a0.patch"
}
}
46 changes: 46 additions & 0 deletions packages/@uppy/aws-s3-multipart/src/createSignedURL.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe('createSignedURL', () => {
Bucket: bucketName,
Key: 'some/key',
}),
{ expiresIn: 900 },
),
).searchParams.get('X-Amz-Signature'),
)
Expand Down Expand Up @@ -88,8 +89,53 @@ describe('createSignedURL', () => {
PartNumber: partNumber,
Key: 'some/key',
}),
{ expiresIn: 900 },
),
).searchParams.get('X-Amz-Signature'),
)
})

it('should escape path and query as restricted to RFC 3986', async () => {
const client = new S3Client(s3ClientOptions)
const partNumber = 99
const specialChars = ";?:@&=+$,#!'()"
const uploadId = `Upload${specialChars}Id`
// '.*' chars of path should be encoded
const Key = `${specialChars}.*/${specialChars}.*.ext`
const implResult = await createSignedURL({
accountKey: s3ClientOptions.credentials.accessKeyId,
accountSecret: s3ClientOptions.credentials.secretAccessKey,
sessionToken: s3ClientOptions.credentials.sessionToken,
uploadId,
partNumber,
bucketName,
Key,
Region: s3ClientOptions.region,
expires: 900,
})
const sdkResult = new URL(
await getSignedUrl(
client,
new UploadPartCommand({
Bucket: bucketName,
UploadId: uploadId,
PartNumber: partNumber,
Key,
}),
{ expiresIn: 900 },
),
)
assert.strictEqual(implResult.pathname, sdkResult.pathname)

const extractUploadId = /([?&])uploadId=([^&]+?)(&|$)/
const extractSignature = /([?&])X-Amz-Signature=([^&]+?)(&|$)/
assert.strictEqual(
implResult.search.match(extractUploadId)![2],
sdkResult.search.match(extractUploadId)![2],
)
assert.strictEqual(
implResult.search.match(extractSignature)![2],
sdkResult.search.match(extractSignature)![2],
)
})
})
8 changes: 7 additions & 1 deletion packages/@uppy/aws-s3-multipart/src/createSignedURL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,13 @@ export default async function createSignedURL({
}): Promise<URL> {
const Service = 's3'
const host = `${bucketName}.${Service}.${Region}.amazonaws.com`
const CanonicalUri = `/${encodeURI(Key)}`
/**
* List of char out of `encodeURI()` is taken from ECMAScript spec.
* Note that the `/` character is purposefully not included in list below.
*
* @see https://tc39.es/ecma262/#sec-encodeuri-uri
*/
const CanonicalUri = `/${encodeURI(Key).replace(/[;?:@&=+$,#!'()*]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`)}`
const payload = 'UNSIGNED-PAYLOAD'

const requestDateTime = new Date().toISOString().replace(/[-:]|\.\d+/g, '') // YYYYMMDDTHHMMSSZ
Expand Down
4 changes: 2 additions & 2 deletions packages/@uppy/core/src/BasePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type {
OptionalPluralizeLocale,
} from '@uppy/utils/lib/Translator'
import type { Body, Meta } from '@uppy/utils/lib/UppyFile'
import type { State, Uppy } from './Uppy'
import type { State, UnknownPlugin, Uppy } from './Uppy'

export type PluginOpts = {
locale?: Locale
Expand Down Expand Up @@ -111,7 +111,7 @@ export default class BasePlugin<
*/

// eslint-disable-next-line @typescript-eslint/no-unused-vars
addTarget(plugin: unknown): HTMLElement {
addTarget(plugin: UnknownPlugin<M, B>): HTMLElement | null {
throw new Error(
"Extend the addTarget method to add your plugin to another plugin's target",
)
Expand Down
4 changes: 2 additions & 2 deletions packages/@uppy/core/src/UIPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class UIPlugin<

this.onMount()

return this.el
return this.el!
}

const targetPlugin = this.getTargetPlugin(target)
Expand All @@ -148,7 +148,7 @@ class UIPlugin<
this.el = targetPlugin.addTarget(plugin)

this.onMount()
return this.el
return this.el!
}

this.uppy.log(`Not installing ${callerPluginName}`)
Expand Down
20 changes: 12 additions & 8 deletions packages/@uppy/core/src/Uppy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export type UnknownPlugin<
export type UnknownProviderPluginState = {
authenticated: boolean | undefined
breadcrumbs: {
requestPath: string
requestPath?: string
name?: string
id?: string
}[]
Expand Down Expand Up @@ -135,7 +135,7 @@ export type UnknownSearchProviderPlugin<
provider: CompanionClientSearchProvider
}

interface UploadResult<M extends Meta, B extends Body> {
export interface UploadResult<M extends Meta, B extends Body> {
successful?: UppyFile<M, B>[]
failed?: UppyFile<M, B>[]
uploadID?: string
Expand All @@ -159,10 +159,12 @@ export interface State<M extends Meta, B extends Body>
uploadProgress: boolean
individualCancellation: boolean
resumableUploads: boolean
isMobileDevice?: boolean
darkMode?: boolean
}
currentUploads: Record<string, CurrentUpload<M, B>>
allowNewUpload: boolean
recoveredState: null | State<M, B>
recoveredState: null | Required<Pick<State<M, B>, 'files' | 'currentUploads'>>
error: string | null
files: {
[key: string]: UppyFile<M, B>
Expand Down Expand Up @@ -270,13 +272,13 @@ type UploadCompleteCallback<M extends Meta, B extends Body> = (
result: UploadResult<M, B>,
) => void
type ErrorCallback<M extends Meta, B extends Body> = (
error: { message?: string; details?: string },
error: { name: string; message: string; details?: string },
file?: UppyFile<M, B>,
response?: UppyFile<M, B>['response'],
) => void
type UploadErrorCallback<M extends Meta, B extends Body> = (
file: UppyFile<M, B> | undefined,
error: { message: string; details?: string },
error: { name: string; message: string; details?: string },
response?:
| Omit<NonNullable<UppyFile<M, B>['response']>, 'uploadURL'>
| undefined,
Expand Down Expand Up @@ -320,8 +322,9 @@ export interface _UppyEventMap<M extends Meta, B extends Body> {
'preprocess-progress': PreProcessProgressCallback<M, B>
progress: ProgressCallback
'reset-progress': GenericEventCallback
restored: GenericEventCallback
restored: (pluginData: any) => void
'restore-confirmed': GenericEventCallback
'restore-canceled': GenericEventCallback
'restriction-failed': RestrictionFailedCallback<M, B>
'resume-all': GenericEventCallback
'retry-all': RetryAllCallback
Expand Down Expand Up @@ -638,7 +641,7 @@ export class Uppy<M extends Meta, B extends Body> {

// @todo next major: rename to `clear()`, make it also cancel ongoing uploads
// or throw and say you need to cancel manually
protected clearUploadedFiles(): void {
clearUploadedFiles(): void {
this.setState({ ...defaultUploadState, files: {} })
}

Expand Down Expand Up @@ -789,6 +792,7 @@ export class Uppy<M extends Meta, B extends Body> {

#informAndEmit(
errors: {
name: string
message: string
isUserFacing?: boolean
details?: string
Expand Down Expand Up @@ -1716,7 +1720,7 @@ export class Uppy<M extends Meta, B extends Body> {

#updateOnlineStatus = this.updateOnlineStatus.bind(this)

getID(): UppyOptions<M, B>['id'] {
getID(): string {
return this.opts.id
}

Expand Down
3 changes: 2 additions & 1 deletion packages/@uppy/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
export { default } from './Uppy.ts'
export {
default as Uppy,
type UppyEventMap,
type State,
type UnknownPlugin,
type UnknownProviderPlugin,
type UnknownSearchProviderPlugin,
type UploadResult,
type UppyEventMap,
} from './Uppy.ts'
export { default as UIPlugin } from './UIPlugin.ts'
export { default as BasePlugin } from './BasePlugin.ts'
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/drag-drop/src/DragDrop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { h, type ComponentChild } from 'preact'
import packageJson from '../package.json'
import locale from './locale.ts'

interface DragDropOptions extends UIPluginOptions {
export interface DragDropOptions extends UIPluginOptions {
inputName?: string
allowMultipleFiles?: boolean
width?: string | number
Expand Down
1 change: 1 addition & 0 deletions packages/@uppy/drag-drop/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default } from './DragDrop.tsx'
export type { DragDropOptions } from './DragDrop.tsx'
1 change: 1 addition & 0 deletions packages/@uppy/golden-retriever/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tsconfig.*

0 comments on commit dcd4e5c

Please sign in to comment.