pixel-serve-server
Version:
A robust Node.js utility for handling and processing images. This package provides features like resizing, format conversion and etc.
46 lines (41 loc) • 1.62 kB
text/typescript
import { Request, Response, NextFunction } from 'express';
type ImageType = "avatar" | "normal";
type ImageFormat = "jpeg" | "jpg" | "png" | "webp" | "gif" | "tiff" | "avif" | "svg";
type Options = {
baseDir: string;
idHandler?: (id: string) => string;
getUserFolder?: (req: Request, id?: string | undefined) => Promise<string>;
websiteURL?: string;
apiRegex?: RegExp;
allowedNetworkList?: string[];
};
type UserData = {
quality: number | string;
format: ImageFormat;
src?: string;
folder?: string;
type?: ImageType;
userId?: string;
width?: number | string;
height?: number | string;
};
/**
* @function registerServe
* @description A function to register the serveImage function as middleware for Express.
* @param {Options} options - The options object for image processing.
* @returns {function(Request, Response, NextFunction): Promise<void>} The middleware function.
*/
declare const registerServe: (options: Options) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
/**
* @typedef {("avatar" | "normal")} ImageType
* @description Defines the type of image being processed.
*/
/**
* Checks if a specified path is valid within a base path.
*
* @param {string} basePath - The base directory to resolve paths.
* @param {string} specifiedPath - The path to check.
* @returns {boolean} True if the path is valid, false otherwise.
*/
declare const isValidPath: (basePath: string, specifiedPath: string) => Promise<boolean>;
export { type ImageFormat, type ImageType, type Options, type UserData, isValidPath, registerServe };