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()