From 92e330df28ed783ead1783aced4aed1d4f2e236d Mon Sep 17 00:00:00 2001 From: stringsplit <77242831+nbitzz@users.noreply.github.com> Date: Wed, 6 Mar 2024 18:09:40 -0800 Subject: [PATCH] Wow i am. stupid okay --- 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 bcb5bd8..437ad8d 100644 --- a/src/server/lib/DiscordAPI/index.ts +++ b/src/server/lib/DiscordAPI/index.ts @@ -16,7 +16,7 @@ function convertSnowflakeToDate(snowflake: string|number, epoch = DISCORD_EPOCH) interface MessageCacheObject { expire: number, - object: APIMessage + object: string } export class Client { @@ -37,13 +37,13 @@ export class Client { if (cache && this.messageCache.has(id)) { let cachedMessage = this.messageCache.get(id)! if (cachedMessage.expire >= Date.now()) { - return cachedMessage.object + return JSON.parse(cachedMessage.object) as APIMessage } } let message = await (this.rest.fetch(`/channels/${this.targetChannel}/messages/${id}`).then(res=>res.json()) as Promise) - this.messageCache.set(id, { object: message, expire: EXPIRE_AFTER + Date.now() }) + this.messageCache.set(id, { object: JSON.stringify(message) /* clone object so that removing ids from the array doesn't. yeah */, expire: EXPIRE_AFTER + Date.now() }) return message } diff --git a/src/server/lib/files.ts b/src/server/lib/files.ts index 9ba91ea..ab2e96a 100644 --- a/src/server/lib/files.ts +++ b/src/server/lib/files.ts @@ -177,12 +177,14 @@ export class ReadStream extends Readable { let msg = await this.files.api .fetchMessage(this.pointer.messageids[this.msgIdx]) - .catch(() => { + .catch((e) => { + console.error(e) return null }) if (msg?.attachments) { let attach = msg.attachments + console.log(attach) this.attachmentBuffer = this.ranges.useRanges ? attach.slice( this.msgIdx == this.ranges.scan_msg_begin @@ -192,6 +194,8 @@ export class ReadStream extends Readable { ? this.ranges.scan_files_end - this.ranges.scan_msg_end * 10 + 1 : attach.length ) : attach + + console.log(this.attachmentBuffer) } this.msgIdx++ @@ -230,12 +234,12 @@ export class ReadStream extends Readable { } async getNextChunk() { - console.log("Next chunk requested") let scanning_chunk = await this.getNextAttachment() + console.log(this.id, "Next chunk requested; got attachment", scanning_chunk) if (!scanning_chunk) return null let { - byteStart, byteEnd, scan_files_begin, scan_files_end, scan_msg_begin, scan_msg_end + byteStart, byteEnd, scan_files_begin, scan_files_end } = this.ranges let headers: HeadersInit =