Skip to content

Commit

Permalink
Fix filedownloader
Browse files Browse the repository at this point in the history
  • Loading branch information
butlerx committed Jun 10, 2023
1 parent 6c3e39a commit 9714ec6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 11 deletions.
51 changes: 47 additions & 4 deletions .github/workflows/pull-requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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
4 changes: 2 additions & 2 deletions src/client/wetty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/client/wetty/download.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import fileType from 'file-type';
import { fileTypeFromBuffer } from 'file-type';
import Toastify from 'toastify-js';

const DEFAULT_FILE_BEGIN = '\u001b[5i';
const DEFAULT_FILE_END = '\u001b[4i';

type OnCompleteFile = (bufferCharacters: string) => void;

function onCompleteFile(bufferCharacters: string): void {
async function onCompleteFile(bufferCharacters: string): Promise<void> {
let fileCharacters = bufferCharacters;
// Try to decode it as base64, if it fails we assume it's not base64
try {
Expand All @@ -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;
Expand Down Expand Up @@ -77,7 +77,7 @@ export class FileDownloader {
this.onCompleteFileCallback = onCompleteFileCallback;
}

bufferCharacter(character: string): string {
async bufferCharacter(character: string): Promise<string> {
// 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.
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 9714ec6

Please sign in to comment.