From b0a16b436015b862048e6e1c8e44bb79966cda65 Mon Sep 17 00:00:00 2001 From: Cian Butler Date: Sat, 10 Jun 2023 20:09:56 +0100 Subject: [PATCH] Fix filedownloader --- .github/workflows/pull-requests.yml | 52 ++++++++++++++++++++++++++--- src/client/wetty.ts | 4 +-- src/client/wetty/download.ts | 10 +++--- 3 files changed, 54 insertions(+), 12 deletions(-) diff --git a/.github/workflows/pull-requests.yml b/.github/workflows/pull-requests.yml index 32630dab..91c8c2ae 100644 --- a/.github/workflows/pull-requests.yml +++ b/.github/workflows/pull-requests.yml @@ -9,7 +9,6 @@ jobs: validate-docker: name: Validate Docker Build - uses: ./.github/workflows/docker.workflow.yml strategy: matrix: platform: @@ -17,7 +16,50 @@ jobs: - linux/arm/v6 - linux/arm/v7 - linux/arm64 - secrets: inherit - with: - platforms: ${{ matrix.platform }} - push: false + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: | + wettyoss/wetty + ghcr.io/butlerx/wetty + flavor: | + latest=true + tags: | + type=schedule + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Login to GHCR + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push + uses: docker/build-push-action@v4 + with: + context: . + file: containers/wetty/Dockerfile + platforms: ${{ matrix.platform }} + push: false + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=registry,ref=${{ steps.meta.outputs.tags }} + cache-to: type=inline diff --git a/src/client/wetty.ts b/src/client/wetty.ts index f9373ec4..920d5632 100644 --- a/src/client/wetty.ts +++ b/src/client/wetty.ts @@ -42,8 +42,8 @@ socket.on('connect', () => { socket.emit('resize', size); }); socket - .on('data', (data: string) => { - const remainingData = fileDownloader.buffer(data); + .on('data', async (data: string) => { + const remainingData = await fileDownloader.buffer(data); const downloadLength = data.length - remainingData.length; if (downloadLength && fcClient.needsCommit(downloadLength)) { socket.emit('commit', fcClient.ackBytes); diff --git a/src/client/wetty/download.ts b/src/client/wetty/download.ts index 90cb09d9..99cc3ca3 100644 --- a/src/client/wetty/download.ts +++ b/src/client/wetty/download.ts @@ -1,4 +1,4 @@ -import fileType from 'file-type'; +import { fileTypeFromBuffer } from 'file-type'; import Toastify from 'toastify-js'; const DEFAULT_FILE_BEGIN = '\u001b[5i'; @@ -6,7 +6,7 @@ const DEFAULT_FILE_END = '\u001b[4i'; type OnCompleteFile = (bufferCharacters: string) => void; -function onCompleteFile(bufferCharacters: string): void { +async function onCompleteFile(bufferCharacters: string): Promise { let fileCharacters = bufferCharacters; // Try to decode it as base64, if it fails we assume it's not base64 try { @@ -22,7 +22,7 @@ function onCompleteFile(bufferCharacters: string): void { let mimeType = 'application/octet-stream'; let fileExt = ''; - const typeData = fileType(bytes); + const typeData = await fileTypeFromBuffer(bytes); if (typeData) { mimeType = typeData.mime; fileExt = typeData.ext; @@ -77,7 +77,7 @@ export class FileDownloader { this.onCompleteFileCallback = onCompleteFileCallback; } - bufferCharacter(character: string): string { + async bufferCharacter(character: string): Promise { // If we are not currently buffering a file. if (this.fileBuffer.length === 0) { // If we are not currently expecting the rest of the fileBegin sequences. @@ -125,7 +125,7 @@ export class FileDownloader { this.fileBuffer.length >= this.fileBegin.length + this.fileEnd.length && this.fileBuffer.slice(-this.fileEnd.length).join('') === this.fileEnd ) { - this.onCompleteFileCallback( + await this.onCompleteFileCallback( this.fileBuffer .slice( this.fileBegin.length,