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 {
|
interface MessageCacheObject {
|
||||||
expire: number,
|
expire: number,
|
||||||
object: APIMessage
|
object: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Client {
|
export class Client {
|
||||||
|
@ -37,13 +37,13 @@ export class Client {
|
||||||
if (cache && this.messageCache.has(id)) {
|
if (cache && this.messageCache.has(id)) {
|
||||||
let cachedMessage = this.messageCache.get(id)!
|
let cachedMessage = this.messageCache.get(id)!
|
||||||
if (cachedMessage.expire >= Date.now()) {
|
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>)
|
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
|
return message
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -177,12 +177,14 @@ export class ReadStream extends Readable {
|
||||||
|
|
||||||
let msg = await this.files.api
|
let msg = await this.files.api
|
||||||
.fetchMessage(this.pointer.messageids[this.msgIdx])
|
.fetchMessage(this.pointer.messageids[this.msgIdx])
|
||||||
.catch(() => {
|
.catch((e) => {
|
||||||
|
console.error(e)
|
||||||
return null
|
return null
|
||||||
})
|
})
|
||||||
|
|
||||||
if (msg?.attachments) {
|
if (msg?.attachments) {
|
||||||
let attach = msg.attachments
|
let attach = msg.attachments
|
||||||
|
console.log(attach)
|
||||||
|
|
||||||
this.attachmentBuffer = this.ranges.useRanges ? attach.slice(
|
this.attachmentBuffer = this.ranges.useRanges ? attach.slice(
|
||||||
this.msgIdx == this.ranges.scan_msg_begin
|
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
|
? this.ranges.scan_files_end - this.ranges.scan_msg_end * 10 + 1
|
||||||
: attach.length
|
: attach.length
|
||||||
) : attach
|
) : attach
|
||||||
|
|
||||||
|
console.log(this.attachmentBuffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.msgIdx++
|
this.msgIdx++
|
||||||
|
@ -230,12 +234,12 @@ export class ReadStream extends Readable {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getNextChunk() {
|
async getNextChunk() {
|
||||||
console.log("Next chunk requested")
|
|
||||||
let scanning_chunk = await this.getNextAttachment()
|
let scanning_chunk = await this.getNextAttachment()
|
||||||
|
console.log(this.id, "Next chunk requested; got attachment", scanning_chunk)
|
||||||
if (!scanning_chunk) return null
|
if (!scanning_chunk) return null
|
||||||
|
|
||||||
let {
|
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
|
} = this.ranges
|
||||||
|
|
||||||
let headers: HeadersInit =
|
let headers: HeadersInit =
|
||||||
|
|
Loading…
Reference in a new issue