This commit is contained in:
Min Idzelis
2025-03-22 12:48:50 +00:00
parent 6a8e38042d
commit 442f11c9e1
12 changed files with 179 additions and 51 deletions
+6 -6
View File
@@ -1,7 +1,7 @@
import { HttpException, StreamableFile } from '@nestjs/common';
import { NextFunction, Response } from 'express';
import { access, constants } from 'node:fs/promises';
import { basename, extname, isAbsolute } from 'node:path';
import { basename, extname, isAbsolute, resolve } from 'node:path';
import { promisify } from 'node:util';
import { CacheControl } from 'src/enum';
import { LoggingRepository } from 'src/repositories/logging.repository';
@@ -64,13 +64,13 @@ export const sendFile = async (
// configure options for serving
const options: SendFileOptions = { dotfiles: 'allow' };
if (!isAbsolute(file.path)) {
options.root = process.cwd();
let filePath = file.path;
if (!isAbsolute(filePath)) {
filePath = resolve(filePath);
}
await access(filePath, constants.R_OK);
await access(file.path, constants.R_OK);
return await _sendFile(file.path, options);
return await _sendFile(filePath, options);
} catch (error: Error | any) {
// ignore client-closed connection
if (isConnectionAborted(error) || res.headersSent) {