diff --git a/.github/workflows/companion-deploy.yml b/.github/workflows/companion-deploy.yml index c2d676def8..a8c06b6d5b 100644 --- a/.github/workflows/companion-deploy.yml +++ b/.github/workflows/companion-deploy.yml @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index edfa74e560..3f3d25d963 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 diff --git a/packages/@uppy/aws-s3-multipart/src/index.js b/packages/@uppy/aws-s3-multipart/src/index.js index eac3c0b0c8..733857765c 100644 --- a/packages/@uppy/aws-s3-multipart/src/index.js +++ b/packages/@uppy/aws-s3-multipart/src/index.js @@ -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) @@ -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() }) } }) @@ -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() }) }) @@ -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() }) }) } diff --git a/packages/@uppy/companion-client/src/Socket.js b/packages/@uppy/companion-client/src/Socket.js index 620fee1c2a..0a98200d72 100644 --- a/packages/@uppy/companion-client/src/Socket.js +++ b/packages/@uppy/companion-client/src/Socket.js @@ -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 = () => { @@ -37,6 +39,7 @@ export default class UppySocket { this.#socket.onclose = () => { this.#isOpen = false + this.#socket = null } this.#socket.onmessage = this.#handleMessage diff --git a/packages/@uppy/companion/src/server/provider/dropbox/index.js b/packages/@uppy/companion/src/server/provider/dropbox/index.js index 1b6c3ca715..11f5945f7f 100644 --- a/packages/@uppy/companion/src/server/provider/dropbox/index.js +++ b/packages/@uppy/companion/src/server/provider/dropbox/index.js @@ -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', diff --git a/packages/@uppy/companion/src/standalone/index.js b/packages/@uppy/companion/src/standalone/index.js index 93e45a8950..409f080550 100644 --- a/packages/@uppy/companion/src/standalone/index.js +++ b/packages/@uppy/companion/src/standalone/index.js @@ -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:' }) } diff --git a/packages/@uppy/tus/src/index.js b/packages/@uppy/tus/src/index.js index ec3b588d8f..707136e1e1 100644 --- a/packages/@uppy/tus/src/index.js +++ b/packages/@uppy/tus/src/index.js @@ -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) @@ -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() }) } }) @@ -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() }) }) @@ -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() }) }) } diff --git a/private/dev/package.json b/private/dev/package.json index 33a02f4683..fc4394d0aa 100644 --- a/private/dev/package.json +++ b/private/dev/package.json @@ -18,7 +18,7 @@ "private": true, "type": "module", "scripts": { - "dev": "vite", + "dev": "vite --clearScreen false", "build": "vite build", "preview": "vite preview" }