Skip to content

Commit

Permalink
Merge stable branch
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Jun 9, 2022
2 parents 3974905 + ef8c5cc commit a6029d0
Show file tree
Hide file tree
Showing 47 changed files with 1,159 additions and 191 deletions.
7 changes: 4 additions & 3 deletions .eslintrc.js
Expand Up @@ -197,8 +197,8 @@ module.exports = {

// Packages that have switched to ESM sources:
'packages/@uppy/audio/src/**/*.js',
'packages/@uppy/aws-s3/src/**/*.js',
'packages/@uppy/aws-s3-multipart/src/**/*.js',
'packages/@uppy/aws-s3/src/**/*.js',
'packages/@uppy/box/src/**/*.js',
'packages/@uppy/companion-client/src/**/*.js',
'packages/@uppy/compressor/src/**/*.js',
Expand All @@ -222,16 +222,17 @@ module.exports = {
'packages/@uppy/provider-views/src/**/*.js',
'packages/@uppy/react/src/**/*.js',
'packages/@uppy/redux-dev-tools/src/**/*.js',
'packages/@uppy/remote-sources/src/**/*.js',
'packages/@uppy/screen-capture/src/**/*.js',
'packages/@uppy/status-bar/src/**/*.js',
'packages/@uppy/store-default/src/**/*.js',
'packages/@uppy/store-redux/src/**/*.js',
'packages/@uppy/svelte/src/**/*.js',
'packages/@uppy/svelte/rollup.config.js',
'packages/@uppy/svelte/src/**/*.js',
'packages/@uppy/thumbnail-generator/src/**/*.js',
'packages/@uppy/transloadit/src/**/*.js',
'packages/@uppy/tus/src/**/*.js',
'packages/@uppy/unsplash/src/**/*.js',
'packages/@uppy/transloadit/src/**/*.js',
'packages/@uppy/url/src/**/*.js',
'packages/@uppy/utils/src/**/*.js',
'packages/@uppy/vue/src/**/*.js',
Expand Down
11 changes: 4 additions & 7 deletions .github/workflows/release-beta-candidate.yml
Expand Up @@ -14,13 +14,8 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v3
with:
branch: release
- name: Rebase
run: |
git fetch origin ${{ env.BETA_BRANCH }} --depth=1
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"
git rebase FETCH_HEAD
branch: release-beta
fetch-depth: 3 # the prepare commit, the merge commit, and the base ones.
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(corepack yarn config get cacheFolder)"
Expand Down Expand Up @@ -56,6 +51,8 @@ jobs:
echo "This is a release candidate for the following packages:" >> commitMessage
echo >> commitMessage
jq -r 'map("- `"+.ident+"`: "+.oldVersion+" -> "+.newVersion) | join("\n") ' < releases.json >> commitMessage
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"
git commit -n --amend --file commitMessage
- name: Open Pull Request
id: pr_opening
Expand Down
41 changes: 41 additions & 0 deletions CHANGELOG.md
Expand Up @@ -50,6 +50,47 @@ Released: 2022-05-30
- @uppy/transloadit: remove IE 10 hack (Antoine du Hamel / #3777)


## 2.12.1

Released: 2022-06-09

| Package | Version | Package | Version |
| ----------------- | ------- | ----------------- | ------- |
| @uppy/transloadit | 2.3.1 | uppy | 2.12.1 |
| @uppy/robodog | 2.8.1 | | |

- @uppy/transloadit: fix `COMPANION_PATTERN` export (Antoine du Hamel / #3820)
- meta: fix URL generation in the release script (Antoine du Hamel)


## 2.12.0

Released: 2022-06-07

| Package | Version | Package | Version |
| ---------------------- | ------- | ---------------------- | ------- |
| @uppy/aws-s3 | 2.2.1 | @uppy/tus | 2.4.1 |
| @uppy/aws-s3-multipart | 2.4.1 | @uppy/url | 2.2.0 |
| @uppy/companion-client | 2.2.1 | @uppy/xhr-upload | 2.1.2 |
| @uppy/core | 2.3.1 | @uppy/robodog | 2.8.0 |
| @uppy/react | 2.2.2 | uppy | 2.12.0 |
| @uppy/remote-sources | 0.1.0 | | |

- @uppy/remote-sources: Add @uppy/remote-sources preset/plugin (Artur Paikin / #3676)
- @uppy/react: Reset uppy instance when React component is unmounted (Tomasz Pęksa / #3814)
- @uppy/aws-s3-multipart,@uppy/aws-s3,@uppy/tus: queue socket token requests for remote files (Merlijn Vos / #3797)
- @uppy/xhr-upload: replace `ev.target.status` with `xhr.status` (Wes Sankey / #3782)
- @uppy/core: fix `TypeError` when file was deleted (Antoine du Hamel / #3811)
- @uppy/robodog: fix linter warnings (Antoine du Hamel / #3808)
- meta: fix GHA workflow for prereleases (Antoine du Hamel)
- @uppy/aws-s3-multipart: allow `companionHeaders` to be modified with `setOptions` (Paulo Lemos Neto / #3770)
- @uppy/url: enable passing optional meta data to `addFile` (Brad Edelman / #3788)
- @uppy/url: fix `getFileNameFromUrl` (Brad Edelman / #3804)
- @uppy/tus: make onShouldRetry type optional (Merlijn Vos / #3800)
- doc: fix React examples (Antoine du Hamel / #3799)
- meta: add GHA workflow for prereleases (Antoine du Hamel)


## 2.11.0

Released: 2022-05-30
Expand Down
8 changes: 8 additions & 0 deletions packages/@uppy/aws-s3-multipart/CHANGELOG.md
@@ -1,5 +1,13 @@
# @uppy/aws-s3-multipart

## 2.4.1

Released: 2022-06-07
Included in: Uppy v2.12.0

- @uppy/aws-s3-multipart,@uppy/aws-s3,@uppy/tus: queue socket token requests for remote files (Merlijn Vos / #3797)
- @uppy/aws-s3-multipart: allow `companionHeaders` to be modified with `setOptions` (Paulo Lemos Neto / #3770)

## 2.4.0

Released: 2022-05-30
Expand Down
94 changes: 59 additions & 35 deletions packages/@uppy/aws-s3-multipart/src/index.js
Expand Up @@ -20,12 +20,16 @@ function assertServerError (res) {
export default class AwsS3Multipart extends BasePlugin {
static VERSION = packageJson.version

#queueRequestSocketToken

#client

constructor (uppy, opts) {
super(uppy, opts)
this.type = 'uploader'
this.id = this.opts.id || 'AwsS3Multipart'
this.title = 'AWS S3 Multipart'
this.client = new RequestClient(uppy, opts)
this.#client = new RequestClient(uppy, opts)

const defaultOptions = {
timeout: 30 * 1000,
Expand All @@ -36,6 +40,7 @@ export default class AwsS3Multipart extends BasePlugin {
prepareUploadParts: this.prepareUploadParts.bind(this),
abortMultipartUpload: this.abortMultipartUpload.bind(this),
completeMultipartUpload: this.completeMultipartUpload.bind(this),
companionHeaders: {},
}

this.opts = { ...defaultOptions, ...opts }
Expand All @@ -47,8 +52,17 @@ export default class AwsS3Multipart extends BasePlugin {
this.uploaders = Object.create(null)
this.uploaderEvents = Object.create(null)
this.uploaderSockets = Object.create(null)

this.#queueRequestSocketToken = this.requests.wrapPromiseFunction(this.#requestSocketToken)
}

[Symbol.for('uppy test: getClient')] () { return this.#client }

// TODO: remove getter and setter for #client on the next major release
get client () { return this.#client }

set client (client) { this.#client = client }

/**
* Clean up all references for a file's upload: the MultipartUploader instance,
* any events related to the file, and the Companion WebSocket connection.
Expand Down Expand Up @@ -88,7 +102,7 @@ export default class AwsS3Multipart extends BasePlugin {
}
})

return this.client.post('s3/multipart', {
return this.#client.post('s3/multipart', {
filename: file.name,
type: file.type,
metadata,
Expand All @@ -99,15 +113,15 @@ export default class AwsS3Multipart extends BasePlugin {
this.assertHost('listParts')

const filename = encodeURIComponent(key)
return this.client.get(`s3/multipart/${uploadId}?key=${filename}`)
return this.#client.get(`s3/multipart/${uploadId}?key=${filename}`)
.then(assertServerError)
}

prepareUploadParts (file, { key, uploadId, partNumbers }) {
this.assertHost('prepareUploadParts')

const filename = encodeURIComponent(key)
return this.client.get(`s3/multipart/${uploadId}/batch?key=${filename}&partNumbers=${partNumbers.join(',')}`)
return this.#client.get(`s3/multipart/${uploadId}/batch?key=${filename}&partNumbers=${partNumbers.join(',')}`)
.then(assertServerError)
}

Expand All @@ -116,7 +130,7 @@ export default class AwsS3Multipart extends BasePlugin {

const filename = encodeURIComponent(key)
const uploadIdEnc = encodeURIComponent(uploadId)
return this.client.post(`s3/multipart/${uploadIdEnc}/complete?key=${filename}`, { parts })
return this.#client.post(`s3/multipart/${uploadIdEnc}/complete?key=${filename}`, { parts })
.then(assertServerError)
}

Expand All @@ -125,7 +139,7 @@ export default class AwsS3Multipart extends BasePlugin {

const filename = encodeURIComponent(key)
const uploadIdEnc = encodeURIComponent(uploadId)
return this.client.delete(`s3/multipart/${uploadIdEnc}?key=${filename}`)
return this.#client.delete(`s3/multipart/${uploadIdEnc}?key=${filename}`)
.then(assertServerError)
}

Expand Down Expand Up @@ -279,41 +293,45 @@ export default class AwsS3Multipart extends BasePlugin {
})
}

uploadRemote (file) {
#requestSocketToken = async (file) => {
const Client = file.remote.providerOptions.provider ? Provider : RequestClient
const client = new Client(this.uppy, file.remote.providerOptions)
const opts = { ...this.opts }

if (file.tus) {
// Install file-specific upload overrides.
Object.assign(opts, file.tus)
}

const res = await client.post(file.remote.url, {
...file.remote.body,
protocol: 's3-multipart',
size: file.data.size,
metadata: file.meta,
})
return res.token
}

async uploadRemote (file) {
this.resetUploaderReferences(file.id)

// Don't double-emit upload-started for Golden Retriever-restored files that were already started
if (!file.progress.uploadStarted || !file.isRestored) {
this.uppy.emit('upload-started', file)
}

if (file.serverToken) {
return this.connectToServerSocket(file)
}

return new Promise((resolve, reject) => {
const Client = file.remote.providerOptions.provider ? Provider : RequestClient
const client = new Client(this.uppy, file.remote.providerOptions)
client.post(
file.remote.url,
{
...file.remote.body,
protocol: 's3-multipart',
size: file.data.size,
metadata: file.meta,
},
).then((res) => {
this.uppy.setFileState(file.id, { serverToken: res.token })
// eslint-disable-next-line no-param-reassign
file = this.uppy.getFile(file.id)
try {
if (file.serverToken) {
return this.connectToServerSocket(file)
}).then(() => {
resolve()
}).catch((err) => {
this.uppy.emit('upload-error', file, err)
reject(err)
})
})
}
const serverToken = await this.#queueRequestSocketToken(file)

this.uppy.setFileState(file.id, { serverToken })
return this.connectToServerSocket(this.uppy.getFile(file.id))
} catch (err) {
this.uppy.emit('upload-error', file, err)
throw err
}
}

connectToServerSocket (file) {
Expand All @@ -322,7 +340,7 @@ export default class AwsS3Multipart extends BasePlugin {

const token = file.serverToken
const host = getSocketHost(file.remote.companionUrl)
const socket = new Socket({ target: `${host}/api/${token}`, autoOpen: false })
const socket = new Socket({ target: `${host}/api/${token}` })
this.uploaderSockets[file.id] = socket
this.uploaderEvents[file.id] = new EventTracker(this.uppy)

Expand Down Expand Up @@ -412,7 +430,6 @@ export default class AwsS3Multipart extends BasePlugin {
})

queuedRequest = this.requests.run(() => {
socket.open()
if (file.isPaused) {
socket.send('pause', {})
}
Expand All @@ -436,6 +453,11 @@ export default class AwsS3Multipart extends BasePlugin {
return Promise.all(promises)
}

#setCompanionHeaders = () => {
this.#client.setCompanionHeaders(this.opts.companionHeaders)
return Promise.resolve()
}

onFileRemove (fileID, cb) {
this.uploaderEvents[fileID].on('file-removed', (file) => {
if (fileID === file.id) cb(file.id)
Expand Down Expand Up @@ -495,6 +517,7 @@ export default class AwsS3Multipart extends BasePlugin {
resumableUploads: true,
},
})
this.uppy.addPreProcessor(this.#setCompanionHeaders)
this.uppy.addUploader(this.upload)
}

Expand All @@ -506,6 +529,7 @@ export default class AwsS3Multipart extends BasePlugin {
resumableUploads: false,
},
})
this.uppy.removePreProcessor(this.#setCompanionHeaders)
this.uppy.removeUploader(this.upload)
}
}
31 changes: 31 additions & 0 deletions packages/@uppy/aws-s3-multipart/src/index.test.js
Expand Up @@ -227,4 +227,35 @@ describe('AwsS3Multipart', () => {
expect(awsS3Multipart.opts.prepareUploadParts.mock.calls.length).toEqual(2)
})
})

describe('dynamic companionHeader', () => {
let core
let awsS3Multipart
const oldToken = 'old token'
const newToken = 'new token'

beforeEach(() => {
core = new Core()
core.use(AwsS3Multipart, {
companionHeaders: {
authorization: oldToken,
},
})
awsS3Multipart = core.getPlugin('AwsS3Multipart')
})

it('companionHeader is updated before uploading file', async () => {
awsS3Multipart.setOptions({
companionHeaders: {
authorization: newToken,
},
})

await core.upload()

const client = awsS3Multipart[Symbol.for('uppy test: getClient')]()

expect(client[Symbol.for('uppy test: getCompanionHeaders')]().authorization).toEqual(newToken)
})
})
})
7 changes: 7 additions & 0 deletions packages/@uppy/aws-s3/CHANGELOG.md
@@ -1,5 +1,12 @@
# @uppy/aws-s3

## 2.2.1

Released: 2022-06-07
Included in: Uppy v2.12.0

- @uppy/aws-s3-multipart,@uppy/aws-s3,@uppy/tus: queue socket token requests for remote files (Merlijn Vos / #3797)

## 2.2.0

Released: 2022-05-30
Expand Down

0 comments on commit a6029d0

Please sign in to comment.