🐛Fix bug with sending files with response stream
Also updated another dependencies and removed old version of the fastify multipart plugin
This commit is contained in:
committed by
Anton Shepilov
parent
999e3087e8
commit
2884193072
@@ -2,7 +2,7 @@ import { logger, TdriveService } from "../../framework";
|
||||
import { Server, IncomingMessage, ServerResponse } from "http";
|
||||
import { FastifyInstance, fastify, FastifyRegisterOptions, FastifyServerOptions } from "fastify";
|
||||
import sensible from "@fastify/sensible";
|
||||
import multipart from "fastify-multipart";
|
||||
import multipart from "@fastify/multipart";
|
||||
import formbody from "@fastify/formbody";
|
||||
import fastifyStatic from "@fastify/static";
|
||||
import corsPlugin, { FastifyCorsOptions } from "@fastify/cors";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { randomBytes } from "crypto";
|
||||
import { Readable } from "stream";
|
||||
import { Multipart } from "fastify-multipart";
|
||||
import { MultipartFile } from "@fastify/multipart";
|
||||
import { UploadOptions } from "../types";
|
||||
import { File } from "../entities/file";
|
||||
import Repository from "../../../../src/core/platform/services/database/services/orm/repository/repository";
|
||||
@@ -73,7 +73,7 @@ export class FileServiceImpl {
|
||||
|
||||
async save(
|
||||
id: string,
|
||||
file: Multipart,
|
||||
file: MultipartFile,
|
||||
options: UploadOptions,
|
||||
context: CompanyExecutionContext,
|
||||
): Promise<File> {
|
||||
@@ -443,7 +443,7 @@ export class FileServiceImpl {
|
||||
}
|
||||
}
|
||||
|
||||
async restoreFileS3(id: string, file: Multipart, options: UploadOptions): Promise<any> {
|
||||
async restoreFileS3(id: string, file: MultipartFile, options: UploadOptions): Promise<any> {
|
||||
try {
|
||||
const result = await this.checkFileExistsS3(id);
|
||||
if (result.exist) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { FastifyReply, FastifyRequest } from "fastify";
|
||||
import { Multipart } from "fastify-multipart";
|
||||
import { MultipartFile } from "@fastify/multipart";
|
||||
import { ResourceDeleteResponse } from "../../../../utils/types";
|
||||
import { CompanyExecutionContext } from "../types";
|
||||
import { UploadOptions } from "../../types";
|
||||
@@ -16,7 +16,7 @@ export class FileController {
|
||||
): Promise<{ resource: PublicFile }> {
|
||||
const context = getCompanyExecutionContext(request);
|
||||
|
||||
let file: null | Multipart = null;
|
||||
let file: null | MultipartFile = null;
|
||||
if (request.isMultipart()) {
|
||||
file = await request.file();
|
||||
}
|
||||
@@ -52,7 +52,7 @@ export class FileController {
|
||||
response.header("Content-disposition", `attachment; filename="${filename}"`);
|
||||
if (data.size) response.header("Content-Length", data.size);
|
||||
response.type(data.mime);
|
||||
response.send(data.file);
|
||||
return response.send(data.file);
|
||||
} catch (e) {
|
||||
console.log("!!!" + e);
|
||||
throw e;
|
||||
@@ -121,7 +121,7 @@ export class FileController {
|
||||
}>,
|
||||
): Promise<{ resource: PublicFile }> {
|
||||
const params = request.params;
|
||||
let file: null | Multipart = null;
|
||||
let file: null | MultipartFile = null;
|
||||
if (request.isMultipart()) {
|
||||
file = await request.file();
|
||||
}
|
||||
@@ -148,7 +148,7 @@ function getCompanyExecutionContext(
|
||||
|
||||
company: { id: request.params.company_id },
|
||||
url: request.url,
|
||||
method: request.routerMethod,
|
||||
method: request.routeOptions.method,
|
||||
reqId: request.id,
|
||||
transport: "http",
|
||||
};
|
||||
|
||||
@@ -120,7 +120,7 @@ function getExecutionContext(request: FastifyRequest): ExecutionContext {
|
||||
return {
|
||||
user: request.currentUser,
|
||||
url: request.url,
|
||||
method: request.routerMethod,
|
||||
method: request.routeOptions.method,
|
||||
transport: "http",
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user