outers
Version:
outers - a all in one package for your day to day use
36 lines • 1.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SendFileResponse = void 0;
/* eslint-disable @typescript-eslint/no-explicit-any */
// types
// Constants
const Response_Constant_1 = require("../Config/Constant/Response.Constant"); // Import JPG_REGEX
// Send File Response
/**
* The function sends a file as a response with the specified status code, filename, and root
* directory.
* @param {FileResponseInterface} - - `statusCode`: The HTTP status code to be sent in the response.
* @param {FileResponseInterface} - - `Filename`: The filename of the file to be sent in the response.
* @param {FileResponseInterface} - - `rootName`: The root directory of the file to be sent in the response.
* @param {FileResponseInterface} - - `cookieData`: The cookie data to be sent in the response.
*/
const SendFileResponse = ({ statusCode, response, Filename, rootName, cookieData, contentType, }) => {
// Set Content Type if available
if (contentType) {
for (const Type of Response_Constant_1.MIME_Types) {
if (Type.toLowerCase().includes(contentType.toLowerCase())) {
response.setHeader("Content-Type", Type);
break;
}
}
}
// Set Cookie Data to Response if it exists
if (cookieData) {
cookieData.forEach((CookieItems) => {
response.cookie(CookieItems.name, CookieItems.value, CookieItems.options); // sets cookie for each cookie in cookieData
});
}
response.status(statusCode).sendFile(Filename, { root: rootName }); // sends response with file
};
exports.SendFileResponse = SendFileResponse;
//# sourceMappingURL=File-Response.js.map