import crypto from "node:crypto"; import * as fs from "node:fs"; import * as path from "node:path"; import { getPlatformAdapter } from "../adapter/index.js"; import type { SsrfPolicyConfig } from "../adapter/types.js"; import { formatErrorMessage } from "./format.js"; import { normalizeLowercaseStringOrEmpty, normalizeOptionalString } from "./string-normalize.js";
/** Maximum file size accepted by the QQ Bot API. */
export const MAX_UPLOAD_SIZE = 20 * 1024 * 1024;
/** Threshold used to treat an upload as a large file. */
export const LARGE_FILE_THRESHOLD = 5 * 1024 * 1024;
/** Get file size asynchronously. */
export async function getFileSizeAsync(filePath: string): Promise<number> { const stat = await fs.promises.stat(filePath); return stat.size;
}
/** Return true when a file should be treated as large. */
export function isLargeFile(sizeBytes: number): boolean { return sizeBytes >= LARGE_FILE_THRESHOLD;
}
/** Format a byte count into a human-readable size string. */
export function formatFileSize(bytes: number): string { if (bytes < 1024) { return `${bytes}B`;
} if (bytes < 1024 * 1024) { return `${(bytes / 1024).toFixed(1)}KB`;
} return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.