1
0
mirror of https://github.com/stonith404/pingvin-share.git synced 2024-10-02 09:30:10 +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", "version": "0.0.1",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "gradely-backend", "name": "pingvin-share-backend",
"version": "0.0.1", "version": "0.0.1",
"license": "UNLICENSED",
"dependencies": { "dependencies": {
"@nestjs/common": "^9.1.2", "@nestjs/common": "^9.1.2",
"@nestjs/config": "^2.2.0", "@nestjs/config": "^2.2.0",
@ -21,6 +20,7 @@
"argon2": "^0.29.1", "argon2": "^0.29.1",
"class-transformer": "^0.5.1", "class-transformer": "^0.5.1",
"class-validator": "^0.13.2", "class-validator": "^0.13.2",
"content-disposition": "^0.5.4",
"mime-types": "^2.1.35", "mime-types": "^2.1.35",
"moment": "^2.29.4", "moment": "^2.29.4",
"multer": "^1.4.5-lts.1", "multer": "^1.4.5-lts.1",

View File

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

View File

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