From 790bafa46ecee1f2b7e4e2a60515ed178b0cac9f Mon Sep 17 00:00:00 2001 From: Tony133 Date: Thu, 7 Nov 2024 21:15:39 +0100 Subject: [PATCH] refactor(): update fastify static options interface --- .../fastify-static-options.interface.ts | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/packages/platform-fastify/interfaces/external/fastify-static-options.interface.ts b/packages/platform-fastify/interfaces/external/fastify-static-options.interface.ts index 6414a9ed979..e4a434a3549 100644 --- a/packages/platform-fastify/interfaces/external/fastify-static-options.interface.ts +++ b/packages/platform-fastify/interfaces/external/fastify-static-options.interface.ts @@ -3,9 +3,16 @@ * @see https://github.com/fastify/fastify-static/blob/master/types/index.d.ts * @publicApi */ -import { RouteOptions, FastifyRequest } from 'fastify'; +import { RouteOptions, FastifyRequest, FastifyReply } from 'fastify'; import { Stats } from 'fs'; +interface SetHeadersResponse { + getHeader: FastifyReply['getHeader']; + setHeader: FastifyReply['header']; + readonly filename: string; + statusCode: number; +} + interface ExtendedInformation { fileCount: number; totalFileCount: number; @@ -33,13 +40,22 @@ interface ListRender { } interface ListOptions { - format: 'json' | 'html'; names: string[]; - render: ListRender; extendedFolderInfo?: boolean; jsonFormat?: 'names' | 'extended'; } +export interface ListOptionsJsonFormat extends ListOptions { + format: 'json'; + // Required when the URL parameter `format=html` exists + render?: ListRender; +} + +export interface ListOptionsHtmlFormat extends ListOptions { + format: 'html'; + render: ListRender; +} + // Passed on to `send` interface SendOptions { acceptRanges?: boolean; @@ -55,16 +71,16 @@ interface SendOptions { } export interface FastifyStaticOptions extends SendOptions { - root: string | string[]; + root: string | string[] | URL | URL[]; prefix?: string; prefixAvoidTrailingSlash?: boolean; serve?: boolean; decorateReply?: boolean; schemaHide?: boolean; - setHeaders?: (...args: any[]) => void; + setHeaders?: (res: SetHeadersResponse, path: string, stat: Stats) => void; redirect?: boolean; wildcard?: boolean; - list?: boolean | ListOptions; + list?: boolean | ListOptionsJsonFormat | ListOptionsHtmlFormat; allowedPath?: ( pathName: string, root: string,