mirror of
https://github.com/mollersuite/monofile.git
synced 2024-11-21 21:36:26 -08:00
port readFileStream
This commit is contained in:
parent
107709a98a
commit
739f5b4e3f
|
@ -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`)
|
||||
|
|
|
@ -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<FilePointer, "chunkSize" | "sizeInBytes"> =
|
||||
|
@ -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
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue