/// import { DFWScheme } from "../.."; import DFWModule from "./DFWModule"; import moment from "moment"; import dfw_file from "../../model/dfw_file.model"; import * as Express from "express"; export declare type UploadOptions = { path?: string; name?: string; slug?: string; ext?: string; expiration?: Date | moment.Moment | null; access?: number; description?: string; parent?: dfw_file | FileRecord | number; variant?: string; copy?: boolean; }; export declare type UploadConfig = { headers?: any; highWaterMark?: number; fileHwm?: number; defCharset?: string; preservePath?: boolean; limits?: { fieldNameSize?: number; fieldSize?: number; fields?: number; fileSize?: number; files?: number; parts?: number; headerPairs?: number; }; }; export declare type FileRecord = { id: number; description: string; url: string; size: number; expire: Date; created: Date; children?: FileRecord[]; variant: string; }; export declare type FileRecordOptions = { recursive?: boolean; }; export interface UploadedFile { name: string; encoding: string; mimetype: string; data: Buffer; size: number; tempFilePath: string; truncated: boolean; md5: string; mv(path: string, callback: (err: any) => void): void; mv(path: string): Promise; } export default class UploadManager extends DFWModule { static readonly ACCESS_PUBLIC = 0; static readonly ACCESS_SESSION = 1; static readonly ACCESS_PRIVATE = 2; private readonly TMPDIR; constructor(dfw: any); /** * @param dfw */ touchAsync(dfw: DFWScheme): Promise; /** * Flushes the uploaded file to save in DFW database * @param dfw * @param currentPath * @param config */ flushUploadedFileAsync(dfw: DFWScheme, file: UploadedFile, config: UploadOptions): Promise; /** * * @param file */ invalidateFileAsync(file: number | dfw_file | FileRecord): Promise; /** * * @param file * @param expire */ validateFileAsync(file: number | dfw_file | FileRecord, expire?: Date | null): Promise; /** * * @param dfw * @param filePath * @param options */ assingLocalFileAsync(dfw: DFWScheme, filePath: string, options?: UploadOptions): Promise; /** * * @param dfw * @param path * @param parent * @param variant * @param options */ assignChildLocalFileAsync(dfw: DFWScheme, path: string, parent: number | dfw_file | FileRecord, variant?: string, options?: UploadOptions): Promise; /** * * @param file */ getFileRecordData(file: dfw_file | dfw_file[], options?: FileRecordOptions): FileRecord | FileRecord[]; /** * Static method * @param DFW * @param file */ getFileRecordDataAsync(file: number | dfw_file | number[] | dfw_file[], options?: FileRecordOptions): Promise; /** * */ getLocalPrivateUploadDir(): string; /** * */ getLocalUploadDir(): string; /** * */ getStaticUploadPath(): string; /** * */ getStaticUploadSlugPath(): string; /** * Generate pre-configured middleware for file uploading * @param config */ makeUploadMiddleware(config?: UploadConfig): Express.RequestHandler; /** * * @param file */ removeFileAsync(file: number | dfw_file | FileRecord): any; /** * TODO * @param dfw * @param file */ checkFileAccessAsync(dfw: DFWScheme, file: number | dfw_file | FileRecord): Promise; getFileURL(file: dfw_file): string; getFileLocalPath(file: dfw_file): string; /** * Delete all expired uploaded files in the local file system */ purge(): Promise; } export interface DFWFileSystemSchema { /** * Flushes the upload with the file and uploadConfig */ flushUploadAsync: (file: UploadedFile, config?: UploadOptions) => Promise; /*** * */ getFileRecordAsync: (file: number | dfw_file | number[] | dfw_file[], options?: FileRecordOptions) => Promise; /*** * */ getFileRecord: (file: dfw_file | dfw_file[]) => FileRecord | FileRecord[] | null; /** * */ checkFileAccessAsync: (file: number | dfw_file) => Promise; /** * */ validateFileAsync: (file: number | dfw_file | FileRecord, expire?: Date | null) => Promise; /** * */ invalidateFileAsync: (file: number | dfw_file | FileRecord) => Promise; /** * */ removeFileAsync: (file: number | dfw_file | FileRecord) => Promise; }