import { IncomingMessage, ServerResponse } from 'node:http'; import { Readable } from 'node:stream'; import { U as UploadResponse } from "../../../packem_shared/types.d-DFh9698o.js"; import { H as Handlers, A as AsyncHandler, U as UploadOptions, a as ResponseFile, R as ResponseList, M as MethodHandler } from "../../../packem_shared/types.d-BeCD21R_.js"; export type { B as BaseHandler, b as RequestEvent, c as UploadErrorEvent, d as UploadEvent } from "../../../packem_shared/types.d-BeCD21R_.js"; import { L as LocationSource, B as BaseHandlerCore } from "../../../packem_shared/tus-base.d-CWXOg_Ui.js"; export { T as TUS_RESUMABLE, a as TUS_VERSION } from "../../../packem_shared/tus-base.d-CWXOg_Ui.js"; import { U as UploadFile } from "../../../packem_shared/storage.d-Cnjmzau5.js"; import 'node:crypto'; import 'lru-cache'; import 'node:events'; import '@visulima/pagination'; import "../../../packem_shared/media-transformer.d-2MuwlsDB.js"; import "../../../packem_shared/types.d-JKMJy3u9.js"; /** * Base handler for Node.js platform (IncomingMessage/ServerResponse). * Extends BaseHandlerCore with Node.js-specific request/response handling. * @template TFile The file type used by this handler. * @template NodeRequest The Node.js request type. * @template NodeResponse The Node.js response type. */ declare abstract class BaseHandlerNode extends BaseHandlerCore implements MethodHandler { /** * Limiting enabled HTTP method handler. */ static readonly methods: Handlers[]; /** * Map of registered HTTP method handlers. */ protected registeredHandlers: Map>; constructor(options: UploadOptions); /** * Gets the registered handlers map. * @returns Map of registered handlers. */ get handlers(): Map>; /** * Handles HTTP request (alias for upload method). * @param request Node.js IncomingMessage. * @param response Node.js ServerResponse. */ handle: (request: NodeRequest, response: NodeResponse) => Promise; /** * Main upload handler that processes HTTP requests and routes them to appropriate method handlers. * @param request Node.js IncomingMessage. * @param response Node.js ServerResponse. * @param next Optional Express-style next function for middleware compatibility. * @throws {UploadError} When storage is not ready or method is not allowed. */ upload: (request: NodeRequest, response: NodeResponse, next?: () => void) => Promise; /** * Adjusts a request before it is routed to a method handler (e.g. a protocol's method * override). Throw an HttpError to reject the request. * @param _request Node.js IncomingMessage. */ protected normalizeRequest(_request: NodeRequest): void; /** * Compose and register HTTP method handlers. * Subclasses should override this to register their specific handlers. */ protected abstract compose(): void; /** * Sends an HTTP response with the provided body, headers, and status code. * @param response Node.js ServerResponse to send data to. * @param body Response body, headers, and status code. */ send(response: NodeResponse, { body, headers, statusCode }: UploadResponse): void; /** * Sends an error response to the client with appropriate status code and message. * @param response Node.js ServerResponse to send error to. * @param error Error object to convert to HTTP error response. */ sendError(response: NodeResponse, error: Error): Promise; /** * Sends streaming response to client with proper backpressure handling and range request support. * @param response Node.js ServerResponse to stream data to. * @param stream Readable stream containing the file data. * @param options Streaming options including headers, range, size, and status code. */ sendStream(response: NodeResponse, stream: Readable, { headers, range, size, statusCode }: { headers?: Record; range?: { end: number; start: number; }; size?: number; statusCode?: number; }): void; /** * Finish upload by sending final response to client with completed file data. * @param _request HTTP request (unused parameter) * @param response HTTP response object to send final response to * @param uploadResponse Final upload response data containing body, headers, and status code */ protected finish(_request: NodeRequest, response: NodeResponse, uploadResponse: UploadResponse | ResponseFile): void; /** * Build file URL from request and file data. * @param request HTTP request with optional originalUrl property * @param file File object containing ID and content type * @returns Constructed file URL with extension based on content type */ protected buildFileUrl(request: NodeRequest & { originalUrl?: string; }, file: TFile): string; /** * Negotiates content type based on Accept header and supported formats. * @param request HTTP request object containing Accept header. * @param supportedTypes Array of supported MIME types to match against. * @returns Best matching content type or undefined if no match found. */ negotiateContentType(request: NodeRequest, supportedTypes: string[]): string | undefined; /** * Default OPTIONS handler. * @param _request HTTP request (unused) * @param _response HTTP response (unused) * @returns Promise resolving to ResponseFile with CORS headers */ options(_request: NodeRequest, _response: NodeResponse): Promise>; /** * Retrieves a file or - with `allowList` enabled - a list of files based on the request path. * @param request Node.js IncomingMessage with optional originalUrl. * @param response Node.js ServerResponse. * @returns Promise resolving to a single file, paginated list, or array of files. * @throws {HttpError} 404 when the file is not found (or the path does not address a file and listing is disabled). */ get(request: NodeRequest & { originalUrl?: string; }, _response: NodeResponse): Promise | ResponseList>; /** * Returns a list of uploaded files with optional pagination support. * @param request Node.js IncomingMessage containing query parameters for pagination. * @param _response Node.js ServerResponse (unused). * @returns Promise resolving to a paginated or complete list of uploaded files. */ list(request: NodeRequest, _response: NodeResponse): Promise>; /** * What a Location header is built from: a Node request URL is only a path, so its origin comes * from the Host / Forwarded headers and the connection. * @param request Node.js request * @returns The location source */ protected locationOf(request: NodeRequest & { originalUrl?: string; }): LocationSource; /** * Check if error is related to undefined ID or path and throw appropriate HTTP error. * @param error Error object to check */ protected override checkForUndefinedIdOrPath(error: unknown): void; } /** * Multipart/form-data upload handler (Node.js version). * @example * ```ts * const multipart = new Multipart({ * storage, * maxFileSize: 100 * 1024 * 1024, // 100MB * }); * * app.use('/files', multipart.handle); * ``` */ declare class Multipart extends BaseHandlerNode { /** * Limiting enabled http method handler */ static override readonly methods: Handlers[]; private readonly multipartBase; /** * Maximum file size allowed for multipart uploads */ private maxFileSize; /** * Maximum header size allowed for multipart parser */ private maxHeaderSize; constructor(options: UploadOptions); /** * Handles multipart/form-data POST requests for file uploads. * @param request Node.js IncomingMessage containing multipart data. * @returns Promise resolving to ResponseFile with upload result. */ post(request: NodeRequest): Promise>; /** * Delete an uploaded file. * @param request Node.js IncomingMessage with file ID * @returns Promise resolving to ResponseFile with deletion result */ delete(request: NodeRequest): Promise>; /** * Compose and register HTTP method handlers. */ protected compose(): void; } /** * REST API handler for direct binary file uploads (Node.js version). * * This handler provides a clean REST interface for file operations: * - POST: Create a new file with raw binary data or initialize chunked upload * - PUT: Create or update a file (requires ID in URL) * - PATCH: Upload chunks for chunked uploads (requires ID in URL) * - GET: Retrieve a file or list files * - DELETE: Delete a file (single) or multiple files (via ?ids=id1,id2 or JSON body) * - HEAD: Get file metadata and upload progress * - OPTIONS: CORS preflight * @example * ```ts * const rest = new Rest({ * storage, * }); * * app.use('/files', rest.handle); * ``` */ declare class Rest extends BaseHandlerNode { /** * Limiting enabled http method handler */ static override readonly methods: Handlers[]; private readonly restBase; constructor(options: UploadOptions); /** * Compose and register HTTP method handlers. */ protected override compose(): void; /** * Creates a new file via POST request with raw binary data. * Supports both full file uploads and chunked upload initialization. * @param request Node.js IncomingMessage with file data. * @returns Promise resolving to ResponseFile with upload result. */ post(request: NodeRequest): Promise>; /** * Create or update a file via PUT request. * Requires file ID in the URL path. * @param request Node.js IncomingMessage with file ID and data * @returns Promise resolving to ResponseFile with upload result */ put(request: NodeRequest): Promise>; /** * Delete an uploaded file or multiple files. * Supports single file (ID in URL) or batch delete (via ?ids=id1,id2 or JSON body). * @param request Node.js IncomingMessage with file ID(s) * @returns Promise resolving to ResponseFile (single) or ResponseList (batch) with deletion result */ delete(request: NodeRequest): Promise | ResponseList>; /** * Uploads a chunk via PATCH request for chunked uploads. * Headers required: X-Chunk-Offset (byte offset), Content-Length (chunk size). * Optional: X-Chunk-Checksum (SHA256 checksum for validation). * @param request Node.js IncomingMessage with chunk data. * @returns Promise resolving to ResponseFile with upload progress. */ patch(request: NodeRequest): Promise>; /** * Get file metadata via HEAD request. * For chunked uploads, also returns upload progress information. * @param request Node.js IncomingMessage with file ID * @returns Promise resolving to ResponseFile with metadata headers */ head(request: NodeRequest): Promise>; /** * Handle OPTIONS requests with REST API capabilities. * @returns Promise resolving to ResponseFile with CORS headers */ override options(): Promise>; } /** * TUS resumable upload protocol handler (Node.js version). * * [tus resumable upload protocol](https://github.com/tus/tus-resumable-upload-protocol/blob/master/protocol.md) * @example * ```ts * const tus = new Tus({storage}); * * app.all('/files', tus.handle); * ``` */ declare class Tus extends BaseHandlerNode { /** * Limiting enabled http method handler */ static override readonly methods: Handlers[]; override disableTerminationForFinishedUploads: boolean; private readonly allowMethodOverride; private readonly tusBase; constructor(options: UploadOptions); /** * Handle OPTIONS requests with TUS protocol capabilities. * @returns Promise resolving to ResponseFile with TUS headers */ override options(): Promise>; /** * Creates a new TUS upload and optionally starts uploading data. * @param request Node.js IncomingMessage with TUS headers. * @returns Promise resolving to ResponseFile with upload location and offset. */ post(request: NodeRequest): Promise>; /** * Write a chunk of data to an existing TUS upload. * @param request Node.js IncomingMessage with chunk data and TUS headers * @returns Promise resolving to ResponseFile with updated offset */ patch(request: NodeRequest): Promise>; /** * Get current upload offset and metadata for TUS resumable uploads. * @param request Node.js IncomingMessage with upload ID * @returns Promise resolving to ResponseFile with upload-offset and metadata headers */ head(request: NodeRequest): Promise>; /** * Get TUS upload metadata and current status. * @param request Node.js IncomingMessage with upload ID * @returns Promise resolving to ResponseFile with file metadata as JSON */ override get(request: NodeRequest): Promise>; /** * Delete a TUS upload and its associated data. * @param request Node.js IncomingMessage with upload ID * @returns Promise resolving to ResponseFile with deletion confirmation */ delete(request: NodeRequest): Promise>; /** * Send TUS protocol response with required headers. * @param response Node.js ServerResponse to send response to * @param uploadResponse Response data with body, headers, and status code */ override send(response: NodeResponse, { body, headers, statusCode }: UploadResponse): void; /** * Applies X-HTTP-Method-Override, which TUS core says the server must use as the request's * method. Only a POST tunnelled to PATCH or DELETE is honoured; see {@link resolveMethodOverride}. * @param request Node.js IncomingMessage */ protected override normalizeRequest(request: NodeRequest): void; /** * Compose and register HTTP method handlers. */ protected compose(): void; /** * Build file URL for TUS uploads (without file extension). * @param request Request the upload was created by * @param file File object containing ID * @returns Constructed file URL for TUS protocol */ protected buildFileUrlForTus(request: LocationSource, file: TFile): string; /** * Adapts a Node.js request to the runtime-independent {@link TusRequest}. * @param request Node.js IncomingMessage * @returns TUS request */ private toTusRequest; } export { type AsyncHandler, type Handlers, type MethodHandler, Multipart, Rest, Tus, type UploadOptions };