From 739f5b4e3faec639741bf6998c72f7888cd01e45 Mon Sep 17 00:00:00 2001 From: stringsplit <77242831+nbitzz@users.noreply.github.com> Date: Thu, 2 Nov 2023 17:35:02 +0000 Subject: [PATCH] port readFileStream --- src/server/index.ts | 2 -- src/server/lib/files.ts | 14 ++++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/server/index.ts b/src/server/index.ts index a2d5091..cda24bb 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -7,8 +7,6 @@ import { getAccount } from "./lib/middleware" import APIRouter from "./routes/api" import preview from "./routes/preview" -require("dotenv").config() - const pkg = require(`${process.cwd()}/package.json`) const app = new Hono() let config = require(`${process.cwd()}/config.json`) diff --git a/src/server/lib/files.ts b/src/server/lib/files.ts index fba8aa2..33b4495 100644 --- a/src/server/lib/files.ts +++ b/src/server/lib/files.ts @@ -4,6 +4,8 @@ import { readFile, writeFile } from "node:fs/promises" import { Readable } from "node:stream" import crypto from "node:crypto" import { files } from "./accounts" +import * as API from "./DiscordAPI" +import type {APIAttachment} from "discord-api-types/v10" import * as Accounts from "./accounts" @@ -12,6 +14,8 @@ export let alphanum = Array.from( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" ) +require("dotenv").config() + // bad solution but whatever export type FileVisibility = "public" | "anonymous" | "private" @@ -71,11 +75,13 @@ export interface StatusCodeError { export default class Files { config: Configuration client: Client + api: API.Client files: { [key: string]: FilePointer } = {} uploadChannel?: TextBasedChannel constructor(config: Configuration) { this.config = config + this.api = new API.Client(process.env.TOKEN!, config.targetChannel) this.client = new Client({ intents: [ IntentsBitField.Flags.GuildMessages, @@ -290,7 +296,7 @@ export default class Files { * @description Read a file * @param uploadId Target file's ID * @param range Byte range to get - * @returns A `Readable` containing the file's contents + * @returns A {@link Readable} containing the file's contents */ async readFileStream( uploadId: string, @@ -325,7 +331,7 @@ export default class Files { scan_msg_end = Math.ceil(scan_files_end / 10) } - let attachments: Discord.Attachment[] = [] + let attachments: APIAttachment[] = [] /* File updates */ let file_updates: Pick = @@ -333,8 +339,8 @@ export default class Files { let atSIB: number[] = [] // kepes track of the size of each file... for (let xi = scan_msg_begin; xi < scan_msg_end + 1; xi++) { - let msg = await this.uploadChannel.messages - .fetch(file.messageids[xi]) + let msg = await this.api + .fetchMessage(file.messageids[xi]) .catch(() => { return null })