import multer from "multer"; import { ArkosNextFunction, ArkosRequest, ArkosRequestHandler, ArkosResponse } from "../../types"; /** * Service to handle file uploads, including single and multiple file uploads, * file validation (type, size), and file deletion. */ export declare class FileUploadService { readonly uploadDir: string; private fileSizeLimit; private allowedFileTypes; private storage; private maxCount; private handleUploadError; /** * Constructor to initialize the file uploader service. * @param {string} uploadDir - The directory where files will be uploaded. * @param {number} fileSizeLimit - The maximum allowed file size. * @param {RegExp} allowedFileTypes - The regular expression for allowed file types. */ constructor(uploadDir: string, fileSizeLimit?: number, allowedFileTypes?: RegExp, maxCount?: number); /** * Validates the file's type and MIME type. * @param {Express.Multer.File} file - The uploaded file. * @param {Function} cb - The callback function to indicate if file is valid. */ private fileFilter; /** * Returns the multer upload configuration. * @returns {multer.Multer} The multer instance configured for file uploads. */ getUpload(): multer.Multer; /** * Middleware to handle single file upload. * @param {string} [oldFilePath] - The path to the file to delete before uploading. * @returns {Function} Middleware function for handling file upload. */ handleSingleUpload(oldFilePath?: string): ArkosRequestHandler; /** * Middleware to handle multiple file uploads. * @returns {Function} Middleware function for handling multiple file uploads. */ handleMultipleUpload(): ArkosRequestHandler; /** * Middleware to handle deletion of a single file from the filesystem. * @param {string} oldFilePath - The path to the file to be deleted. * @returns {Function} Middleware function for handling file deletion. */ handleDeleteSingleFile(oldFilePath: string): ArkosRequestHandler; /** * Deletes a file based on its URL by identifying the appropriate uploader service * @param {string} fileUrl - The URL of the file to delete * @returns {Promise} - True if deletion successful, false otherwise */ deleteFileByUrl(fileUrl: string): Promise; private getFieldName; /** * Handles the upload process and returns the full URLs of uploaded files * @param {ArkosRequest} req - Arkos request object containing the files * @param {ArkosResponse} res - Arkos response object * @param {object} options - Optional parameters for image processing * @returns {Promise} URL or array of URLs to the uploaded files */ upload(req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction, options?: { format?: string; width?: number; height?: number; resizeTo?: number; }): Promise; /** * Deletes a file based on filename and file type from request parameters * @param {string} fileName - The name of the file to delete * @returns {Promise} - True if deletion successful, false otherwise */ deleteFileByName(fileName: string, fileType: "images" | "videos" | "documents" | "files"): Promise; } /** * Creates and returns all file uploader services based on config * @returns Object containing all specialized file uploader services */ export declare const getFileUploadServices: () => { imageUploadService: FileUploadService; videoUploadService: FileUploadService; documentUploadService: FileUploadService; fileUploadService: FileUploadService; }; export declare const fileUploadDefaultRestrictions: { images: { maxCount: number; maxSize: number; supportedFilesRegex: RegExp; }; videos: { maxCount: number; maxSize: number; supportedFilesRegex: RegExp; }; documents: { maxCount: number; maxSize: number; supportedFilesRegex: RegExp; }; files: { maxCount: number; maxSize: number; supportedFilesRegex: RegExp; }; };