mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
Merge branch 'refactor/move-interface-in-file-stream' of github.com:Tony133/nest into Tony133-refactor/move-interface-in-file-stream
This commit is contained in:
2
packages/common/file-stream/interfaces/index.ts
Normal file
2
packages/common/file-stream/interfaces/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from './streamable-options.interface';
|
||||
export * from './streamable-handler-response.interface';
|
||||
@@ -0,0 +1,12 @@
|
||||
export interface StreamableHandlerResponse {
|
||||
/** `true` if the connection is destroyed, `false` otherwise. */
|
||||
destroyed: boolean;
|
||||
/** `true` if headers were sent, `false` otherwise. */
|
||||
headersSent: boolean;
|
||||
/** The status code that will be sent to the client when the headers get flushed. */
|
||||
statusCode: number;
|
||||
/** Sends the HTTP response. */
|
||||
send: (body: string) => void;
|
||||
/** Signals to the server that all of the response headers and body have been sent. */
|
||||
end: () => void;
|
||||
}
|
||||
@@ -1,13 +1,8 @@
|
||||
import { Readable } from 'stream';
|
||||
import { types } from 'util';
|
||||
import { HttpStatus } from '../enums';
|
||||
import { isFunction } from '../utils/shared.utils';
|
||||
import { StreamableFileOptions } from './streamable-options.interface';
|
||||
|
||||
export interface StreamableHandlerResponse {
|
||||
destroyed: boolean;
|
||||
statusCode: number;
|
||||
send: (msg: string) => void;
|
||||
}
|
||||
import { StreamableFileOptions, StreamableHandlerResponse } from './interfaces';
|
||||
|
||||
/**
|
||||
* @see [Streaming files](https://docs.nestjs.com/techniques/streaming-files)
|
||||
@@ -21,10 +16,16 @@ export class StreamableFile {
|
||||
err: Error,
|
||||
response: StreamableHandlerResponse,
|
||||
) => void = (err: Error, res) => {
|
||||
if (!res.destroyed) {
|
||||
res.statusCode = 400;
|
||||
res.send(err.message);
|
||||
if (res.destroyed) {
|
||||
return;
|
||||
}
|
||||
if (res.headersSent) {
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
|
||||
res.statusCode = HttpStatus.BAD_REQUEST;
|
||||
res.send(err.message);
|
||||
};
|
||||
|
||||
constructor(buffer: Uint8Array, options?: StreamableFileOptions);
|
||||
|
||||
Reference in New Issue
Block a user