mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-02 04:56:07 +00:00
fix: i hate cf workers
This commit is contained in:
parent
25e926ae82
commit
9f228259a2
@ -2,8 +2,9 @@ import type { APIAttachment, RESTAPIAttachment } from 'discord-api-types/v10';
|
||||
import { randomBytes } from 'node:crypto';
|
||||
import path from 'node:path';
|
||||
import { type UsingClient, throwError, type RawFile } from '..';
|
||||
import { promisesReadFile, promisesStat, type ImageResolvable, type ObjectToLower } from '../common';
|
||||
import type { ImageResolvable, ObjectToLower } from '../common';
|
||||
import { Base } from '../structures/extra/Base';
|
||||
import { promises } from 'node:fs';
|
||||
|
||||
export interface AttachmentResolvableMap {
|
||||
url: string;
|
||||
@ -197,12 +198,12 @@ export async function resolveAttachmentData(
|
||||
}
|
||||
case 'path': {
|
||||
const file = path.resolve(data as string);
|
||||
const stats = await promisesStat(file);
|
||||
const stats = await promises.stat(file);
|
||||
if (!stats.isFile())
|
||||
return throwError(
|
||||
`The attachment type has been expressed as ${type.toUpperCase()} but cannot be resolved as one.`,
|
||||
);
|
||||
return { data: await promisesReadFile(file) };
|
||||
return { data: await promises.readFile(file) };
|
||||
}
|
||||
case 'buffer': {
|
||||
if (Buffer.isBuffer(data)) return { data };
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { createWriteStream, existsSync, mkdirSync, type WriteStream } from 'node:fs';
|
||||
import { createWriteStream, existsSync, mkdirSync, promises, type WriteStream } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { bgBrightWhite, black, bold, brightBlack, cyan, gray, italic, red, stripColor, yellow } from './colors';
|
||||
import { MergeOptions, promisesReaddir, promisesUnlink } from './utils';
|
||||
import { MergeOptions } from './utils';
|
||||
export enum LogLevels {
|
||||
Debug = 0,
|
||||
Info = 1,
|
||||
@ -51,9 +51,9 @@ export class Logger {
|
||||
}
|
||||
|
||||
static async clearLogs() {
|
||||
for (const i of await promisesReaddir(join(process.cwd(), Logger.dirname))) {
|
||||
for (const i of await promises.readdir(join(process.cwd(), Logger.dirname), { withFileTypes: true })) {
|
||||
if (this.streams[i.name]) await new Promise(res => this.streams[i.name]!.close(res));
|
||||
await promisesUnlink(join(process.cwd(), Logger.dirname, i.name)).catch(() => {});
|
||||
await promises.unlink(join(process.cwd(), Logger.dirname, i.name)).catch(() => {});
|
||||
delete this.streams[i.name];
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
import type fs from 'node:fs';
|
||||
import { type Dirent, readFile, readdir, stat, unlink } from 'node:fs';
|
||||
import { promises } from 'node:fs';
|
||||
import { basename, join } from 'node:path';
|
||||
import { EmbedColors, type ColorResolvable, type Logger, type ObjectToLower, type ObjectToSnake } from '..';
|
||||
|
||||
@ -115,7 +114,7 @@ export class BaseHandler {
|
||||
protected async getFiles(dir: string) {
|
||||
const files: string[] = [];
|
||||
|
||||
for (const i of await promisesReaddir(dir)) {
|
||||
for (const i of await promises.readdir(dir, { withFileTypes: true })) {
|
||||
if (i.isDirectory()) {
|
||||
files.push(...(await this.getFiles(join(dir, i.name))));
|
||||
} else {
|
||||
@ -282,40 +281,3 @@ export function isCloudfareWorker() {
|
||||
//@ts-expect-error
|
||||
return process.platform === 'browser';
|
||||
}
|
||||
|
||||
//cloudfare support
|
||||
export function promisesReadFile(file: string) {
|
||||
return new Promise<Buffer>((res, rej) =>
|
||||
readFile(file, (err, result) => {
|
||||
if (err) return rej(err);
|
||||
res(result);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function promisesUnlink(file: string) {
|
||||
return new Promise<void>((res, rej) =>
|
||||
unlink(file, err => {
|
||||
if (err) return rej(err);
|
||||
res();
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function promisesStat(file: string) {
|
||||
return new Promise<fs.Stats>((res, rej) =>
|
||||
stat(file, (err, result) => {
|
||||
if (err) return rej(err);
|
||||
res(result);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function promisesReaddir(file: string) {
|
||||
return new Promise<Dirent[]>((res, rej) =>
|
||||
readdir(file, { withFileTypes: true }, (err, result) => {
|
||||
if (err) return rej(err);
|
||||
res(result);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user