feat!: absolute file paths (#19995)

feat: absolute file paths
This commit is contained in:
Jason Rasmussen 2025-07-18 10:57:29 -04:00 committed by GitHub
parent f32d4f15b6
commit 493d85b021
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
34 changed files with 689 additions and 257 deletions

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 } from 'node:path';
import { promisify } from 'node:util';
import { CacheControl } from 'src/enum';
import { LoggingRepository } from 'src/repositories/logging.repository';
@ -62,15 +62,9 @@ export const sendFile = async (
res.header('Content-Disposition', `inline; filename*=UTF-8''${encodeURIComponent(file.fileName)}`);
}
// configure options for serving
const options: SendFileOptions = { dotfiles: 'allow' };
if (!isAbsolute(file.path)) {
options.root = process.cwd();
}
await access(file.path, constants.R_OK);
return await _sendFile(file.path, options);
return await _sendFile(file.path, { dotfiles: 'allow' });
} catch (error: Error | any) {
// ignore client-closed connection
if (isConnectionAborted(error) || res.headersSent) {