IT.S DONE FUCK

This commit is contained in:
May 2024-03-03 17:03:36 -08:00
parent daca021522
commit 549f7de7ac
2 changed files with 15 additions and 8 deletions

View file

@ -80,7 +80,7 @@ export class Client {
let boundary = "-".repeat(20) + Math.random().toString().slice(2) let boundary = "-".repeat(20) + Math.random().toString().slice(2)
let pushBoundary = (stream: Readable) => let pushBoundary = (stream: Readable) =>
stream.push(`${(file_number++) == 0 ? "" : "\n"}--${boundary}\nContent-Disposition: form-data; name="files[${file_number}]"; filename="${Math.random().toString().slice(2)}\nContent-Type: application/octet-stream\n\n`) stream.push(`${(file_number++) == 0 ? "" : "\r\n"}--${boundary}\r\nContent-Disposition: form-data; name="files[${file_number}]"; filename="${Math.random().toString().slice(2)}\r\nContent-Type: application/octet-stream\r\n\r\n`)
let boundPush = (stream: Readable, chunk: Buffer) => { let boundPush = (stream: Readable, chunk: Buffer) => {
let position = 0 let position = 0
console.log(`Chunk length ${chunk.byteLength}`) console.log(`Chunk length ${chunk.byteLength}`)
@ -92,8 +92,8 @@ export class Client {
} }
let capture = Math.min( let capture = Math.min(
this.config.maxDiscordFileSize - (bytes_sent % this.config.maxDiscordFileSize) + 1, (this.config.maxDiscordFileSize - (bytes_sent % this.config.maxDiscordFileSize)) + 1,
chunk.byteLength chunk.byteLength-position
) )
console.log(`Capturing ${capture} bytes, ${chunk.subarray(position, position+capture).byteLength}`) console.log(`Capturing ${capture} bytes, ${chunk.subarray(position, position+capture).byteLength}`)
stream.push( chunk.subarray(position, position + capture) ) stream.push( chunk.subarray(position, position + capture) )
@ -111,7 +111,7 @@ export class Client {
callback() callback()
}, },
flush(callback) { flush(callback) {
this.push(`\n--${boundary}--`) this.push(`\r\n--${boundary}--`)
callback() callback()
} }
}) })
@ -127,6 +127,11 @@ export class Client {
} }
}) })
if (!returned.ok) {
throw new Error(`[Message creation] ${returned.status} ${returned.statusText}`)
}
let response = (await returned.json() as APIMessage) let response = (await returned.json() as APIMessage)
console.log(JSON.stringify(response, null, 4)) console.log(JSON.stringify(response, null, 4))
return response return response

View file

@ -137,10 +137,10 @@ export class UploadStream extends Writable {
while (position < data.byteLength) { while (position < data.byteLength) {
let capture = Math.min( let capture = Math.min(
(this.files.config.maxDiscordFileSize*10) - (this.filled % (this.files.config.maxDiscordFileSize*10)) + 1, ((this.files.config.maxDiscordFileSize*10) - (this.filled % (this.files.config.maxDiscordFileSize*10))) + 1,
data.byteLength data.byteLength-position
) )
console.log(`Capturing ${capture} bytes from fl, ${data.subarray(position, position + capture).byteLength}`) console.log(`Capturing ${capture} bytes for megachunk, ${data.subarray(position, position + capture).byteLength}`)
if (!this.current) await this.getNextStream() if (!this.current) await this.getNextStream()
if (!this.current) { if (!this.current) {
this.destroy(new Error("getNextStream called during debounce")); return this.destroy(new Error("getNextStream called during debounce")); return
@ -161,7 +161,7 @@ export class UploadStream extends Writable {
else this.once("exec-callback", callback) else this.once("exec-callback", callback)
} }
async _final(callback: (error?: Error | null | undefined) => void) { async _final(callback: (error?: Error | null | undefined) => void) {
if (this.current) { if (this.current) {
this.current.push(null); this.current.push(null);
// i probably dnt need this but whateverrr :3 // i probably dnt need this but whateverrr :3
@ -491,6 +491,8 @@ export default class Files {
return null return null
} }
console.log(msgIdx,position,scanning_chunk.size)
let headers: HeadersInit = let headers: HeadersInit =
useRanges useRanges
? { ? {