import { provider } from '../../utils/index.js'; import type { Response, NextFunction, PathUtils } from '../../types/index.js'; /** * The options to create a {@link SendFile} function. * * @group Services/SendFile */ export type SendFileGeneratorOptions = { /** * A dictionary with the dependencies to inject. */ inject: { pathUtils: PathUtils; }; }; /** * The options for the function that actually serves a file. * * @group Services/SendFile */ export type SendFileOptions = { /** * The response object sent by the application. Necessary to write the file. */ res: Response; /** * The path of the file to serve. Depending on the `from` option, it will be either * relative to the project root, or the application executable. */ filepath: string; /** * The name of a location on the `pathUtils` service from where the `filepath` is * relative to. It can be `app` for the directory containing the application executable, * or `project` for the project root. It could also be any other location that the * implementation may have registered. * * @default 'app' */ from?: string; /** * The function to move to the next middleware. It can be used to report an error in * case the file can't be served. * * @default {() => {}} */ next?: NextFunction; }; /** * The type of the function that serves a file. * This is exported to make it easy to type the dependency injection. * * @group Services/SendFile */ export type SendFile = (options: SendFileOptions) => void; /** * Generates a function to send files on the application response. * * @param options To inject the required dependencies. * @example * *