import type * as stream from "stream"; import type { ALLOWED_CONTENT_TYPE, ALLOWED_EXTENSION, ValidatedColumnInfo } from "prostgles-types"; import type { DB, DBHandlerServer, Prostgles } from "../Prostgles"; export declare const HOUR: number; export declare const asSQLIdentifier: (name: string, db: DB) => Promise; export type OnProgress = (progress: { total: number; loaded: number; }) => void; type ImageCompressionOptions = { inside: { width: number; height: number; }; } | { contain: { width: number; } | { height: number; }; }; /** * Deprecated */ export type ImageOptions = { keepMetadata?: boolean; compression?: ImageCompressionOptions; }; export type UploadedCloudFile = { cloud_url: string; etag: string; content_length: number; }; export type FileUploadArgs = { fileName: string; contentType: string; file: string | Buffer | stream.PassThrough; onFinish: (...args: [error: Error, result: undefined] | [error: undefined, result: UploadedCloudFile]) => void; onProgress?: (bytesUploaded: number) => void; }; export type CloudClient = { upload: (file: FileUploadArgs) => Promise; downloadAsStream: (name: string) => Promise; delete: (fileName: string) => Promise; getSignedUrlForDownload: (fileName: string, expiresInSeconds: number) => Promise; }; export type LocalConfig = { /** * example: path.join(__dirname+'/media') * note that this location will be relative to the compiled file location */ localFolderPath: string; /** * Minimum amount of free bytes available to allow saving files * Defaults to 100MB */ minFreeBytes?: number; }; export type UploadItem = { name: string; content_type: string; data: Buffer; extension: string; }; export type UploadedItem = { /** * Url that is passed to client */ url: string; filePath?: string; etag: string; /** * Cloud url of the resource */ cloud_url?: string; /** * Total uploaded file size in bytes */ content_length: number; }; export declare class FileManager { cloudClient?: CloudClient; config: CloudClient | LocalConfig; imageOptions?: ImageOptions; prostgles?: Prostgles; get dbo(): DBHandlerServer; get db(): DB; tableName?: string; path?: string; get fileRouteExpress(): string; constructor(config: FileManager["config"], imageOptions?: ImageOptions); getFileStream(name: string): Promise; deleteFile(name: string): Promise; getValidatedFileType: (args: { file: Buffer | string; fileName: string; colName?: string; tableName?: string; }) => Promise<{ mime: ALLOWED_CONTENT_TYPE; ext: string; }>; getLocalFileUrl: (name: string) => string; checkFreeSpace: (folderPath: string, fileSize?: number) => Promise; uploadStream: (name: string, mime: string, onProgress?: OnProgress | undefined, onError?: ((error: any) => void) | undefined, onEnd?: ((item: UploadedItem) => void) | undefined, expectedSizeBytes?: number | undefined) => stream.PassThrough; upload: (file: string | Buffer | stream.PassThrough, name: string, mime: string, onProgress?: OnProgress | undefined) => Promise; uploadAsMedia: (params: { item: UploadItem; allowedExtensions?: Array; dissallowedExtensions?: Array; imageOptions?: ImageOptions; }) => Promise; getFileCloudDownloadURL(fileName: string, expiresInSecondsRaw?: number): Promise; parseSQLIdentifier: (name: string) => Promise; getColInfo: (args: { tableName: string; colName: string; }) => ValidatedColumnInfo["file"] | undefined; init: (prg: Prostgles) => Promise; destroy: () => void; } export declare const getFileTypeFromFilename: (fileName: string) => { mime: ALLOWED_CONTENT_TYPE; ext: ALLOWED_EXTENSION; } | undefined; export declare const getFileType: (file: Buffer | string, fileName: string) => Promise<{ mime: ALLOWED_CONTENT_TYPE; ext: ALLOWED_EXTENSION; }>; export declare function bytesToSize(bytes: number): string; export {}; //# sourceMappingURL=FileManager.d.ts.map