mirror of
https://github.com/mollersuite/monofile.git
synced 2024-11-24 14:46:27 -08:00
Wow i am. stupid okay
This commit is contained in:
parent
7df1c8190a
commit
92e330df28
|
@ -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<APIMessage>)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -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 =
|
||||
|
|
Loading…
Reference in a new issue