From 0621f55c20d637b885e2891a47926fc8deb6d062 Mon Sep 17 00:00:00 2001 From: stringsplit <77242831+nbitzz@users.noreply.github.com> Date: Fri, 1 Mar 2024 11:30:12 -0800 Subject: [PATCH] i think i might have been stupid --- src/server/lib/DiscordAPI/index.ts | 6 +++--- src/server/lib/files.ts | 10 +++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/server/lib/DiscordAPI/index.ts b/src/server/lib/DiscordAPI/index.ts index 8ef8386..32d0e49 100644 --- a/src/server/lib/DiscordAPI/index.ts +++ b/src/server/lib/DiscordAPI/index.ts @@ -86,11 +86,11 @@ export class Client { console.log(`Chunk length ${chunk.byteLength}`) while (position < chunk.byteLength) { let capture = Math.min( - this.config.maxDiscordFileSize - (bytes_sent % this.config.maxDiscordFileSize), + this.config.maxDiscordFileSize - (bytes_sent % this.config.maxDiscordFileSize) + 1, chunk.byteLength ) - console.log(`Capturing ${capture} bytes, ${chunk.subarray(position, capture).byteLength}`) - stream.push( chunk.subarray(position, capture) ) + console.log(`Capturing ${capture} bytes, ${chunk.subarray(position, position+capture).byteLength}`) + stream.push( chunk.subarray(position, position + capture) ) position += capture, bytes_sent += capture console.log("Chunk progress:", bytes_sent % this.config.maxDiscordFileSize, "B") diff --git a/src/server/lib/files.ts b/src/server/lib/files.ts index 4d2cec6..1abee84 100644 --- a/src/server/lib/files.ts +++ b/src/server/lib/files.ts @@ -136,14 +136,18 @@ export class UploadStream extends Writable { while (progress < data.byteLength) { let capture = Math.min( - this.config.maxDiscordFileSize - (this.filled % this.config.maxDiscordFileSize), + (this.config.maxDiscordFileSize*10) - (this.filled % (this.config.maxDiscordFileSize*10)) + 1, chunk.byteLength ) - console.log(`Capturing ${capture} bytes, ${chunk.subarray(position, capture).byteLength}`) + console.log(`Capturing ${capture} bytes, ${chunk.subarray(position, position + capture).byteLength}`) let nextStream = await this.getNextStream() - nextStream.push( chunk.subarray(position, capture) ) + nextStream.push( chunk.subarray(position, position+capture) ) console.log(`pushed ${data.byteLength} byte chunk`); progress += capture, this.filled += capture + + // message is full, so tell the next run to get a new message + if (this.filled % (this.config.maxDiscordFileSize*10) == 0) + this.current = undefined } callback()