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 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 position = 0
console.log(`Chunk length ${chunk.byteLength}`)
@ -92,8 +92,8 @@ export class Client {
}
let capture = Math.min(
this.config.maxDiscordFileSize - (bytes_sent % this.config.maxDiscordFileSize) + 1,
chunk.byteLength
(this.config.maxDiscordFileSize - (bytes_sent % this.config.maxDiscordFileSize)) + 1,
chunk.byteLength-position
)
console.log(`Capturing ${capture} bytes, ${chunk.subarray(position, position+capture).byteLength}`)
stream.push( chunk.subarray(position, position + capture) )
@ -111,7 +111,7 @@ export class Client {
callback()
},
flush(callback) {
this.push(`\n--${boundary}--`)
this.push(`\r\n--${boundary}--`)
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)
console.log(JSON.stringify(response, null, 4))
return response

View file

@ -137,10 +137,10 @@ export class UploadStream extends Writable {
while (position < data.byteLength) {
let capture = Math.min(
(this.files.config.maxDiscordFileSize*10) - (this.filled % (this.files.config.maxDiscordFileSize*10)) + 1,
data.byteLength
((this.files.config.maxDiscordFileSize*10) - (this.filled % (this.files.config.maxDiscordFileSize*10))) + 1,
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) {
this.destroy(new Error("getNextStream called during debounce")); return
@ -161,7 +161,7 @@ export class UploadStream extends Writable {
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) {
this.current.push(null);
// i probably dnt need this but whateverrr :3
@ -491,6 +491,8 @@ export default class Files {
return null
}
console.log(msgIdx,position,scanning_chunk.size)
let headers: HeadersInit =
useRanges
? {