Skip to content

Commit

Permalink
Merge branch 'main' into remove-website
Browse files Browse the repository at this point in the history
* main:
  fixup! website: update links to work under the new URL (#4371)
  fixup! website: update links to work under the new URL
  website: update links to work under the new URL (#4371)
  website: add a deprecation notice and a link to the new website (#4370)
  @uppy/tus: do not auto-open sockets, clean them up on abort
  @uppy/aws-s3-multipart: do not auto-open sockets, clean them up on abort
  @uppy/companion-client: do not open socket more than once
  meta: deploy to Heroku on every companion commit (#4367)
  @uppy/companion: add connection keep-alive to dropbox (#4365)
  • Loading branch information
Murderlon committed Mar 23, 2023
2 parents d544189 + a9687b2 commit b0bbe66
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 29 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/companion-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,20 @@ jobs:
file: Dockerfile
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}

heroku:
name: Heroku
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Alter dockerfile
run: |
sed -i 's/^EXPOSE 3020$/EXPOSE $PORT/g' Dockerfile
- name: Deploy to heroku
uses: akhileshns/heroku-deploy@v3.12.12
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: companion-demo
heroku_email: ${{secrets.HEROKU_EMAIL}}
usedocker: true
19 changes: 0 additions & 19 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,22 +142,3 @@ jobs:
file: Dockerfile
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}

heroku:
name: Heroku
needs: release
if: ${{ needs.release.outputs.companionWasReleased }}
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Alter dockerfile
run: |
sed -i 's/^EXPOSE 3020$/EXPOSE $PORT/g' Dockerfile
- name: Deploy to heroku
uses: akhileshns/heroku-deploy@v3.12.12
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: companion-demo
heroku_email: ${{secrets.HEROKU_EMAIL}}
usedocker: true
12 changes: 9 additions & 3 deletions packages/@uppy/aws-s3-multipart/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,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}` })
const socket = new Socket({ target: `${host}/api/${token}`, autoOpen: false })
this.uploaderSockets[file.id] = socket
this.uploaderEvents[file.id] = new EventTracker(this.uppy)

Expand All @@ -644,8 +644,9 @@ export default class AwsS3Multipart extends BasePlugin {
// resume a queued upload to make it skip the queue.
queuedRequest.abort()
queuedRequest = this.requests.run(() => {
socket.open()
socket.send('resume', {})
return () => {}
return () => socket.close()
})
}
})
Expand All @@ -670,7 +671,10 @@ export default class AwsS3Multipart extends BasePlugin {
socket.send('pause', {})
}
queuedRequest = this.requests.run(() => {
socket.open()
socket.send('resume', {})

return () => socket.close()
})
})

Expand Down Expand Up @@ -715,9 +719,11 @@ export default class AwsS3Multipart extends BasePlugin {
queuedRequest = this.requests.run(() => {
if (file.isPaused) {
socket.send('pause', {})
} else {
socket.open()
}

return () => {}
return () => socket.close()
})
})
}
Expand Down
3 changes: 3 additions & 0 deletions packages/@uppy/companion-client/src/Socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export default class UppySocket {
[Symbol.for('uppy test: getQueued')] () { return this.#queued }

open () {
if (this.#socket != null) return

this.#socket = new WebSocket(this.opts.target)

this.#socket.onopen = () => {
Expand All @@ -37,6 +39,7 @@ export default class UppySocket {

this.#socket.onclose = () => {
this.#isOpen = false
this.#socket = null
}

this.#socket.onmessage = this.#handleMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class DropBox extends Provider {
prefixUrl: 'https://content.dropboxapi.com/2',
headers: {
'Dropbox-API-Arg': httpHeaderSafeJson({ path: String(id) }),
Connection: 'keep-alive', // important because https://github.com/transloadit/uppy/issues/4357
},
body: Buffer.alloc(0), // if not, it will hang waiting for the writable stream
responseType: 'json',
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/companion/src/standalone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ module.exports = function server (inputCompanionOptions) {
if (companionOptions.redisUrl) {
const RedisStore = connectRedis(session)
const redisClient = redis.client(companionOptions)
// todo next major: change default prefix to something like "companion:" and possibly remove this option
// todo next major: change default prefix to something like "companion-session:" and possibly remove this option
sessionOptions.store = new RedisStore({ client: redisClient, prefix: process.env.COMPANION_REDIS_EXPRESS_SESSION_PREFIX || 'sess:' })
}

Expand Down
16 changes: 11 additions & 5 deletions packages/@uppy/tus/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ export default class Tus extends BasePlugin {
return new Promise((resolve, reject) => {
const token = file.serverToken
const host = getSocketHost(file.remote.companionUrl)
const socket = new Socket({ target: `${host}/api/${token}` })
const socket = new Socket({ target: `${host}/api/${token}`, autoOpen: false })
this.uploaderSockets[file.id] = socket
this.uploaderEvents[file.id] = new EventTracker(this.uppy)

Expand All @@ -519,8 +519,10 @@ export default class Tus extends BasePlugin {
// resume a queued upload to make it skip the queue.
queuedRequest.abort()
queuedRequest = this.requests.run(() => {
socket.open()
socket.send('resume', {})
return () => {}

return () => socket.close()
})
}
})
Expand All @@ -545,8 +547,10 @@ export default class Tus extends BasePlugin {
socket.send('pause', {})
}
queuedRequest = this.requests.run(() => {
socket.open()
socket.send('resume', {})
return () => {}

return () => socket.close()
})
})

Expand Down Expand Up @@ -607,15 +611,17 @@ export default class Tus extends BasePlugin {
queuedRequest = this.requests.run(() => {
if (file.isPaused) {
socket.send('pause', {})
} else {
socket.open()
}

// Don't do anything here, the caller will take care of cancelling the upload itself
// Just close the socket here, the caller will take care of cancelling the upload itself
// using resetUploaderReferences(). This is because resetUploaderReferences() has to be
// called when this request is still in the queue, and has not been started yet, too. At
// that point this cancellation function is not going to be called.
// Also, we need to remove the request from the queue _without_ destroying everything
// related to this upload to handle pauses.
return () => {}
return () => socket.close()
})
})
}
Expand Down
2 changes: 1 addition & 1 deletion private/dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"dev": "vite --clearScreen false",
"build": "vite build",
"preview": "vite preview"
}
Expand Down

0 comments on commit b0bbe66

Please sign in to comment.