1
0
mirror of https://github.com/stonith404/pingvin-share.git synced 2024-07-02 07:20:38 +02:00

fix: file names with special characters

This commit is contained in:
Elias Schneider 2022-10-12 15:04:57 +02:00
parent 0b9cc3bd30
commit bfbf3d8130
3 changed files with 10 additions and 4 deletions

View File

@ -1,13 +1,12 @@
{
"name": "gradely-backend",
"name": "pingvin-share-backend",
"version": "0.0.1",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "gradely-backend",
"name": "pingvin-share-backend",
"version": "0.0.1",
"license": "UNLICENSED",
"dependencies": {
"@nestjs/common": "^9.1.2",
"@nestjs/config": "^2.2.0",
@ -21,6 +20,7 @@
"argon2": "^0.29.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.13.2",
"content-disposition": "^0.5.4",
"mime-types": "^2.1.35",
"moment": "^2.29.4",
"multer": "^1.4.5-lts.1",

View File

@ -21,6 +21,7 @@
"argon2": "^0.29.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.13.2",
"content-disposition": "^0.5.4",
"mime-types": "^2.1.35",
"moment": "^2.29.4",
"multer": "^1.4.5-lts.1",

View File

@ -11,6 +11,7 @@ import {
UseInterceptors,
} from "@nestjs/common";
import { FileInterceptor } from "@nestjs/platform-express";
import * as contentDisposition from "content-disposition";
import { Response } from "express";
import { JwtGuard } from "src/auth/guard/jwt.guard";
import { FileDownloadGuard } from "src/file/guard/fileDownload.guard";
@ -41,6 +42,10 @@ export class FileController {
file: Express.Multer.File,
@Param("shareId") shareId: string
) {
// Fixes file names with special characters
file.originalname = Buffer.from(file.originalname, "latin1").toString(
"utf8"
);
return new ShareDTO().from(await this.fileService.create(file, shareId));
}
@ -98,7 +103,7 @@ export class FileController {
res.set({
"Content-Type": file.metaData.mimeType,
"Content-Length": file.metaData.size,
"Content-Disposition": `attachment ; filename="${file.metaData.name}"`,
"Content-Disposition": contentDisposition(file.metaData.name),
});
return new StreamableFile(file.file);